diff --git a/api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts b/api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts new file mode 100644 index 000000000..dbae2e7d6 --- /dev/null +++ b/api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts @@ -0,0 +1,61 @@ +import { Logger } from '@nestjs/common'; +import { readFile, rm, writeFile } from 'node:fs/promises'; + +import { fileExists } from '@app/core/utils/files/file-exists.js'; +import { + FileModification, + ShouldApplyWithReason, +} from '@app/unraid-api/unraid-file-modifier/file-modification.js'; + +export class LogViewerModification extends FileModification { + id: string = 'log-viewer'; + public readonly filePath: string = + '/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page' as const; + + private readonly logViewerConfig: string = ` +Menu="UNRAID-OS" +Title="Log Viewer (new)" +Icon="icon-log" +Tag="list" +--- + + + + +`.trimStart(); + + constructor(logger: Logger) { + super(logger); + } + + protected async generatePatch(overridePath?: string): Promise { + const currentContent = (await fileExists(this.filePath)) + ? await readFile(this.filePath, 'utf8') + : ''; + + return this.createPatchWithDiff( + overridePath ?? this.filePath, + currentContent, + this.logViewerConfig + ); + } + + async shouldApply(): Promise { + const alreadyConfigured = await fileExists(this.filePath); + if (alreadyConfigured) { + return { shouldApply: false, reason: 'LogViewer configuration already exists' }; + } + return { shouldApply: true, reason: 'No LogViewer config for the API configured yet' }; + } + + async apply(): Promise { + await this.rollback(); + await writeFile(this.filePath, this.logViewerConfig, { mode: 0o644 }); + return this.logViewerConfig; + } + + async rollback(): Promise { + await rm(this.getPathToAppliedPatch(), { force: true }); + await rm(this.filePath, { force: true }); + } +} 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 363934d90..27d4b3f08 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 @@ -4,6 +4,7 @@ import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modi import AuthRequestModification from '@app/unraid-api/unraid-file-modifier/modifications/auth-request.modification.js'; import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.js'; import { LogRotateModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.js'; +import { LogViewerModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.js'; import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.js'; import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification.js'; @@ -42,6 +43,7 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest async loadModifications(): Promise { const modifications: FileModification[] = []; const modificationClasses: Array FileModification> = [ + LogViewerModification, LogRotateModification, AuthRequestModification, SSOFileModification, diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page deleted file mode 100644 index 8af0343cc..000000000 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page +++ /dev/null @@ -1,19 +0,0 @@ -Menu="UNRAID-OS" -Title="Log Viewer (new)" -Icon="icon-log" -Tag="list" ---- - - - -