mirror of
https://github.com/unraid/api.git
synced 2025-12-31 05:29:48 -06:00
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 -->
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
@@ -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<FileModification[]> {
|
||||
const modifications: FileModification[] = [];
|
||||
const modificationClasses: Array<new (logger: Logger) => FileModification> = [
|
||||
LogViewerModification,
|
||||
LogRotateModification,
|
||||
AuthRequestModification,
|
||||
SSOFileModification,
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
Menu="UNRAID-OS"
|
||||
Title="Log Viewer (new)"
|
||||
Icon="icon-log"
|
||||
Tag="list"
|
||||
---
|
||||
<?php
|
||||
/* Copyright 2005-2023, Lime Technology
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<unraid-i18n-host>
|
||||
<unraid-log-viewer></unraid-log-viewer>
|
||||
</unraid-i18n-host>
|
||||
Reference in New Issue
Block a user