From 95ede2efd72351eb5cf228680dcabf230a83810d Mon Sep 17 00:00:00 2001 From: jonvdveen <196496658+jonvdveen@users.noreply.github.com> Date: Thu, 2 Jul 2026 22:54:43 -0600 Subject: [PATCH 1/2] feat: Remove Tag workflow action to complement Add Tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes a tag (by name, matching the tag's full path value) from the matched assets via DELETE /tags/:id/assets. The tag is looked up without creating it — removing a tag that doesn't exist is a no-op rather than an error, so add/remove pairs are safe in the same workflow. Registered in the node palette, action node, run-detail view, and action config (same tag-name field as Add Tag). Co-Authored-By: Claude Fable 5 --- src/components/workflows/NodePalette.tsx | 1 + .../workflows/config/ActionConfig.tsx | 5 ++++- src/components/workflows/nodes/ActionNode.tsx | 4 +++- src/lib/workflow/actionExecutor.ts | 19 +++++++++++++++++++ src/pages/workflows/[id]/runs/[runId].tsx | 4 ++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/components/workflows/NodePalette.tsx b/src/components/workflows/NodePalette.tsx index 4ffc7c4..632db56 100644 --- a/src/components/workflows/NodePalette.tsx +++ b/src/components/workflows/NodePalette.tsx @@ -27,6 +27,7 @@ const actionItems: PaletteItem[] = [ { type: "action", subType: "unfavorite", label: "Unfavorite", icon: HeartOff, color: "text-purple-500" }, { type: "action", subType: "archive", label: "Archive", icon: Archive, color: "text-purple-500" }, { type: "action", subType: "tag", label: "Add Tag", icon: Tag, color: "text-purple-500" }, + { type: "action", subType: "remove_tag", label: "Remove Tag", icon: Tag, color: "text-purple-500" }, ]; function PaletteGroup({ title, items }: { title: string; items: PaletteItem[] }) { diff --git a/src/components/workflows/config/ActionConfig.tsx b/src/components/workflows/config/ActionConfig.tsx index 09a62cc..cc15cb0 100644 --- a/src/components/workflows/config/ActionConfig.tsx +++ b/src/components/workflows/config/ActionConfig.tsx @@ -115,7 +115,7 @@ export default function ActionConfig({ subType, config, onChange }: ActionConfig ); } - if (subType === "tag") { + if (subType === "tag" || subType === "remove_tag") { return (
@@ -125,6 +125,9 @@ export default function ActionConfig({ subType, config, onChange }: ActionConfig value={config.tagName || ""} onChange={(e) => onChange({ ...config, tagName: e.target.value })} /> + {subType === "remove_tag" && ( +

Removes this tag from matched assets. If the tag doesn't exist, nothing happens.

+ )}
); } diff --git a/src/components/workflows/nodes/ActionNode.tsx b/src/components/workflows/nodes/ActionNode.tsx index fea2f50..08f937e 100644 --- a/src/components/workflows/nodes/ActionNode.tsx +++ b/src/components/workflows/nodes/ActionNode.tsx @@ -9,6 +9,7 @@ const actionIcons: Record = { unfavorite: HeartOff, archive: Archive, tag: Tag, + remove_tag: Tag, }; const actionLabels: Record = { @@ -19,6 +20,7 @@ const actionLabels: Record = { unfavorite: "Unfavorite", archive: "Archive", tag: "Add Tag", + remove_tag: "Remove Tag", }; export default function ActionNode({ data, selected }: NodeProps) { @@ -42,7 +44,7 @@ export default function ActionNode({ data, selected }: NodeProps) { {(subType === "add_to_album" || subType === "remove_from_album") && config.albumName && (

{config.albumName}

)} - {subType === "tag" && config.tagName && ( + {(subType === "tag" || subType === "remove_tag") && config.tagName && (

{config.tagName}

)} diff --git a/src/lib/workflow/actionExecutor.ts b/src/lib/workflow/actionExecutor.ts index 1fd09b1..244ecb6 100644 --- a/src/lib/workflow/actionExecutor.ts +++ b/src/lib/workflow/actionExecutor.ts @@ -180,6 +180,25 @@ export async function executeAction( } } + case "remove_tag": { + if (!config.tagName) throw new Error("Tag name is required"); + try { + // Look up the tag by value (full path for nested tags) without creating it — + // removing a tag that doesn't exist is a no-op, not an error. + const result = await db.execute( + sql`SELECT id FROM "tag" WHERE "userId" = ${user.id} AND "value" = ${config.tagName} LIMIT 1` + ); + const tagId = result.rows?.[0]?.id as string | undefined; + if (!tagId) { + return { action: "remove_tag", assetsProcessed: 0 }; + } + await immichFetch(`/tags/${tagId}/assets`, "DELETE", { ids: assetIds }, user); + return { action: "remove_tag", assetsProcessed: assetIds.length }; + } catch (e: any) { + return { action: "remove_tag", assetsProcessed: 0, error: e.message }; + } + } + default: return { action: subType, assetsProcessed: 0, error: `Unknown action: ${subType}` }; } diff --git a/src/pages/workflows/[id]/runs/[runId].tsx b/src/pages/workflows/[id]/runs/[runId].tsx index 14f6e6c..eb261c8 100644 --- a/src/pages/workflows/[id]/runs/[runId].tsx +++ b/src/pages/workflows/[id]/runs/[runId].tsx @@ -135,11 +135,11 @@ function AnnotatedActionNode({ data }: NodeProps) { const step = data.runStep as any; const icons: Record = { create_album: FolderPlus, add_to_album: FolderInput, remove_from_album: FolderMinus, - favorite: Heart, unfavorite: HeartOff, archive: Archive, tag: Tag, + favorite: Heart, unfavorite: HeartOff, archive: Archive, tag: Tag, remove_tag: Tag, }; const labels: Record = { create_album: "Create Album", add_to_album: "Add to Album", remove_from_album: "Remove from Album", - favorite: "Favorite", unfavorite: "Unfavorite", archive: "Archive", tag: "Add Tag", + favorite: "Favorite", unfavorite: "Unfavorite", archive: "Archive", tag: "Add Tag", remove_tag: "Remove Tag", }; const Icon = icons[subType] || FolderPlus; const isDryRun = step?.detail?.includes("DRY RUN"); From 40e9e0dde2854784fe4398d18f9f47ecddf48df2 Mon Sep 17 00:00:00 2001 From: Varun Raj Date: Fri, 10 Jul 2026 15:48:29 +0000 Subject: [PATCH 2/2] fix: resolve tag via Immich API instead of local DB table in remove_tag The local tag table can lag behind Immich's own tag state (e.g. tags created directly in Immich, or before this app's sync ran), causing remove_tag to silently no-op on a tag that actually exists. Mirror the sibling "tag" action's approach and resolve against the Immich API, matching on the tag's full-path "value" field. Drops the now-unused db/sql local lookup. --- src/lib/workflow/actionExecutor.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib/workflow/actionExecutor.ts b/src/lib/workflow/actionExecutor.ts index 244ecb6..f325cba 100644 --- a/src/lib/workflow/actionExecutor.ts +++ b/src/lib/workflow/actionExecutor.ts @@ -6,7 +6,7 @@ import { exif } from "@/schema"; import { assets } from "@/schema/assets.schema"; import { person } from "@/schema/person.schema"; import { assetFaces } from "@/schema/assetFaces.schema"; -import { eq, and, inArray, sql, desc } from "drizzle-orm"; +import { eq, and, inArray, desc } from "drizzle-orm"; import { IUser } from "@/types/user"; import { getUserHeaders } from "@/helpers/user.helper"; @@ -183,16 +183,15 @@ export async function executeAction( case "remove_tag": { if (!config.tagName) throw new Error("Tag name is required"); try { - // Look up the tag by value (full path for nested tags) without creating it — - // removing a tag that doesn't exist is a no-op, not an error. - const result = await db.execute( - sql`SELECT id FROM "tag" WHERE "userId" = ${user.id} AND "value" = ${config.tagName} LIMIT 1` - ); - const tagId = result.rows?.[0]?.id as string | undefined; - if (!tagId) { + // Look up the tag via Immich's API (same source of truth the "tag" + // action creates/gets from) without creating it — removing a tag + // that doesn't exist is a no-op, not an error. + const tags = await immichFetch("/tags", "GET", undefined, user); + const tag = Array.isArray(tags) ? tags.find((t: any) => t.value === config.tagName) : undefined; + if (!tag) { return { action: "remove_tag", assetsProcessed: 0 }; } - await immichFetch(`/tags/${tagId}/assets`, "DELETE", { ids: assetIds }, user); + await immichFetch(`/tags/${tag.id}/assets`, "DELETE", { ids: assetIds }, user); return { action: "remove_tag", assetsProcessed: assetIds.length }; } catch (e: any) { return { action: "remove_tag", assetsProcessed: 0, error: e.message };