From 7208a3b4fe6dd21b2c074c50e1d0580f0a7a2a1a Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 18 Nov 2023 14:43:22 +0100 Subject: [PATCH] Refactoring Job config and exposing it to messenger #753 --- .../model/jobs/jobs/AlbumCoverFillingJob.ts | 11 ++++++----- .../model/jobs/jobs/AlbumCoverResetJob.ts | 5 +++-- src/backend/model/jobs/jobs/AlbumResetJob.ts | 5 +++-- src/backend/model/jobs/jobs/FileJob.ts | 4 ++-- src/backend/model/jobs/jobs/GalleryResetJob.ts | 5 +++-- src/backend/model/jobs/jobs/IndexingJob.ts | 5 +++-- src/backend/model/jobs/jobs/Job.ts | 5 +++-- .../model/jobs/jobs/TempFolderCleaningJob.ts | 5 +++-- src/backend/model/jobs/jobs/TopPickSendJob.ts | 3 ++- src/common/entities/DynamicConfig.ts | 17 +++++++++++++++++ src/common/entities/job/JobDTO.ts | 10 ++-------- 11 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 src/common/entities/DynamicConfig.ts diff --git a/src/backend/model/jobs/jobs/AlbumCoverFillingJob.ts b/src/backend/model/jobs/jobs/AlbumCoverFillingJob.ts index 89ab10f5..62a3411d 100644 --- a/src/backend/model/jobs/jobs/AlbumCoverFillingJob.ts +++ b/src/backend/model/jobs/jobs/AlbumCoverFillingJob.ts @@ -1,10 +1,11 @@ import {ObjectManagers} from '../../ObjectManagers'; -import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; import {Job} from './Job'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; export class AlbumCoverFillingJob extends Job { public readonly Name = DefaultsJobs[DefaultsJobs['Album Cover Filling']]; - public readonly ConfigTemplate: ConfigTemplateEntry[] = null; + public readonly ConfigTemplate: DynamicConfig[] = null; directoryToSetCover: { id: number; name: string; path: string }[] = null; status: 'Persons' | 'Albums' | 'Directory' = 'Persons'; @@ -20,7 +21,7 @@ export class AlbumCoverFillingJob extends Job { if (!this.directoryToSetCover) { this.Progress.log('Loading Directories to process'); this.directoryToSetCover = - await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers(); + await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers(); this.Progress.Left = this.directoryToSetCover.length + 2; return true; } @@ -57,7 +58,7 @@ export class AlbumCoverFillingJob extends Job { private async stepDirectoryCover(): Promise { if (this.directoryToSetCover.length === 0) { this.directoryToSetCover = - await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers(); + await ObjectManagers.getInstance().CoverManager.getPartialDirsWithoutCovers(); // double check if there is really no more if (this.directoryToSetCover.length > 0) { return true; // continue @@ -70,7 +71,7 @@ export class AlbumCoverFillingJob extends Job { this.Progress.Left = this.directoryToSetCover.length; await ObjectManagers.getInstance().CoverManager.setAndGetCoverForDirectory( - directory + directory ); this.Progress.Processed++; return true; diff --git a/src/backend/model/jobs/jobs/AlbumCoverResetJob.ts b/src/backend/model/jobs/jobs/AlbumCoverResetJob.ts index 32ee08eb..07121827 100644 --- a/src/backend/model/jobs/jobs/AlbumCoverResetJob.ts +++ b/src/backend/model/jobs/jobs/AlbumCoverResetJob.ts @@ -1,10 +1,11 @@ import {ObjectManagers} from '../../ObjectManagers'; -import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; import {Job} from './Job'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; export class AlbumCoverRestJob extends Job { public readonly Name = DefaultsJobs[DefaultsJobs['Album Cover Reset']]; - public readonly ConfigTemplate: ConfigTemplateEntry[] = null; + public readonly ConfigTemplate: DynamicConfig[] = null; protected readonly IsInstant = true; public get Supported(): boolean { diff --git a/src/backend/model/jobs/jobs/AlbumResetJob.ts b/src/backend/model/jobs/jobs/AlbumResetJob.ts index 93967743..edae7ef9 100644 --- a/src/backend/model/jobs/jobs/AlbumResetJob.ts +++ b/src/backend/model/jobs/jobs/AlbumResetJob.ts @@ -1,10 +1,11 @@ import {ObjectManagers} from '../../ObjectManagers'; -import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; import {Job} from './Job'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; export class AlbumRestJob extends Job { public readonly Name = DefaultsJobs[DefaultsJobs['Album Reset']]; - public readonly ConfigTemplate: ConfigTemplateEntry[] = null; + public readonly ConfigTemplate: DynamicConfig[] = null; protected readonly IsInstant = true; public get Supported(): boolean { diff --git a/src/backend/model/jobs/jobs/FileJob.ts b/src/backend/model/jobs/jobs/FileJob.ts index f5295dbc..2159973b 100644 --- a/src/backend/model/jobs/jobs/FileJob.ts +++ b/src/backend/model/jobs/jobs/FileJob.ts @@ -1,4 +1,3 @@ -import {ConfigTemplateEntry} from '../../../../common/entities/job/JobDTO'; import {Job} from './Job'; import * as path from 'path'; import {Logger} from '../../../Logger'; @@ -13,6 +12,7 @@ import {ProjectPath} from '../../../ProjectPath'; import {FileEntity} from '../../database/enitites/FileEntity'; import {DirectoryBaseDTO, DirectoryDTOUtils} from '../../../../common/entities/DirectoryDTO'; import {DirectoryScanSettings, DiskManager} from '../../fileaccess/DiskManager'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; const LOG_TAG = '[FileJob]'; @@ -20,7 +20,7 @@ const LOG_TAG = '[FileJob]'; * Abstract class for thumbnail creation, file deleting etc. */ export abstract class FileJob extends Job { - public readonly ConfigTemplate: ConfigTemplateEntry[] = []; + public readonly ConfigTemplate: DynamicConfig[] = []; directoryQueue: string[] = []; fileQueue: string[] = []; DBProcessing = { diff --git a/src/backend/model/jobs/jobs/GalleryResetJob.ts b/src/backend/model/jobs/jobs/GalleryResetJob.ts index 00fa74e4..ee3c162f 100644 --- a/src/backend/model/jobs/jobs/GalleryResetJob.ts +++ b/src/backend/model/jobs/jobs/GalleryResetJob.ts @@ -1,10 +1,11 @@ import {ObjectManagers} from '../../ObjectManagers'; -import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; import {Job} from './Job'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; export class GalleryRestJob extends Job { public readonly Name = DefaultsJobs[DefaultsJobs['Gallery Reset']]; - public readonly ConfigTemplate: ConfigTemplateEntry[] = null; + public readonly ConfigTemplate: DynamicConfig[] = null; protected readonly IsInstant = true; public get Supported(): boolean { diff --git a/src/backend/model/jobs/jobs/IndexingJob.ts b/src/backend/model/jobs/jobs/IndexingJob.ts index 709d8271..65973e85 100644 --- a/src/backend/model/jobs/jobs/IndexingJob.ts +++ b/src/backend/model/jobs/jobs/IndexingJob.ts @@ -2,7 +2,7 @@ import {ObjectManagers} from '../../ObjectManagers'; import * as path from 'path'; import * as fs from 'fs'; import {Job} from './Job'; -import {ConfigTemplateEntry, DefaultsJobs,} from '../../../../common/entities/job/JobDTO'; +import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; import {JobProgressStates} from '../../../../common/entities/job/JobProgressDTO'; import {ProjectPath} from '../../../ProjectPath'; import {backendTexts} from '../../../../common/BackendTexts'; @@ -10,6 +10,7 @@ import {ParentDirectoryDTO} from '../../../../common/entities/DirectoryDTO'; import {Logger} from '../../../Logger'; import {FileDTO} from '../../../../common/entities/FileDTO'; import {DiskManager} from '../../fileaccess/DiskManager'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; const LOG_TAG = '[IndexingJob]'; @@ -18,7 +19,7 @@ export class IndexingJob< > extends Job { public readonly Name = DefaultsJobs[DefaultsJobs.Indexing]; directoriesToIndex: string[] = []; - public readonly ConfigTemplate: ConfigTemplateEntry[] = [ + public readonly ConfigTemplate: DynamicConfig[] = [ { id: 'indexChangesOnly', type: 'boolean', diff --git a/src/backend/model/jobs/jobs/Job.ts b/src/backend/model/jobs/jobs/Job.ts index c17639cc..36a7a0cb 100644 --- a/src/backend/model/jobs/jobs/Job.ts +++ b/src/backend/model/jobs/jobs/Job.ts @@ -1,9 +1,10 @@ import {Logger} from '../../../Logger'; import {IJob} from './IJob'; -import {ConfigTemplateEntry, JobDTO, JobDTOUtils,} from '../../../../common/entities/job/JobDTO'; +import {JobDTO, JobDTOUtils} from '../../../../common/entities/job/JobDTO'; import {JobProgress} from './JobProgress'; import {IJobListener} from './IJobListener'; import {JobProgressStates} from '../../../../common/entities/job/JobProgressDTO'; +import {DynamicConfig} from '../../../../common/entities/DynamicConfig'; declare const process: { nextTick: (_: unknown) => void }; declare const global: { gc: () => void }; @@ -27,7 +28,7 @@ export abstract class Job = Record { public readonly Name = DefaultsJobs[DefaultsJobs['Top Pick Sending']]; public readonly Supported: boolean = true; - public readonly ConfigTemplate: ConfigTemplateEntry[] = [ + public readonly ConfigTemplate: DynamicConfig[] = [ { id: 'mediaPick', type: 'MediaPickDTO-array', diff --git a/src/common/entities/DynamicConfig.ts b/src/common/entities/DynamicConfig.ts new file mode 100644 index 00000000..becfc97b --- /dev/null +++ b/src/common/entities/DynamicConfig.ts @@ -0,0 +1,17 @@ +import {backendText} from '../BackendTexts'; +import {fieldType} from './job/JobDTO'; + +/** + * Dynamic configs are not part of the typeconfig maintained config. + * Pigallery uses them to dynamically define configuration + * on the serverside so the client can parse and render it. + * It is mostly used for configuring jobs + */ +export interface DynamicConfig { + id: string; + // Use a predefined and localized backend text id or explicitly define the text + name: backendText | string; + description: backendText | string; + type: fieldType; + defaultValue: unknown; +} diff --git a/src/common/entities/job/JobDTO.ts b/src/common/entities/job/JobDTO.ts index ac98c2b6..3001a80f 100644 --- a/src/common/entities/job/JobDTO.ts +++ b/src/common/entities/job/JobDTO.ts @@ -1,4 +1,5 @@ import {backendText} from '../../BackendTexts'; +import {DynamicConfig} from '../DynamicConfig'; export type fieldType = 'string' | 'string-array' | 'number' | 'boolean' | 'number-array' | 'MediaPickDTO-array'; @@ -17,17 +18,10 @@ export enum DefaultsJobs { 'Top Pick Sending' = 12 } -export interface ConfigTemplateEntry { - id: string; - name: backendText; - description: backendText; - type: fieldType; - defaultValue: any; -} export interface JobDTO { Name: string; - ConfigTemplate: ConfigTemplateEntry[]; + ConfigTemplate: DynamicConfig[]; } export const JobDTOUtils = {