import { API_BASE_URL } from "./client"; /** * Get preview URL for a file * @param path - File path * @param size - Preview size (128, 256, 512) */ export function getPreviewUrl(path: string, size: number = 256): string { const encodedPath = encodeURIComponent(path.slice(1)); // Remove leading slash return `${API_BASE_URL}/preview/${size}/${encodedPath}`; } /** * Check if a file type is previewable */ export function isPreviewable(filename: string): boolean { const ext = filename.split(".").pop()?.toLowerCase() || ""; const previewableTypes = [ // Images "jpg", "jpeg", "png", "gif", "webp", "svg", "bmp", // Video "mp4", "webm", "ogv", // Audio "mp3", "wav", "ogg", // Documents "pdf", "txt", "md", "json", "xml", "html", "css", "js", ]; return previewableTypes.includes(ext); } /** * Get file type category */ export function getFileType(filename: string): "image" | "video" | "audio" | "document" | "unknown" { const ext = filename.split(".").pop()?.toLowerCase() || ""; const imageExts = ["jpg", "jpeg", "png", "gif", "webp", "svg", "bmp"]; const videoExts = ["mp4", "webm", "ogv"]; const audioExts = ["mp3", "wav", "ogg"]; const docExts = ["pdf", "txt", "md", "json", "xml", "html", "css", "js"]; if (imageExts.includes(ext)) return "image"; if (videoExts.includes(ext)) return "video"; if (audioExts.includes(ext)) return "audio"; if (docExts.includes(ext)) return "document"; return "unknown"; }