From 14faeb38a98e6dd2c1d32425327f9ef4a0ac6a4e Mon Sep 17 00:00:00 2001 From: sascha Date: Fri, 17 Jul 2026 19:39:45 +0200 Subject: [PATCH] feat: Radarr import - add skip-guard to avoid unnecessary API calls --- .../scripts/Radarr_-_Trigger_Manual_Import.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fileflows/scripts/Radarr_-_Trigger_Manual_Import.js b/fileflows/scripts/Radarr_-_Trigger_Manual_Import.js index 4fcea78..5b24baf 100644 --- a/fileflows/scripts/Radarr_-_Trigger_Manual_Import.js +++ b/fileflows/scripts/Radarr_-_Trigger_Manual_Import.js @@ -1,3 +1,17 @@ +/** + * @name Radarr - Trigger Manual Import + * @description Trigger Radarr ManualImport or downloadedMoviesScan with skip-guard. + * @author FileFlows + Sascha + * @revision 9 + * @output Import erfolgreich + * @output Fehler + * @param {string} URL Radarr root URL and port + * @param {string} ApiKey Radarr API Key + * @param {string} ImportPath Output path for import triggering + * @param {bool} UseUnmappedPath Whether to Unmap the path + * @param {bool} MoveMode Import mode: true=move, false=copy + * @param {int} TimeOut Timeout in seconds (max 3600) + */ import { Radarr } from 'Shared/Radarr'; @@ -9,6 +23,22 @@ function Script(URL, ApiKey, ImportPath, UseUnmappedPath, MoveMode, TimeOut) { ImportPath = UseUnmappedPath ? Flow.UnMapPath(ImportPath) : ImportPath; const importMode = MoveMode ? 'move' : 'copy'; + // ── SKIP-GUARD: Nur API-Call machen, wenn der aktuelle ImportPath + // mit dem konfigurierten Pfad uebereinstimmt. Sonst sofort OK. + // Das verhindert 3 unnoetige API-Calls pro Datei (4 Arr-Instanzen). + if (ImportPath && ImportPath.indexOf(URL) === -1) { + // ImportPath ist ein Dateipfad, URL ist die Radarr-Instanz-URL. + // Pruefe ob der ImportPath unter dem erwarteten Verzeichnis liegt. + // Die Flow-Konfiguration setzt ImportPath z.B. auf /tdarr/converted/video4k/ + // oder /tdarr/converted/video/. Wenn der aktuelle file.FullName nicht + // darunter liegt, sind wir nicht zustaendig. + var currentFile = Variables['file.FullName'] || ''; + if (currentFile && ImportPath && currentFile.indexOf(ImportPath) === -1) { + Logger.ILog(`Skip: current file '${currentFile}' not under ImportPath '${ImportPath}' - not responsible`); + return 1; + } + } + const radarr = new Radarr(URL, ApiKey); /*── movieId detection ──────────────────────────────────*/