Skip to content

Commit e6ec110

Browse files
authored
feat: make log viewer component dynamic (#1242)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new Log Viewer configuration component to enhance the management and application of log settings. - **Chores** - Removed the legacy log viewer interface to streamline log management and improve the overall user experience. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 20b0aeb commit e6ec110

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Logger } from '@nestjs/common';
2+
import { readFile, rm, writeFile } from 'node:fs/promises';
3+
4+
import { fileExists } from '@app/core/utils/files/file-exists.js';
5+
import {
6+
FileModification,
7+
ShouldApplyWithReason,
8+
} from '@app/unraid-api/unraid-file-modifier/file-modification.js';
9+
10+
export class LogViewerModification extends FileModification {
11+
id: string = 'log-viewer';
12+
public readonly filePath: string =
13+
'/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page' as const;
14+
15+
private readonly logViewerConfig: string = `
16+
Menu="UNRAID-OS"
17+
Title="Log Viewer (new)"
18+
Icon="icon-log"
19+
Tag="list"
20+
---
21+
<unraid-i18n-host>
22+
<unraid-log-viewer></unraid-log-viewer>
23+
</unraid-i18n-host>
24+
25+
`.trimStart();
26+
27+
constructor(logger: Logger) {
28+
super(logger);
29+
}
30+
31+
protected async generatePatch(overridePath?: string): Promise<string> {
32+
const currentContent = (await fileExists(this.filePath))
33+
? await readFile(this.filePath, 'utf8')
34+
: '';
35+
36+
return this.createPatchWithDiff(
37+
overridePath ?? this.filePath,
38+
currentContent,
39+
this.logViewerConfig
40+
);
41+
}
42+
43+
async shouldApply(): Promise<ShouldApplyWithReason> {
44+
const alreadyConfigured = await fileExists(this.filePath);
45+
if (alreadyConfigured) {
46+
return { shouldApply: false, reason: 'LogViewer configuration already exists' };
47+
}
48+
return { shouldApply: true, reason: 'No LogViewer config for the API configured yet' };
49+
}
50+
51+
async apply(): Promise<string> {
52+
await this.rollback();
53+
await writeFile(this.filePath, this.logViewerConfig, { mode: 0o644 });
54+
return this.logViewerConfig;
55+
}
56+
57+
async rollback(): Promise<void> {
58+
await rm(this.getPathToAppliedPatch(), { force: true });
59+
await rm(this.filePath, { force: true });
60+
}
61+
}

api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modi
44
import AuthRequestModification from '@app/unraid-api/unraid-file-modifier/modifications/auth-request.modification.js';
55
import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.js';
66
import { LogRotateModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.js';
7+
import { LogViewerModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.js';
78
import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.js';
89
import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification.js';
910

@@ -42,6 +43,7 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest
4243
async loadModifications(): Promise<FileModification[]> {
4344
const modifications: FileModification[] = [];
4445
const modificationClasses: Array<new (logger: Logger) => FileModification> = [
46+
LogViewerModification,
4547
LogRotateModification,
4648
AuthRequestModification,
4749
SSOFileModification,

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)