mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
- Move icon name logic to Attachment and Reference classes - Create reusable setElementIcon Svelte action in ElementHelper - Update ChatArea and ChatAttachments to use new icon helper - Add visual separator and background color for message attachments - Fix duplicate URIs in drag-and-drop file handling - Improve attachment icon centering with flexbox layout
48 lines
No EOL
1.2 KiB
TypeScript
48 lines
No EOL
1.2 KiB
TypeScript
import { isAudioFile, isImageFile, isKnownFileType, isTextFile, isVideoFile } from "Enums/FileType";
|
|
import { pathExtname } from "Helpers/Helpers";
|
|
|
|
export class Reference {
|
|
|
|
public fileName: string;
|
|
public size: number;
|
|
|
|
public constructor(fileName: string, size: number) {
|
|
this.fileName = fileName;
|
|
this.size = size;
|
|
}
|
|
|
|
public getIconName(): string {
|
|
const extension = pathExtname(this.fileName);
|
|
|
|
if (isTextFile(extension)) {
|
|
return "file-text";
|
|
}
|
|
if (isImageFile(extension)) {
|
|
return "file-image";
|
|
}
|
|
if (isAudioFile(extension)) {
|
|
return "file-music";
|
|
}
|
|
if (isVideoFile(extension)) {
|
|
return "file-play";
|
|
}
|
|
if (isKnownFileType(extension)) {
|
|
return "file";
|
|
}
|
|
return "file";
|
|
}
|
|
|
|
public static isReferenceData(this: void, data: unknown): data is {
|
|
fileName: string;
|
|
size: number;
|
|
} {
|
|
return (
|
|
data !== null &&
|
|
typeof data === "object" &&
|
|
"fileName" in data &&
|
|
"size" in data &&
|
|
typeof data.fileName === "string" &&
|
|
typeof data.size === "number"
|
|
);
|
|
}
|
|
} |