prevent image loading and add image-off logo for code preview

This commit is contained in:
lemonknowsall committed 2025-11-16 17:44:17 -08:00
1 parent 766aea14b9
commit e88b8c90d9
3 files changed
+64 -23

No files matched your search

+23
View File
@@ -67,4 +67,27 @@ export async function saveFileToTmp(fs: JSRuntimeFS, file: File, tmpPath = '/tmp
await fs.writeFile(fullPath, uint8Array);
return fullPath;
}
/**
* Check if a file path represents a media/binary file that cannot be edited as text
* @param path - File path to check
* @returns boolean - True if the file is a media/binary file
*/
export function isMediaFile(path: string): boolean {
const extension = path.split('.').pop()?.toLowerCase();
if (!extension) return false;
const mediaExtensions = [
// Images
'jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'ico', 'avif', 'heic', 'heif',
// Videos
'mp4', 'webm', 'avi', 'mov', 'mkv', 'flv', 'wmv', 'm4v',
// Audio
'mp3', 'wav', 'ogg', 'flac', 'm4a', 'aac', 'wma',
// Other binary formats
'pdf', 'zip', 'tar', 'gz', 'rar', '7z',
];
return mediaExtensions.includes(extension);
}