Add file-type and host filters with a 4chan default

This commit is contained in:
Fisto
2026-09-17 08:39:41 +02:00
parent 42b4bfd231
commit 0b72422afe
9 changed files with 117 additions and 6 deletions
+13
View File
@@ -108,6 +108,8 @@ export interface MediaFilterOptions {
authorId?: string;
authorIds?: string[];
cachedOnly?: boolean;
exts?: string[];
excludeHosts?: string[];
aspect?: string;
resolution?: string;
after?: string;
@@ -493,6 +495,17 @@ export class ScrapeStore {
if (options.cachedOnly) {
conditions.push("preview_hash IS NOT NULL");
}
if (options.exts?.length) {
const clauses = options.exts.map(() => "(lower(url) LIKE ? OR lower(content_type) LIKE ?)");
conditions.push(`(${clauses.join(" OR ")})`);
for (const ext of options.exts) {
values.push(`%.${ext.toLowerCase()}%`, `%/${ext.toLowerCase()}%`);
}
}
for (const host of options.excludeHosts ?? []) {
conditions.push("lower(url) NOT LIKE ?");
values.push(`%${host.toLowerCase()}%`);
}
if (options.after) {
conditions.push("posted_at >= ?");
values.push(options.after);