Add Discord-hosted preview caching (C11)
This commit is contained in:
@@ -94,6 +94,7 @@ export interface MediaItemResult {
|
||||
kind: MediaKind;
|
||||
url: string;
|
||||
localUrl: string | null;
|
||||
thumbUrl: string | null;
|
||||
provider: string | null;
|
||||
downloaded: boolean;
|
||||
createdAt: string;
|
||||
@@ -141,6 +142,7 @@ export class MediaService {
|
||||
log: line => this.deps.log?.(line),
|
||||
download: {
|
||||
maxFileBytes: number(process.env.VESKSLOP_MEDIA_MAX_FILE_BYTES, 50 * 1024 * 1024),
|
||||
previewMaxBytes: number(process.env.VESKSLOP_MEDIA_PREVIEW_MAX_BYTES, 5 * 1024 * 1024),
|
||||
minGapMs: number(process.env.VESKSLOP_MEDIA_DOWNLOAD_MIN_MS, 1000),
|
||||
maxGapMs: number(process.env.VESKSLOP_MEDIA_DOWNLOAD_MAX_MS, 3000)
|
||||
}
|
||||
@@ -323,6 +325,17 @@ export class MediaService {
|
||||
};
|
||||
}
|
||||
|
||||
/** Absolute path for a cached preview, or null. */
|
||||
getMediaThumb(scrapeId: string, itemId: number): { path: string; contentType: string } | null {
|
||||
const item = this.getMediaItem(scrapeId, itemId);
|
||||
if (!item?.preview_hash) return null;
|
||||
|
||||
return {
|
||||
path: join(this.rootDir, scrapeId, "thumbs", `${item.preview_hash}.webp`),
|
||||
contentType: "image/webp"
|
||||
};
|
||||
}
|
||||
|
||||
/** One media row inside a scrape, with its scrape and channel for context. */
|
||||
getMediaItem(scrapeId: string, itemId: number): (MediaRow & { scrapeId: string; channelId: string }) | null {
|
||||
const meta = this.engine.get(scrapeId);
|
||||
@@ -363,6 +376,7 @@ export class MediaService {
|
||||
kind: row.kind,
|
||||
url: row.url,
|
||||
localUrl: row.file_path ? `/api/media/${meta.id}/${row.id}/file` : null,
|
||||
thumbUrl: row.preview_hash ? `/api/media/${meta.id}/${row.id}/thumb` : null,
|
||||
provider: row.provider,
|
||||
downloaded: row.downloaded === 1,
|
||||
createdAt: row.created_at
|
||||
|
||||
Reference in New Issue
Block a user