fix: support Immich v3.2.0
- v3.2.0 renamed asset_face.personId to personGroupId and dropped person.id in favour of a (ownerId, personGroupId) key, breaking every face/person query.
This commit is contained in:
1 parent
a3357d6b43
commit
741f5bb32a
23 files changed
+90
-59
No files matched your search
@@ -65,7 +65,7 @@ async function immichFetch(path: string, method: string, body: any, user: IUser)
|
||||
return null;
|
||||
}
|
||||
|
||||
async function resolveTemplate(template: string, assetIds: string[]): Promise<string> {
|
||||
async function resolveTemplate(template: string, assetIds: string[], ownerId: string): Promise<string> {
|
||||
if (!template || assetIds.length === 0) return template;
|
||||
|
||||
let result = template;
|
||||
@@ -112,7 +112,10 @@ async function resolveTemplate(template: string, assetIds: string[]): Promise<st
|
||||
const faces = await db
|
||||
.select({ name: person.name })
|
||||
.from(assetFaces)
|
||||
.innerJoin(person, eq(assetFaces.personId, person.id))
|
||||
.innerJoin(person, and(
|
||||
eq(assetFaces.personGroupId, person.personGroupId),
|
||||
eq(person.ownerId, ownerId),
|
||||
))
|
||||
.where(inArray(assetFaces.assetId, assetIds))
|
||||
.limit(100);
|
||||
|
||||
@@ -145,7 +148,7 @@ export async function executeAction(
|
||||
|
||||
switch (subType) {
|
||||
case "create_album": {
|
||||
const albumName = await resolveTemplate(config.nameTemplate || "Auto Album", assetIds);
|
||||
const albumName = await resolveTemplate(config.nameTemplate || "Auto Album", assetIds, user.id);
|
||||
const album = await immichFetch("/albums", "POST", { albumName, assetIds: assetIds.slice(0, API_BATCH_SIZE) }, user);
|
||||
if (assetIds.length > API_BATCH_SIZE) {
|
||||
await immichFetchBatched(`/albums/${album.id}/assets`, "PUT", assetIds.slice(API_BATCH_SIZE), {}, user);
|
||||
|
||||
@@ -13,14 +13,14 @@ export function buildConditions(conditions: ICondition[], ownerId: string): SQL[
|
||||
];
|
||||
|
||||
for (const c of conditions) {
|
||||
const clause = buildSingleCondition(c);
|
||||
const clause = buildSingleCondition(c, ownerId);
|
||||
if (clause) clauses.push(clause);
|
||||
}
|
||||
|
||||
return clauses;
|
||||
}
|
||||
|
||||
function buildSingleCondition(c: ICondition): SQL | undefined {
|
||||
function buildSingleCondition(c: ICondition, ownerId: string): SQL | undefined {
|
||||
switch (c.type) {
|
||||
case "city":
|
||||
return c.match === "not_equals"
|
||||
@@ -171,7 +171,7 @@ function buildSingleCondition(c: ICondition): SQL | undefined {
|
||||
if (c.match === "not_contains") {
|
||||
// Asset must not contain ANY of these people
|
||||
const checks = ids.map((pid: string) =>
|
||||
sql`NOT EXISTS (SELECT 1 FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."personId" = ${pid})`
|
||||
sql`NOT EXISTS (SELECT 1 FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."personGroupId" = ${pid})`
|
||||
);
|
||||
return and(...checks)!;
|
||||
}
|
||||
@@ -179,14 +179,14 @@ function buildSingleCondition(c: ICondition): SQL | undefined {
|
||||
if (c.match === "contains_all") {
|
||||
// Asset must contain ALL of these people
|
||||
const checks = ids.map((pid: string) =>
|
||||
sql`EXISTS (SELECT 1 FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."personId" = ${pid})`
|
||||
sql`EXISTS (SELECT 1 FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."personGroupId" = ${pid})`
|
||||
);
|
||||
return and(...checks)!;
|
||||
}
|
||||
|
||||
// contains_any (default) — asset contains at least one of these people
|
||||
const idList = ids.map((id: string) => `'${id}'`).join(",");
|
||||
return sql`EXISTS (SELECT 1 FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."personId" IN (${sql.raw(idList)}))`;
|
||||
return sql`EXISTS (SELECT 1 FROM "asset_face" af WHERE af."assetId" = ${assets.id} AND af."personGroupId" IN (${sql.raw(idList)}))`;
|
||||
}
|
||||
|
||||
case "tag": {
|
||||
@@ -221,9 +221,9 @@ function buildSingleCondition(c: ICondition): SQL | undefined {
|
||||
|
||||
case "person_unnamed":
|
||||
if (c.match === "no_unnamed") {
|
||||
return sql`NOT EXISTS (SELECT 1 FROM "asset_face" af JOIN "person" p ON af."personId" = p.id WHERE af."assetId" = ${assets.id} AND (p.name = '' OR p.name IS NULL))`;
|
||||
return sql`NOT EXISTS (SELECT 1 FROM "asset_face" af JOIN "person" p ON af."personGroupId" = p."personGroupId" AND p."ownerId" = ${ownerId} WHERE af."assetId" = ${assets.id} AND (p.name = '' OR p.name IS NULL))`;
|
||||
}
|
||||
return sql`EXISTS (SELECT 1 FROM "asset_face" af JOIN "person" p ON af."personId" = p.id WHERE af."assetId" = ${assets.id} AND (p.name = '' OR p.name IS NULL))`;
|
||||
return sql`EXISTS (SELECT 1 FROM "asset_face" af JOIN "person" p ON af."personGroupId" = p."personGroupId" AND p."ownerId" = ${ownerId} WHERE af."assetId" = ${assets.id} AND (p.name = '' OR p.name IS NULL))`;
|
||||
|
||||
case "not_in_album":
|
||||
return sql`NOT EXISTS (SELECT 1 FROM "album_asset" aa WHERE aa."assetId" = ${assets.id})`;
|
||||
|
||||
Reference in new issue
Block a user