Add per-kind stats, GIF hover playback, and static gif previews

This commit is contained in:
Fisto
2026-09-16 13:36:51 +02:00
parent 612b2504dc
commit 0081224954
13 changed files with 189 additions and 57 deletions
+21 -6
View File
@@ -118,6 +118,8 @@ export interface MediaItemResult {
durationSecs: number | null;
url: string;
playUrl: string | null;
/** The remote thumbnail URL from Discord's embed data (may be an animated GIF). */
remotePreviewUrl: string | null;
localUrl: string | null;
thumbUrl: string | null;
provider: string | null;
@@ -539,9 +541,9 @@ export class MediaService {
resolution?: string;
after?: string;
before?: string;
} = {}): { total: number; downloaded: number; cached: number; notDownloaded: number } {
} = {}): Record<MediaKind, { total: number; downloaded: number; cached: number; notDownloaded: number }> {
// Deduplicate by URL across scrapes, newest scrape wins, like queryMedia.
const byUrl = new Map<string, { downloaded: boolean; cached: boolean }>();
const byUrl = new Map<string, { kind: MediaKind; downloaded: boolean; cached: boolean }>();
for (const meta of this.engine.list()) {
if (meta.state === "deleted") continue;
@@ -559,6 +561,7 @@ export class MediaService {
for (const row of rows) {
if (byUrl.has(row.url)) continue;
byUrl.set(row.url, {
kind: row.kind,
downloaded: row.downloaded === 1,
cached: row.preview_hash !== null
});
@@ -571,13 +574,24 @@ export class MediaService {
}
}
const totals = { total: byUrl.size, downloaded: 0, cached: 0, notDownloaded: 0 };
const totals: Record<
MediaKind,
{ total: number; downloaded: number; cached: number; notDownloaded: number }
> = {
image: { total: 0, downloaded: 0, cached: 0, notDownloaded: 0 },
gif: { total: 0, downloaded: 0, cached: 0, notDownloaded: 0 },
video: { total: 0, downloaded: 0, cached: 0, notDownloaded: 0 },
audio: { total: 0, downloaded: 0, cached: 0, notDownloaded: 0 }
};
for (const entry of byUrl.values()) {
const bucket = totals[entry.kind];
bucket.total++;
if (entry.downloaded) {
totals.downloaded++;
bucket.downloaded++;
} else {
totals.notDownloaded++;
if (entry.cached) totals.cached++;
bucket.notDownloaded++;
if (entry.cached) bucket.cached++;
}
}
@@ -694,6 +708,7 @@ export class MediaService {
durationSecs: row.duration_secs,
url: row.url,
playUrl: row.play_url,
remotePreviewUrl: row.preview_url,
localUrl:
row.file_path && !meta.downloadDir
? `/api/media/${meta.id}/${row.id}/file`