feat: five library-cleanup conditions for workflow IF/SWITCH nodes

Adds condition types common in smart-album systems of other photo
managers (Apple Photos, Lightroom, Google Photos):

- File Size: min/max in MB (fractional) over asset_exif.fileSizeInByte
- File Name / Path: contains / not contains / starts with / ends with
  against originalFileName or originalPath (ILIKE, wildcards escaped so
  user text matches literally)
- File Extension: is any of / is none of a comma-separated list,
  case-insensitive, matched after the last dot
- Face Count: min/max visible, non-deleted detected faces — 'how many
  people', complementing the person condition's 'who'
- Time of Day: from/to hour over localDateTime (capture wall-clock
  time, no timezone math); From > To wraps past midnight (22 to 5)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jonvdveenandClaude Fable 5 committed 2026-07-02 21:51:02 -06:00
1 parent f0d8a88c27
commit 1431b8523e
4 files changed
+160

No files matched your search

+57
View File
@@ -92,6 +92,63 @@ function buildSingleCondition(c: ICondition): SQL | undefined {
return parts.length > 0 ? and(...parts)! : undefined;
}
case "file_size": {
// min/max in megabytes (fractional allowed)
const parts: SQL[] = [];
if (c.min !== undefined && c.min !== null) parts.push(sql`${exif.fileSizeInByte} >= ${Math.round(c.min * 1048576)}`);
if (c.max !== undefined && c.max !== null) parts.push(sql`${exif.fileSizeInByte} <= ${Math.round(c.max * 1048576)}`);
return parts.length > 0 ? and(...parts)! : undefined;
}
case "filename": {
if (!c.text) return undefined;
const column = c.field === "path" ? assets.originalPath : assets.originalFileName;
// Escape LIKE wildcards so user text is matched literally
const escaped = c.text.replace(/([\\%_])/g, "\\$1");
const match = c.match || "contains";
const pattern =
match === "starts_with" ? `${escaped}%`
: match === "ends_with" ? `%${escaped}`
: `%${escaped}%`;
return match === "not_contains"
? sql`${column} NOT ILIKE ${pattern}`
: sql`${column} ILIKE ${pattern}`;
}
case "file_extension": {
const raw: string = c.extensions || "";
const exts = raw
.split(",")
.map((e: string) => e.trim().replace(/^\./, "").toLowerCase())
.filter(Boolean);
if (exts.length === 0) return undefined;
// Extension = text after the last dot; files without one never match either mode
const extExpr = sql`lower(substring(${assets.originalFileName} from '\\.([^.]+)$'))`;
const list = exts.map((e: string) => `'${e.replace(/'/g, "''")}'`).join(",");
return c.match === "not_in"
? sql`${extExpr} NOT IN (${sql.raw(list)})`
: sql`${extExpr} IN (${sql.raw(list)})`;
}
case "face_count": {
const faceCount = sql`(SELECT count(*) FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."deletedAt" IS NULL AND af."isVisible" = true)`;
const parts: SQL[] = [];
if (c.min !== undefined && c.min !== null) parts.push(sql`${faceCount} >= ${c.min}`);
if (c.max !== undefined && c.max !== null) parts.push(sql`${faceCount} <= ${c.max}`);
return parts.length > 0 ? and(...parts)! : undefined;
}
case "time_of_day": {
if (c.fromHour == null || c.toHour == null) return undefined;
// localDateTime holds the capture wall-clock time, so no timezone math needed
const hour = sql`EXTRACT(HOUR FROM ${assets.localDateTime})`;
if (c.fromHour <= c.toHour) {
return sql`${hour} BETWEEN ${c.fromHour} AND ${c.toHour}`;
}
// From > To wraps past midnight, e.g. 22–5 = evening through early morning
return sql`(${hour} >= ${c.fromHour} OR ${hour} <= ${c.toHour})`;
}
case "person": {
const ids: string[] = c.personIds || (c.personId ? [c.personId] : []);
if (ids.length === 0) return undefined;