attachmentFileMeta.ts
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** 与 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() : "文件");
}