ultisuite-client/lib/drive/onlyoffice-formats.ts
R3D347HR4Y 82ca9a27db
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat(drive): refactor document and drawing editors with new metadata handling
- Replaced suite page metadata with drive-specific metadata for document and drawing editors.
- Introduced new `driveEditorPageMetadata` function to manage titles and favicons based on editor type.
- Updated layout components for document and drawing editors to utilize the new metadata structure.
- Enhanced document title handling in various editor components to reflect the current editing context.
- Added new SVG icons for UltiDocs, UltiSheets, UltiSlides, and UltiDraw to improve visual consistency across editors.
- Improved print styles and layout handling for better document rendering in print and PDF formats.
2026-06-15 15:51:09 +02:00

153 lines
2.7 KiB
TypeScript

/**
* Extensions supported by ONLYOFFICE Document Server (view/edit).
* @see https://github.com/ONLYOFFICE/document-formats
* PDF is omitted here — opened via in-app preview instead.
*/
const ONLYOFFICE_WORD = [
"doc",
"docm",
"docx",
"dot",
"dotm",
"dotx",
"epub",
"fb2",
"fodt",
"htm",
"html",
"hwp",
"hwpx",
"md",
"mht",
"mhtml",
"odt",
"ott",
"rtf",
"stw",
"sxw",
"txt",
"wps",
"wpt",
"xml",
] as const
const ONLYOFFICE_CELL = [
"csv",
"et",
"ett",
"fods",
"ods",
"ots",
"sxc",
"tsv",
"xls",
"xlsb",
"xlsm",
"xlsx",
"xlt",
"xltm",
"xltx",
] as const
const ONLYOFFICE_SLIDE = [
"dps",
"dpt",
"fodp",
"odg",
"odp",
"otp",
"pot",
"potm",
"potx",
"pps",
"ppsm",
"ppsx",
"ppt",
"pptm",
"pptx",
"sxi",
] as const
const ONLYOFFICE_DIAGRAM = [
"vsdm",
"vsdx",
"vssm",
"vssx",
"vstm",
"vstx",
] as const
export const ONLYOFFICE_EXTENSIONS = new Set<string>([
...ONLYOFFICE_WORD,
...ONLYOFFICE_CELL,
...ONLYOFFICE_SLIDE,
...ONLYOFFICE_DIAGRAM,
])
const OFFICE_MIME_HINTS = [
"wordprocessingml",
"spreadsheetml",
"presentationml",
"msword",
"ms-excel",
"ms-powerpoint",
"opendocument",
"visio",
] as const
export function fileExtension(name: string): string {
const base = name.split("/").pop() ?? name
const i = base.lastIndexOf(".")
if (i <= 0) return ""
return base.slice(i + 1).toLowerCase()
}
export function isOnlyOfficeExtension(ext: string): boolean {
return ONLYOFFICE_EXTENSIONS.has(ext.toLowerCase())
}
export function isOnlyOfficeMime(mime: string): boolean {
const m = mime.toLowerCase()
if (m === "application/pdf") return false
return OFFICE_MIME_HINTS.some((hint) => m.includes(hint))
}
export function isOnlyOfficeFile(file: {
name: string
mime_type?: string
}): boolean {
const mime = (file.mime_type ?? "").toLowerCase()
if (mime && isOnlyOfficeMime(mime)) return true
return isOnlyOfficeExtension(fileExtension(file.name))
}
const ONLYOFFICE_CELL_SET = new Set<string>(ONLYOFFICE_CELL)
const ONLYOFFICE_SLIDE_SET = new Set<string>([...ONLYOFFICE_SLIDE, ...ONLYOFFICE_DIAGRAM])
export function resolveOnlyOfficeEditorKind(file: {
name: string
mime_type?: string
}): "sheets" | "presentation" {
const mime = (file.mime_type ?? "").toLowerCase()
const ext = fileExtension(file.name)
if (
mime.includes("spreadsheet") ||
mime.includes("excel") ||
ONLYOFFICE_CELL_SET.has(ext)
) {
return "sheets"
}
if (
mime.includes("presentation") ||
mime.includes("powerpoint") ||
mime.includes("visio") ||
ONLYOFFICE_SLIDE_SET.has(ext)
) {
return "presentation"
}
return "sheets"
}