Add source filters and a full-window media view

This commit is contained in:
Fisto
2026-09-16 11:11:50 +02:00
parent 2573dd4d63
commit 902646224f
12 changed files with 179 additions and 32 deletions
+17 -7
View File
@@ -320,17 +320,27 @@ export class ScrapeStore {
return row ?? null;
}
queryMedia(options: { kind?: MediaKind; limit?: number; offset?: number } = {}): MediaRow[] {
queryMedia(
options: { kind?: MediaKind; source?: string; limit?: number; offset?: number } = {}
): MediaRow[] {
const limit = Math.max(1, Math.min(options.limit ?? 50, 500));
const offset = Math.max(0, options.offset ?? 0);
const statement = options.kind
? this.db.prepare("SELECT * FROM media WHERE kind = ? ORDER BY id DESC LIMIT ? OFFSET ?")
: this.db.prepare("SELECT * FROM media ORDER BY id DESC LIMIT ? OFFSET ?");
const conditions: string[] = [];
const values: Array<string | number> = [];
if (options.kind) {
conditions.push("kind = ?");
values.push(options.kind);
}
if (options.source) {
conditions.push("source = ?");
values.push(options.source);
}
const rows = options.kind
? statement.all(options.kind, limit, offset)
: statement.all(limit, offset);
const where = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
const rows = this.db
.prepare(`SELECT * FROM media ${where} ORDER BY id DESC LIMIT ? OFFSET ?`)
.all(...values, limit, offset);
return rows as unknown as MediaRow[];
}