返回 DeepSeek-Reasonix
composerAttachments.ts
根目录 / desktop / frontend / src / lib / composerAttachments.ts
1 export interface Attachment {
2 clientAttachmentId?: string;
3 path: string;
4 previewUrl?: string;
5 displayName?: string;
6 draftId?: string;
7 file?: File;
8 }
9
10 export function baseName(path: string): string {
11 const clean = path.replace(/[\\/]+$/, "");
12 return clean.split(/[\\/]/).filter(Boolean).pop() ?? path;
13 }
14
15 export function attachmentName(attachment: Attachment): string {
16 return (attachment.displayName || baseName(attachment.path) || "attachment").trim();
17 }
18
19 export function attachmentExt(name: string): string {
20 const dot = name.lastIndexOf(".");
21 return dot >= 0 ? name.slice(dot + 1).toUpperCase() : "";
22 }
23
24 export function hasImageAttachments(items: Attachment[]): boolean {
25 return items.some((attachment) => Boolean(attachment.previewUrl));
26 }
27
28 export function displayRefName(name: string): string {
29 return name.replace(/[\[\]\(\)\r\n]+/g, " ").replace(/\s+/g, " ").trim() || "attachment";
30 }
31
32 export function formatAttachmentDisplayReference(attachment: Attachment): string {
33 return `@[${displayRefName(attachmentName(attachment))}](${attachment.path})`;
34 }
35
36 export function sortComposerAttachments(items: Attachment[]): Attachment[] {
37 return [...items];
38 }
39
39 lines TYPESCRIPT