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