From d27955ed90bffe6a039b41c03d40276f8cf7d824 Mon Sep 17 00:00:00 2001 From: "jeanchristophe.mqt@gmail.com" Date: Fri, 22 Mar 2024 23:05:28 +0100 Subject: [PATCH] Fix eslint warnings and errors --- .../1.0.0/index.js | 57 +++++++----- .../1.0.0/index.ts | 87 +++++++++++-------- 2 files changed, 87 insertions(+), 57 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.js index 40b46d9..feff620 100644 --- a/FlowPlugins/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.js @@ -55,7 +55,8 @@ var fileMoveOrCopy_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/fi var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); var details = function () { return ({ name: 'Apply Radarr or Sonarr naming policy', - description: 'Apply Radarr or Sonarr naming policy to a file. This plugin should be called after the original file has been replaced and Radarr or Sonarr has been notified. Radarr or Sonarr should also be notified after this plugin.', + description: 'Apply Radarr or Sonarr naming policy to a file. This plugin should be called after the original file has been ' + + 'replaced and Radarr or Sonarr has been notified. Radarr or Sonarr should also be notified after this plugin.', style: { borderColor: 'green', }, @@ -111,8 +112,8 @@ var details = function () { return ({ { number: 2, tooltip: 'Radarr or Sonnar do not know this file', - } - ] + }, + ], }); }; exports.details = details; var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () { @@ -130,7 +131,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function filePath = (_c = (_b = args.originalLibraryFile) === null || _b === void 0 ? void 0 : _b._id) !== null && _c !== void 0 ? _c : ''; fileNames = { originalFileName: (0, fileUtils_1.getFileName)((_e = (_d = args.originalLibraryFile) === null || _d === void 0 ? void 0 : _d._id) !== null && _e !== void 0 ? _e : ''), - currentFileName: (0, fileUtils_1.getFileName)((_g = (_f = args.inputFileObj) === null || _f === void 0 ? void 0 : _f._id) !== null && _g !== void 0 ? _g : '') + currentFileName: (0, fileUtils_1.getFileName)((_g = (_f = args.inputFileObj) === null || _f === void 0 ? void 0 : _f._id) !== null && _g !== void 0 ? _g : ''), }; getNewPath = function (getNewPathType) { return __awaiter(void 0, void 0, void 0, function () { var output, headers, getParseRequestResult, fileName, parseRequestResult, previewRenameRequestConfig, previewRenameRequestResult, fileToRename, _a; @@ -139,7 +140,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function case 0: output = { newPath: '', - isSuccessful: false + isSuccessful: false, }; args.jobLog('Going to apply new name'); args.jobLog("Renaming ".concat(getNewPathType.appName, "...")); @@ -162,8 +163,8 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function case 1: parseRequestResult = _a.sent(); id = getNewPathType.delegates.getIdFromParseRequestResult(parseRequestResult); - args.jobLog(id !== '-1' ? - "Found ".concat(getNewPathType.contentName, " ").concat(id, " with a file named '").concat(fileName, "'") + args.jobLog(id !== '-1' + ? "Found ".concat(getNewPathType.contentName, " ").concat(id, " with a file named '").concat(fileName, "'") : "Didn't find ".concat(getNewPathType.contentName, " with a file named '").concat(fileName, "' in ").concat(arrHost, ".")); return [2 /*return*/, { requestResult: parseRequestResult, id: id }]; } @@ -173,7 +174,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function return [4 /*yield*/, getParseRequestResult(fileName)]; case 1: parseRequestResult = _b.sent(); - if (!(parseRequestResult.id == '-1' && fileNames.currentFileName !== fileNames.originalFileName)) return [3 /*break*/, 3]; + if (!(parseRequestResult.id === '-1' && fileNames.currentFileName !== fileNames.originalFileName)) return [3 /*break*/, 3]; fileName = fileNames.currentFileName; return [4 /*yield*/, getParseRequestResult(fileName)]; case 2: @@ -189,7 +190,8 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function return [4 /*yield*/, args.deps.axios(previewRenameRequestConfig)]; case 4: previewRenameRequestResult = _b.sent(); - fileToRename = getNewPathType.delegates.getFileToRenameFromPreviewRenameRequestResult(previewRenameRequestResult); + fileToRename = getNewPathType.delegates + .getFileToRenameFromPreviewRenameRequestResult(previewRenameRequestResult); if (!(fileToRename !== undefined)) return [3 /*break*/, 6]; output.newPath = "".concat((0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id), "/").concat((0, fileUtils_1.getFileName)(fileToRename.newPath), ".").concat((0, fileUtils_1.getContainer)(fileToRename.newPath)); _a = output; @@ -201,7 +203,8 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function })]; case 5: _a.isSuccessful = _b.sent(); - args.jobLog("\u2714 Renamed ".concat(getNewPathType.contentName, " ").concat(parseRequestResult.id, " : '").concat(filePath, "' => '").concat(output.newPath, "'.")); + args.jobLog("\u2714 Renamed ".concat(getNewPathType.contentName, " ").concat(parseRequestResult.id, " : ") + + "'".concat(filePath, "' => '").concat(output.newPath, "'.")); return [3 /*break*/, 7]; case 6: output.isSuccessful = true; @@ -221,11 +224,11 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function buildPreviewRenameResquestUrl: function (parseRequestResult) { return "".concat(arrHost, "/api/v3/rename?movieId=").concat(parseRequestResult.id); }, getFileToRenameFromPreviewRenameRequestResult: function (previewRenameRequestResult) { var _a, _b; - return (((_b = (_a = previewRenameRequestResult.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ? - previewRenameRequestResult.data[0] - : undefined; - } - } + return ((((_b = (_a = previewRenameRequestResult.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) + ? previewRenameRequestResult.data[0] + : undefined); + }, + }, }, sonarr: { appName: 'Sonarr', @@ -234,22 +237,30 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function getIdFromParseRequestResult: function (parseRequestResult) { var _a, _b, _c; return String((_c = (_b = (_a = parseRequestResult.data) === null || _a === void 0 ? void 0 : _a.series) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : -1); }, buildPreviewRenameResquestUrl: function (parseRequestResult) { episodeNumber = parseRequestResult.requestResult.data.parsedEpisodeInfo.episodeNumbers[0]; - return "".concat(arrHost, "/api/v3/rename?seriesId=").concat(parseRequestResult.id, "&seasonNumber=").concat(parseRequestResult.requestResult.data.parsedEpisodeInfo.seasonNumber); + return "".concat(arrHost, "/api/v3/rename?") + + "seriesId=".concat(parseRequestResult.id) + + "&seasonNumber=".concat(parseRequestResult.requestResult.data.parsedEpisodeInfo.seasonNumber); }, getFileToRenameFromPreviewRenameRequestResult: function (previewRenameRequestResult) { var _a, _b; - return (((_b = (_a = previewRenameRequestResult.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ? - previewRenameRequestResult.data.find(function (episodeFile) { var _a, _b; return (((_b = (_a = episodeFile.episodeNumbers) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ? episodeFile.episodeNumbers[0] === episodeNumber : false; }) - : undefined; - } - } - } + return ((((_b = (_a = previewRenameRequestResult.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) + ? previewRenameRequestResult.data.find(function (episodeFile) { + var _a, _b; + return ((((_b = (_a = episodeFile.episodeNumbers) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) + ? episodeFile.episodeNumbers[0] === episodeNumber + : false); + }) + : undefined); + }, + }, + }, }; return [4 /*yield*/, getNewPath(arr === 'radarr' ? getNewPathTypes.radarr : getNewPathTypes.sonarr)]; case 1: newPathOutput = _h.sent(); return [2 /*return*/, { - outputFileObj: newPathOutput.isSuccessful && newPathOutput.newPath !== '' ? __assign(__assign({}, args.inputFileObj), { _id: newPathOutput.newPath }) : args.inputFileObj, + outputFileObj: newPathOutput.isSuccessful && newPathOutput.newPath !== '' + ? __assign(__assign({}, args.inputFileObj), { _id: newPathOutput.newPath }) : args.inputFileObj, outputNumber: newPathOutput.isSuccessful ? 1 : 2, variables: args.variables, }]; diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.ts index 456996a..2937157 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/applyRadarrOrSonarrNamingPolicy/1.0.0/index.ts @@ -10,7 +10,9 @@ import { const details = (): IpluginDetails => ({ name: 'Apply Radarr or Sonarr naming policy', - description: 'Apply Radarr or Sonarr naming policy to a file. This plugin should be called after the original file has been replaced and Radarr or Sonarr has been notified. Radarr or Sonarr should also be notified after this plugin.', + description: + 'Apply Radarr or Sonarr naming policy to a file. This plugin should be called after the original file has been ' + + 'replaced and Radarr or Sonarr has been notified. Radarr or Sonarr should also be notified after this plugin.', style: { borderColor: 'green', }, @@ -66,8 +68,8 @@ const details = (): IpluginDetails => ({ { number: 2, tooltip: 'Radarr or Sonnar do not know this file', - } - ] + }, + ], }); interface IFileNames { @@ -108,15 +110,15 @@ const plugin = async (args: IpluginInputArgs): Promise => { const filePath = args.originalLibraryFile?._id ?? ''; const fileNames: IFileNames = { originalFileName: getFileName(args.originalLibraryFile?._id ?? ''), - currentFileName: getFileName(args.inputFileObj?._id ?? '') + currentFileName: getFileName(args.inputFileObj?._id ?? ''), }; const getNewPath = async (getNewPathType: IGetNewPathType) : Promise => { const output: IGetNewPathOutput = { newPath: '', - isSuccessful: false - } + isSuccessful: false, + }; args.jobLog('Going to apply new name'); args.jobLog(`Renaming ${getNewPathType.appName}...`); @@ -136,16 +138,16 @@ const plugin = async (args: IpluginInputArgs): Promise => { }; const parseRequestResult = await args.deps.axios(parseRequestConfig); const id = getNewPathType.delegates.getIdFromParseRequestResult(parseRequestResult); - args.jobLog(id !== '-1' ? - `Found ${getNewPathType.contentName} ${id} with a file named '${fileName}'` + args.jobLog(id !== '-1' + ? `Found ${getNewPathType.contentName} ${id} with a file named '${fileName}'` : `Didn't find ${getNewPathType.contentName} with a file named '${fileName}' in ${arrHost}.`); - return { requestResult: parseRequestResult, id: id }; - } + return { requestResult: parseRequestResult, id }; + }; let fileName = fileNames.originalFileName; let parseRequestResult = await getParseRequestResult(fileName); // In case there has been a name change and the arr app already noticed it. - if (parseRequestResult.id == '-1' && fileNames.currentFileName !== fileNames.originalFileName) { + if (parseRequestResult.id === '-1' && fileNames.currentFileName !== fileNames.originalFileName) { fileName = fileNames.currentFileName; parseRequestResult = await getParseRequestResult(fileName); } @@ -159,11 +161,14 @@ const plugin = async (args: IpluginInputArgs): Promise => { headers, }; const previewRenameRequestResult = await args.deps.axios(previewRenameRequestConfig); - const fileToRename = getNewPathType.delegates.getFileToRenameFromPreviewRenameRequestResult(previewRenameRequestResult); + const fileToRename = getNewPathType.delegates + .getFileToRenameFromPreviewRenameRequestResult(previewRenameRequestResult); // Only if there is a rename to execute if (fileToRename !== undefined) { - output.newPath = `${getFileAbosluteDir(args.inputFileObj._id)}/${getFileName(fileToRename.newPath)}.${getContainer(fileToRename.newPath)}`; + output.newPath = `${getFileAbosluteDir(args.inputFileObj._id) + }/${getFileName(fileToRename.newPath) + }.${getContainer(fileToRename.newPath)}`; output.isSuccessful = await fileMoveOrCopy({ operation: 'move', @@ -171,7 +176,8 @@ const plugin = async (args: IpluginInputArgs): Promise => { destinationPath: output.newPath, args, }); - args.jobLog(`✔ Renamed ${getNewPathType.contentName} ${parseRequestResult.id} : '${filePath}' => '${output.newPath}'.`); + args.jobLog(`✔ Renamed ${getNewPathType.contentName} ${parseRequestResult.id} : ` + + `'${filePath}' => '${output.newPath}'.`); } else { output.isSuccessful = true; args.jobLog('✔ No rename necessary.'); @@ -187,34 +193,47 @@ const plugin = async (args: IpluginInputArgs): Promise => { appName: 'Radarr', contentName: 'movie', delegates: { - getIdFromParseRequestResult: (parseRequestResult) => String(parseRequestResult.data?.movie?.movieFile?.movieId ?? -1), - buildPreviewRenameResquestUrl: (parseRequestResult) => `${arrHost}/api/v3/rename?movieId=${parseRequestResult.id}`, - getFileToRenameFromPreviewRenameRequestResult: (previewRenameRequestResult) => - ((previewRenameRequestResult.data?.length ?? 0) > 0) ? - previewRenameRequestResult.data[0] - : undefined - } + getIdFromParseRequestResult: + (parseRequestResult) => String(parseRequestResult.data?.movie?.movieFile?.movieId ?? -1), + buildPreviewRenameResquestUrl: + (parseRequestResult) => `${arrHost}/api/v3/rename?movieId=${parseRequestResult.id}`, + getFileToRenameFromPreviewRenameRequestResult: + (previewRenameRequestResult) => (((previewRenameRequestResult.data?.length ?? 0) > 0) + ? previewRenameRequestResult.data[0] + : undefined), + }, }, sonarr: { appName: 'Sonarr', contentName: 'serie', delegates: { - getIdFromParseRequestResult: (parseRequestResult) => String(parseRequestResult.data?.series?.id ?? -1), - buildPreviewRenameResquestUrl: (parseRequestResult) => { - episodeNumber = parseRequestResult.requestResult.data.parsedEpisodeInfo.episodeNumbers[0]; - return `${arrHost}/api/v3/rename?seriesId=${parseRequestResult.id}&seasonNumber=${parseRequestResult.requestResult.data.parsedEpisodeInfo.seasonNumber}`; - }, - getFileToRenameFromPreviewRenameRequestResult: (previewRenameRequestResult) => - ((previewRenameRequestResult.data?.length ?? 0) > 0) ? - previewRenameRequestResult.data.find((episodeFile: { episodeNumbers: number[]; }) => ((episodeFile.episodeNumbers?.length ?? 0) > 0) ? episodeFile.episodeNumbers[0] === episodeNumber : false) - : undefined - } - } - } + getIdFromParseRequestResult: + (parseRequestResult) => String(parseRequestResult.data?.series?.id ?? -1), + buildPreviewRenameResquestUrl: + (parseRequestResult) => { + [episodeNumber] = parseRequestResult.requestResult.data.parsedEpisodeInfo.episodeNumbers; + return `${arrHost}/api/v3/rename?` + + `seriesId=${parseRequestResult.id}` + + `&seasonNumber=${parseRequestResult.requestResult.data.parsedEpisodeInfo.seasonNumber}`; + }, + getFileToRenameFromPreviewRenameRequestResult: + (previewRenameRequestResult) => (((previewRenameRequestResult.data?.length ?? 0) > 0) + ? previewRenameRequestResult.data.find( + (episodeFile: { episodeNumbers: number[]; }) => (((episodeFile.episodeNumbers?.length ?? 0) > 0) + ? episodeFile.episodeNumbers[0] === episodeNumber + : false), + ) + : undefined), + }, + }, + }; const newPathOutput = await getNewPath(arr === 'radarr' ? getNewPathTypes.radarr : getNewPathTypes.sonarr); return { - outputFileObj: newPathOutput.isSuccessful && newPathOutput.newPath !== '' ? { ...args.inputFileObj, _id: newPathOutput.newPath } : args.inputFileObj, + outputFileObj: + newPathOutput.isSuccessful && newPathOutput.newPath !== '' + ? { ...args.inputFileObj, _id: newPathOutput.newPath } + : args.inputFileObj, outputNumber: newPathOutput.isSuccessful ? 1 : 2, variables: args.variables, };