* fix: files.vue bugs before styling changes * feat: move files tab to shared layout structure * fix: qa * fix: qa * fix: bugs * fix: lint * fix: admonition cleanup with progress + actions * fix: cleanup * fix: modals * fix: admon title * fix: i18n standard * fix: lint + i18n pass * fix: remove transition * fix: type errors * feat: files tab in app * fix: qa * fix: backup item minmax * fix: use ContentPageHeader for server panel * fix: lint * fix: lint * fix: lint * feat: page leave safety * fix: lint * fix: cargo fmt fix * fix: blank in prod * fix: content card table stuff * Revert "fix: blank in prod" This reverts commit 74758fe185cf85a4a20355857f889cb091b97ace. * fix: import * feat: browse worlds/servers flow * fix: worlds tab parity with content tab * fix: perf bug + shader filter pill copy * feat: singleplayer filter * fix: ordering * fix: breadcrumbs * fix: lint * fix: qa * feat: store server proj id when adding to a non-linked instance * fix: lint * fix: i18n + qa * fix: conflict * qa: already installed modal + placeholders not server-specific * fix: qa * fix: add + edit server modals * fix: qa * fix: security * fix: devin flags * fix: lint * chore: change file to break build cache * fix: admon * fix: import path stuff * feat: qa * fix: fmt fmt idiot --------- Signed-off-by: Calum H. <calum@modrinth.com>
155 lines
2.9 KiB
TypeScript
155 lines
2.9 KiB
TypeScript
// File extension constants
|
|
export const FILE_CODE_EXTENSIONS = [
|
|
'json',
|
|
'json5',
|
|
'jsonc',
|
|
'java',
|
|
'kt',
|
|
'kts',
|
|
'sh',
|
|
'bat',
|
|
'ps1',
|
|
'yml',
|
|
'yaml',
|
|
'toml',
|
|
'js',
|
|
'ts',
|
|
'py',
|
|
'rb',
|
|
'php',
|
|
'html',
|
|
'css',
|
|
'cpp',
|
|
'c',
|
|
'h',
|
|
'rs',
|
|
'go',
|
|
] as const
|
|
|
|
export const FILE_TEXT_EXTENSIONS = [
|
|
'txt',
|
|
'md',
|
|
'log',
|
|
'cfg',
|
|
'conf',
|
|
'properties',
|
|
'ini',
|
|
'sk',
|
|
] as const
|
|
|
|
export const FILE_IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp'] as const
|
|
|
|
export const FILE_ARCHIVE_EXTENSIONS = ['zip', 'jar', 'tar', 'gz', 'rar', '7z'] as const
|
|
|
|
// Type for extension strings
|
|
export type CodeExtension = (typeof FILE_CODE_EXTENSIONS)[number]
|
|
export type TextExtension = (typeof FILE_TEXT_EXTENSIONS)[number]
|
|
export type ImageExtension = (typeof FILE_IMAGE_EXTENSIONS)[number]
|
|
export type ArchiveExtension = (typeof FILE_ARCHIVE_EXTENSIONS)[number]
|
|
|
|
/**
|
|
* Extract file extension from filename (lowercase)
|
|
*/
|
|
export function getFileExtension(filename: string): string {
|
|
return filename.split('.').pop()?.toLowerCase() ?? ''
|
|
}
|
|
|
|
/**
|
|
* Check if extension is a code file
|
|
*/
|
|
export function isCodeFile(ext: string): boolean {
|
|
return (FILE_CODE_EXTENSIONS as readonly string[]).includes(ext.toLowerCase())
|
|
}
|
|
|
|
/**
|
|
* Check if extension is a text file
|
|
*/
|
|
export function isTextFile(ext: string): boolean {
|
|
return (FILE_TEXT_EXTENSIONS as readonly string[]).includes(ext.toLowerCase())
|
|
}
|
|
|
|
/**
|
|
* Check if extension is an image file
|
|
*/
|
|
export function isImageFile(ext: string): boolean {
|
|
return (FILE_IMAGE_EXTENSIONS as readonly string[]).includes(ext.toLowerCase())
|
|
}
|
|
|
|
/**
|
|
* Check if extension is an archive file
|
|
*/
|
|
export function isArchiveFile(ext: string): boolean {
|
|
return (FILE_ARCHIVE_EXTENSIONS as readonly string[]).includes(ext.toLowerCase())
|
|
}
|
|
|
|
/**
|
|
* Check if file is editable (code or text)
|
|
*/
|
|
export function isEditableFile(ext: string): boolean {
|
|
return isCodeFile(ext) || isTextFile(ext)
|
|
}
|
|
|
|
/**
|
|
* Get Ace editor language mode for a file extension
|
|
*/
|
|
export function getEditorLanguage(ext: string): string {
|
|
const lowered = ext.toLowerCase()
|
|
switch (lowered) {
|
|
// Code files
|
|
case 'json':
|
|
case 'json5':
|
|
case 'jsonc':
|
|
return 'json'
|
|
case 'toml':
|
|
return 'toml'
|
|
case 'sh':
|
|
return 'sh'
|
|
case 'bat':
|
|
return 'batchfile'
|
|
case 'ps1':
|
|
return 'powershell'
|
|
case 'yml':
|
|
case 'yaml':
|
|
return 'yaml'
|
|
case 'js':
|
|
return 'javascript'
|
|
case 'ts':
|
|
return 'typescript'
|
|
case 'py':
|
|
return 'python'
|
|
case 'rb':
|
|
return 'ruby'
|
|
case 'php':
|
|
return 'php'
|
|
case 'html':
|
|
return 'html'
|
|
case 'css':
|
|
return 'css'
|
|
case 'java':
|
|
case 'kt':
|
|
case 'kts':
|
|
return 'java'
|
|
case 'cpp':
|
|
case 'c':
|
|
case 'h':
|
|
return 'c_cpp'
|
|
case 'rs':
|
|
return 'rust'
|
|
case 'go':
|
|
return 'golang'
|
|
// Text files
|
|
case 'md':
|
|
return 'markdown'
|
|
case 'properties':
|
|
return 'properties'
|
|
case 'ini':
|
|
case 'cfg':
|
|
case 'conf':
|
|
return 'ini'
|
|
case 'log':
|
|
return 'mclog'
|
|
default:
|
|
return 'text'
|
|
}
|
|
}
|