feat(media): implement caching for chat media and update components to use cached media

This commit is contained in:
2026-06-30 15:59:33 +08:00
parent 78d8aae22e
commit ccd2d6bd48
15 changed files with 591 additions and 42 deletions
+21
View File
@@ -32,13 +32,34 @@ export interface LocalMessageRow {
sessionId: string;
}
export type LocalChatMediaKind = "image" | "audio";
export interface LocalChatMediaRow {
cacheKey: string;
ownerKey: string;
messageId: string;
kind: LocalChatMediaKind;
remoteUrl: string;
blob: Blob;
mimeType: string;
byteSize: number;
createdAt: number;
updatedAt: number;
lastAccessedAt: number;
}
export class LocalChatDB extends Dexie {
messages!: Table<LocalMessageRow, number>;
media!: Table<LocalChatMediaRow, string>;
constructor(dbName: string = "cozsweet-chat") {
super(dbName);
this.version(1).stores({
messages: "++dbId",
});
this.version(2).stores({
messages: "++dbId",
media: "cacheKey, ownerKey, messageId, kind, remoteUrl, updatedAt, lastAccessedAt",
});
}
}