attachmentFileMeta.ts 1.23 KB
/** 与 Workspace openFileDirectly / Codex 预览一致的标准类型 */
export function getFileTypeFromNameForOpen(fileName: string): string {
  if (!fileName) return "text";
  const ext = fileName.split(".").pop()?.toLowerCase() || "";
  const typeMap: Record<string, string> = {
    md: "md",
    pdf: "pdf",
    doc: "word",
    docx: "word",
    xls: "spreadsheet",
    xlsx: "spreadsheet",
    csv: "spreadsheet",
    ppt: "presentation",
    pptx: "presentation",
    txt: "text",
    json: "text",
    html: "text",
    jpg: "image",
    jpeg: "image",
    png: "image",
    gif: "image",
    webp: "image",
    mp3: "audio",
    wav: "audio",
    mp4: "video",
  };
  return typeMap[ext] || "text";
}

/** 卡片副标题展示用 */
export function getAttachmentKindLabel(fileName: string): string {
  const ext = fileName.split(".").pop()?.toLowerCase() || "";
  const labels: Record<string, string> = {
    md: "Markdown",
    pdf: "PDF",
    doc: "Word",
    docx: "Word",
    xls: "Excel",
    xlsx: "Excel",
    csv: "CSV",
    ppt: "PPT",
    pptx: "PPT",
    txt: "文本",
    png: "图片",
    jpg: "图片",
    jpeg: "图片",
    gif: "图片",
    webp: "图片",
  };
  return labels[ext] || (ext ? ext.toUpperCase() : "文件");
}