feat(frontend,backend): storage panel with weight rows and trash, heavy media streams by url in the viewer
This commit is contained in:
1 parent
f2c245707a
commit
55634984fd
19 files changed
+1822
-24
No files matched your search
@@ -26,6 +26,7 @@ export interface ViewerItem {
|
||||
mediaId: number | null;
|
||||
messageId: number;
|
||||
mime: string | null;
|
||||
src?: string;
|
||||
}
|
||||
|
||||
export function viewerItemsFrom(
|
||||
@@ -102,6 +103,16 @@ export function visualKind(kind: string): VisualKind {
|
||||
return "other";
|
||||
}
|
||||
|
||||
const STREAM_KINDS = new Set(["video", "video_note", "voice", "audio"]);
|
||||
const STREAM_MIME_PREFIXES = ["video/", "audio/"];
|
||||
|
||||
export function isStreamable(kind: string, mime: string | null): boolean {
|
||||
return (
|
||||
STREAM_KINDS.has(kind) ||
|
||||
STREAM_MIME_PREFIXES.some((prefix) => mime?.startsWith(prefix))
|
||||
);
|
||||
}
|
||||
|
||||
const MAX_CACHED = 200;
|
||||
|
||||
const ready = new Map<string, InlineMedia>();
|
||||
@@ -130,6 +141,26 @@ function cacheKey(account: number, chatId: number, messageId: number): string {
|
||||
return `${account}:${chatId}:${messageId}`;
|
||||
}
|
||||
|
||||
function forget(cache: Map<string, InlineMedia>, key: string) {
|
||||
const stale = cache.get(key);
|
||||
cache.delete(key);
|
||||
if (stale?.state === "ready") {
|
||||
URL.revokeObjectURL(stale.url);
|
||||
}
|
||||
}
|
||||
|
||||
export function forgetMedia(
|
||||
chatId: number,
|
||||
messageId: number,
|
||||
mediaId: number
|
||||
): void {
|
||||
const account = accounts.selectedId;
|
||||
if (account !== null) {
|
||||
forget(ready, cacheKey(account, chatId, messageId));
|
||||
forget(byId, `${account}:${mediaId}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function resolve(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
|
||||
Reference in new issue
Block a user