ultisuite-client/lib/drive/ultidraw-formats.ts
R3D347HR4Y 303b2b1074
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
wow
2026-06-11 01:22:40 +02:00

32 lines
1.0 KiB
TypeScript

export const EXCALIDRAW_EXTENSION = "excalidraw"
export function fileExtension(name: string): string {
const base = name.split("/").pop() ?? name
const lower = base.toLowerCase()
if (lower.endsWith(".excalidraw.json")) return "excalidraw.json"
const i = base.lastIndexOf(".")
if (i <= 0) return ""
return base.slice(i + 1).toLowerCase()
}
export function isExcalidrawExtension(ext: string): boolean {
const normalized = ext.toLowerCase()
return normalized === EXCALIDRAW_EXTENSION || normalized === "excalidraw.json"
}
export function isExcalidrawFile(file: { name: string; mime_type?: string; type?: string }): boolean {
if (file.type === "directory") return false
const ext = fileExtension(file.name)
if (ext && isExcalidrawExtension(ext)) return true
const mime = (file.mime_type ?? "").toLowerCase()
return mime === "application/json" && file.name.toLowerCase().endsWith(".excalidraw")
}
export function shouldOpenInUltidrawEditor(file: {
name: string
mime_type?: string
type?: string
}): boolean {
return isExcalidrawFile(file)
}