From 041b984dbd4ebdb19ffad9de891897f50e23f49a Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 29 Jul 2023 11:45:29 +0200 Subject: [PATCH] Add compressed GPX delete button #504 --- .../model/fileprocessing/GPXProcessing.ts | 5 +++++ src/backend/model/jobs/JobRepository.ts | 2 ++ .../model/jobs/jobs/GPXCompressionResetJob.ts | 16 ++++++++++++++++ .../model/jobs/jobs/TempFolderCleaningJob.ts | 2 +- src/common/config/private/PrivateConfig.ts | 3 +++ src/common/entities/job/JobDTO.ts | 1 + .../ui/settings/template/template.component.html | 2 +- 7 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/backend/model/jobs/jobs/GPXCompressionResetJob.ts diff --git a/src/backend/model/fileprocessing/GPXProcessing.ts b/src/backend/model/fileprocessing/GPXProcessing.ts index a2e3df0f..3d72e456 100644 --- a/src/backend/model/fileprocessing/GPXProcessing.ts +++ b/src/backend/model/fileprocessing/GPXProcessing.ts @@ -15,6 +15,11 @@ export class GPXProcessing { return SupportedFormats.WithDots.MetaFiles.indexOf(extension) !== -1; } + public static isGPXFile(fullPath: string): boolean { + const extension = path.extname(fullPath).toLowerCase(); + return extension === '.gpx'; + } + public static generateConvertedPath(filePath: string): string { return path.join( ProjectPath.TranscodedFolder, diff --git a/src/backend/model/jobs/JobRepository.ts b/src/backend/model/jobs/JobRepository.ts index 9521daef..2be563a6 100644 --- a/src/backend/model/jobs/JobRepository.ts +++ b/src/backend/model/jobs/JobRepository.ts @@ -9,6 +9,7 @@ import {PreviewFillingJob} from './jobs/PreviewFillingJob'; import {PreviewRestJob} from './jobs/PreviewResetJob'; import {GPXCompressionJob} from './jobs/GPXCompressionJob'; import {AlbumRestJob} from './jobs/AlbumResetJob'; +import {GPXCompressionResetJob} from './jobs/GPXCompressionResetJob'; export class JobRepository { private static instance: JobRepository = null; @@ -43,3 +44,4 @@ JobRepository.Instance.register(new ThumbnailGenerationJob()); JobRepository.Instance.register(new GPXCompressionJob()); JobRepository.Instance.register(new TempFolderCleaningJob()); JobRepository.Instance.register(new AlbumRestJob()); +JobRepository.Instance.register(new GPXCompressionResetJob()); diff --git a/src/backend/model/jobs/jobs/GPXCompressionResetJob.ts b/src/backend/model/jobs/jobs/GPXCompressionResetJob.ts new file mode 100644 index 00000000..505697e9 --- /dev/null +++ b/src/backend/model/jobs/jobs/GPXCompressionResetJob.ts @@ -0,0 +1,16 @@ +import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; +import {TempFolderCleaningJob} from './TempFolderCleaningJob'; +import {GPXProcessing} from '../../fileprocessing/GPXProcessing'; + +/** + * Deletes all gpx file from the tmp folder + */ +export class GPXCompressionResetJob extends TempFolderCleaningJob { + public readonly Name = DefaultsJobs[DefaultsJobs['Delete Compressed GPX']]; + + // returns false if the file is GPX + protected async isValidFile(filePath: string): Promise { + return !GPXProcessing.isGPXFile(filePath); + } + +} diff --git a/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts b/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts index b5b96fd3..d24f4fb0 100644 --- a/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts +++ b/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts @@ -10,7 +10,7 @@ import {GPXProcessing} from '../../fileprocessing/GPXProcessing'; export class TempFolderCleaningJob extends Job { public readonly Name = DefaultsJobs[DefaultsJobs['Temp Folder Cleaning']]; public readonly ConfigTemplate: ConfigTemplateEntry[] = null; - public readonly Supported = true; + public readonly Supported: boolean = true; directoryQueue: string[] = []; private tempRootCleaned = false; diff --git a/src/common/config/private/PrivateConfig.ts b/src/common/config/private/PrivateConfig.ts index 1e4302c3..8b924325 100644 --- a/src/common/config/private/PrivateConfig.ts +++ b/src/common/config/private/PrivateConfig.ts @@ -395,6 +395,9 @@ export class ServerMetaFileConfig extends ClientMetaFileConfig { uiJob: [{ job: DefaultsJobs[DefaultsJobs['GPX Compression']], relevant: (c) => c.MetaFile.GPXCompressing.enabled + },{ + job: DefaultsJobs[DefaultsJobs['Delete Compressed GPX']], + relevant: (c) => c.MetaFile.GPXCompressing.enabled }] } as TAGS }) diff --git a/src/common/entities/job/JobDTO.ts b/src/common/entities/job/JobDTO.ts index 113728c5..6106e586 100644 --- a/src/common/entities/job/JobDTO.ts +++ b/src/common/entities/job/JobDTO.ts @@ -13,6 +13,7 @@ export enum DefaultsJobs { 'Preview Reset' = 8, 'GPX Compression' = 9, 'Album Reset' = 10, + 'Delete Compressed GPX' = 11 } export interface ConfigTemplateEntry { diff --git a/src/frontend/app/ui/settings/template/template.component.html b/src/frontend/app/ui/settings/template/template.component.html index b4a5e0c6..e35b8a50 100644 --- a/src/frontend/app/ui/settings/template/template.component.html +++ b/src/frontend/app/ui/settings/template/template.component.html @@ -129,7 +129,7 @@ [soloRun]="true" (jobError)="error=$event" [allowParallelRun]="false" - [danger]="job.job.includes('Reset')" + [danger]="job.job.includes('Reset') || job.job.includes('Delete')" [jobName]="job.job">