feat: Sonarr import - add skip-guard to avoid unnecessary API calls

This commit is contained in:
sascha 2026-07-17 19:39:45 +02:00
parent 14faeb38a9
commit 88001b1ce0

View file

@ -1,3 +1,17 @@
/**
* @name Sonarr - Trigger Manual Import
* @description Trigger Sonarr ManualImport or downloadedEpisodesScan with skip-guard.
* @author FileFlows + Sascha
* @revision 8
* @output Import erfolgreich
* @output Fehler
* @param {string} URL Sonarr root URL and port
* @param {string} ApiKey Sonarr 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 { Sonarr } from 'Shared/Sonarr';
@ -9,6 +23,17 @@ 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) {
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 sonarr = new Sonarr(URL, ApiKey);
/*── seriesId / episodeId detection ──────────────────────────────────*/