Add file-type and host filters with a 4chan default
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user