diff --git a/api/src/unraid-api/unraid-file-modifier/file-modification.ts b/api/src/unraid-api/unraid-file-modifier/file-modification.ts index a4c83ad92..6e8a3b701 100644 --- a/api/src/unraid-api/unraid-file-modifier/file-modification.ts +++ b/api/src/unraid-api/unraid-file-modifier/file-modification.ts @@ -15,7 +15,7 @@ export abstract class FileModification { abstract id: string; public abstract readonly filePath: string; - protected constructor(protected readonly logger: Logger) {} + public constructor(protected readonly logger: Logger) {} // This is the main method that child classes need to implement protected abstract generatePatch(): Promise; diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts index b7fa13ba9..2d1988127 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts @@ -8,9 +8,10 @@ import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modi import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification'; import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification'; import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification'; +import { existsSync } from 'fs'; interface ModificationTestCase { - ModificationClass: new (logger: Logger) => FileModification; + ModificationClass: typeof FileModification; fileUrl: string; } @@ -37,8 +38,13 @@ async function testModification(testCase: ModificationTestCase) { const fileName = basename(testCase.fileUrl); const path = resolve(__dirname, `../__fixtures__/downloaded/${fileName}`); - const originalContent = await fetch(testCase.fileUrl).then((response) => response.text()); - await writeFile(path, originalContent); + let originalContent = ''; + if (!existsSync(path)) { + originalContent = await fetch(testCase.fileUrl).then((response) => response.text()); + await writeFile(path, originalContent); + } else { + originalContent = await readFile(path, 'utf-8'); + } expect(originalContent.length).toBeGreaterThan(0); diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.ts b/api/src/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.ts index 99a820a4e..e0b3b5200 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.ts @@ -13,10 +13,6 @@ export default class DefaultPageLayoutModification extends FileModification { public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php'; - constructor(logger: Logger) { - super(logger); - } - private addToaster(source: string): string { if (source.includes('unraid-toaster')) { return source; diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.ts b/api/src/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.ts index 1425d8186..417143dfb 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.ts @@ -12,10 +12,6 @@ export default class NotificationsPageModification extends FileModification { id: string = 'notifications-page'; public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/Notifications.page'; - constructor(logger: Logger) { - super(logger); - } - protected async generatePatch(): Promise { const fileContent = await readFile(this.filePath, 'utf-8'); diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts b/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts index 25145cb9b..aa7b7fc66 100644 --- a/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts +++ b/api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts @@ -7,10 +7,6 @@ export default class SSOFileModification extends FileModification { id: string = 'sso'; public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/include/.login.php'; - constructor(logger: Logger) { - super(logger); - } - protected async generatePatch(): Promise { // Define the new PHP function to insert /* eslint-disable no-useless-escape */ diff --git a/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts b/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts index ed8013d5a..a182f71ff 100644 --- a/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts +++ b/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts @@ -1,10 +1,11 @@ import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; + +import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification'; import AuthRequestModification from '@app/unraid-api/unraid-file-modifier/modifications/auth-request.modification'; import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification'; import { LogRotateModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-rotate.modification'; import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification'; import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification'; -import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification'; @Injectable() export class UnraidFileModificationService implements OnModuleInit, OnModuleDestroy { @@ -17,11 +18,9 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest const mods = await this.loadModifications(); await this.applyModifications(mods); } catch (err) { - if (err instanceof Error) { - this.logger.error(`Failed to apply modifications: ${err.message}`); - } else { - this.logger.error('Failed to apply modifications: Unknown error'); - } + this.logger.error( + `Failed to apply modifications: ${err instanceof Error ? err.message : 'Unknown error'}` + ); } }