Add source filters and a full-window media view
This commit is contained in:
@@ -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[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user