From d227d01241f9969dc7c15044211ed3bbce37f690 Mon Sep 17 00:00:00 2001 From: Eduard Marbach Date: Mon, 1 Apr 2024 19:59:23 +0200 Subject: [PATCH] refactor: logging --- .env.template | 1 + index.ts | 33 ++++++++++++++++++++++++++------- src/api.ts | 2 +- src/quality-profiles.ts | 6 +++++- src/recyclarr-importer.ts | 2 +- src/trash-guide.ts | 2 +- src/util.ts | 1 + 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/.env.template b/.env.template index 616f1cd..d3d076d 100644 --- a/.env.template +++ b/.env.template @@ -2,3 +2,4 @@ #SECRETS_LOCATION=/app/config/secrets.yml DRY_RUN=true LOAD_LOCAL_SAMPLES=false +DEBUG_CREATE_FILES=false diff --git a/index.ts b/index.ts index 1989058..de5b8e0 100644 --- a/index.ts +++ b/index.ts @@ -15,7 +15,7 @@ import { import { cloneRecyclarrTemplateRepo, loadRecyclarrTemplates } from "./src/recyclarr-importer"; import { cloneTrashRepo, loadQualityDefinitionSonarrFromTrash, loadSonarrTrashCFs } from "./src/trash-guide"; import { ArrType, RecyclarrMergedTemplates, TrashQualityDefintion, YamlConfigInstance, YamlConfigQualityProfile } from "./src/types"; -import { IS_DRY_RUN } from "./src/util"; +import { DEBUG_CREATE_FILES, IS_DRY_RUN } from "./src/util"; const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => { const api = getArrApi(); @@ -27,7 +27,7 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => { }; if (value.include) { - console.log(`Recyclarr Includes: ${value.include}`); + console.log(`Recyclarr Includes:\n${value.include.map((e) => e.template).join("\n")}`); value.include.forEach((e) => { const template = recyclarrTemplateMap.get(e.template); @@ -66,8 +66,6 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => { recylarrMergedTemplates.quality_profiles = filterInvalidQualityProfiles(recylarrMergedTemplates.quality_profiles); - console.log(recylarrMergedTemplates); - const result = await loadLocalCfs(); const trashCFs = await loadSonarrTrashCFs(arrType); const mergedCFs = mergeCfSources([trashCFs, result]); @@ -165,9 +163,12 @@ const pipeline = async (value: YamlConfigInstance, arrType: ArrType) => { qpServer, ); - create.concat(changedQPs).forEach((e, i) => { - fs.writeFileSync(`test${i}.json`, JSON.stringify(e, null, 2), "utf-8"); - }); + if (DEBUG_CREATE_FILES) { + create.concat(changedQPs).forEach((e, i) => { + fs.writeFileSync(`test${i}.json`, JSON.stringify(e, null, 2), "utf-8"); + }); + } + console.log(`QPs: Create: ${create.length}, Update: ${changedQPs.length}, Unchanged: ${noChanges.length}`); if (!IS_DRY_RUN) { @@ -249,6 +250,15 @@ const run = async () => { unsetApi(); } + if ( + typeof applicationConfig.sonarr === "object" && + !Array.isArray(applicationConfig.sonarr) && + applicationConfig.sonarr !== null && + Object.keys(applicationConfig.sonarr).length <= 0 + ) { + console.log(`No sonarr instances defined.`); + } + for (const instanceName in applicationConfig.radarr) { console.log(`Processing Radarr instance: ${instanceName}`); const instance = applicationConfig.radarr[instanceName]; @@ -256,6 +266,15 @@ const run = async () => { await pipeline(instance, "RADARR"); unsetApi(); } + + if ( + typeof applicationConfig.radarr === "object" && + !Array.isArray(applicationConfig.radarr) && + applicationConfig.radarr !== null && + Object.keys(applicationConfig.radarr).length <= 0 + ) { + console.log(`No radarr instances defined.`); + } }; run(); diff --git a/src/api.ts b/src/api.ts index c650876..80e8249 100644 --- a/src/api.ts +++ b/src/api.ts @@ -108,7 +108,7 @@ export const configureRadarrApi = async (url: string, apiKey: string) => { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx - message = `Could not load from Sonarr API: Status ${error.response.status} - ${error.response.statusText}`; + message = `Could not load from Radarr API: Status ${error.response.status} - ${error.response.statusText}`; } else if (error.request) { // The request was made but no response was received // `error.request` is an instance of XMLHttpRequest in the browser and an instance of diff --git a/src/quality-profiles.ts b/src/quality-profiles.ts index 830f622..a721e67 100644 --- a/src/quality-profiles.ts +++ b/src/quality-profiles.ts @@ -430,7 +430,11 @@ export const calculateQualityProfilesDiff = async ( noChangedQPs.push(value.name); } - console.log(changeList); + if (changeList.length > 0) { + console.log(`ChangeList for QualityProfile:\n`, changeList); + } else { + console.log(`QualityProfile has no changes.`); + } } return { create: createQPs, changedQPs: changedQPs, noChanges: noChangedQPs }; diff --git a/src/recyclarr-importer.ts b/src/recyclarr-importer.ts index e0df7fd..7579959 100644 --- a/src/recyclarr-importer.ts +++ b/src/recyclarr-importer.ts @@ -25,7 +25,7 @@ export const cloneRecyclarrTemplateRepo = async () => { await gitClient.checkout(applicationConfig.trashRevision ?? "master"); - console.log(`Recyclarr Git Check`, r); + console.log(`Updating Recyclarr repo`); }; export const loadRecyclarrTemplates = (arrType: ArrType) => { diff --git a/src/trash-guide.ts b/src/trash-guide.ts index 8187284..37be9d5 100644 --- a/src/trash-guide.ts +++ b/src/trash-guide.ts @@ -35,7 +35,7 @@ export const cloneTrashRepo = async () => { await gitClient.checkout(applicationConfig.trashRevision ?? "master"); - console.log(`TrashGuide Git Check`, r); + console.log(`Updating TrashGuide repo`); }; export const loadSonarrTrashCFs = async (arrType: ArrType): Promise => { diff --git a/src/util.ts b/src/util.ts index dd08b80..ae88863 100644 --- a/src/util.ts +++ b/src/util.ts @@ -4,6 +4,7 @@ import { ConfigarrCF, ImportCF, TrashCF, UserFriendlyField } from "./types"; export const IS_DRY_RUN = process.env.DRY_RUN === "true"; export const IS_LOCAL_SAMPLE_MODE = process.env.LOAD_LOCAL_SAMPLES === "true"; +export const DEBUG_CREATE_FILES = process.env.DEBUG_CREATE_FILES === "true"; export const repoPath = path.resolve(process.env.CUSTOM_REPO_ROOT || "./repos");