Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
---
<unraid-i18n-host>
<unraid-log-viewer></unraid-log-viewer>
</unraid-i18n-host>

`.trimStart();

constructor(logger: Logger) {
super(logger);
}

protected async generatePatch(overridePath?: string): Promise<string> {
const currentContent = (await fileExists(this.filePath))
? await readFile(this.filePath, 'utf8')
: '';

return this.createPatchWithDiff(
overridePath ?? this.filePath,
currentContent,
this.logViewerConfig
);
}

async shouldApply(): Promise<ShouldApplyWithReason> {
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<string> {
await this.rollback();
await writeFile(this.filePath, this.logViewerConfig, { mode: 0o644 });
return this.logViewerConfig;
}

async rollback(): Promise<void> {
await rm(this.getPathToAppliedPatch(), { force: true });
await rm(this.filePath, { force: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -42,6 +43,7 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest
async loadModifications(): Promise<FileModification[]> {
const modifications: FileModification[] = [];
const modificationClasses: Array<new (logger: Logger) => FileModification> = [
LogViewerModification,
LogRotateModification,
AuthRequestModification,
SSOFileModification,
Expand Down

This file was deleted.

Loading