From 2bb686997eba9b593e45e8510bb6a1e6e284950b Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 21 Nov 2022 20:37:29 +0100 Subject: [PATCH] implementing cleaning job for gpx files --- src/backend/middlewares/MetaFileMWs.ts | 2 +- .../{ => fileprocessing}/GPXProcessing.ts | 18 ++++++--- .../model/jobs/jobs/GPXCompressionJob.ts | 2 +- .../model/jobs/jobs/TempFolderCleaningJob.ts | 18 ++++++--- .../model/threading/DiskMangerWorker.ts | 38 +++++++++---------- 5 files changed, 43 insertions(+), 35 deletions(-) rename src/backend/model/{ => fileprocessing}/GPXProcessing.ts (84%) diff --git a/src/backend/middlewares/MetaFileMWs.ts b/src/backend/middlewares/MetaFileMWs.ts index 5c352b8b..dfa93ccb 100644 --- a/src/backend/middlewares/MetaFileMWs.ts +++ b/src/backend/middlewares/MetaFileMWs.ts @@ -1,7 +1,7 @@ import {NextFunction, Request, Response} from 'express'; import * as fs from 'fs'; import { Config } from '../../common/config/private/Config'; -import { GPXProcessing } from '../model/GPXProcessing'; +import { GPXProcessing } from '../model/fileprocessing/GPXProcessing'; export class MetaFileMWs { public static async compressGPX( diff --git a/src/backend/model/GPXProcessing.ts b/src/backend/model/fileprocessing/GPXProcessing.ts similarity index 84% rename from src/backend/model/GPXProcessing.ts rename to src/backend/model/fileprocessing/GPXProcessing.ts index 41c0e8ed..38f6786d 100644 --- a/src/backend/model/GPXProcessing.ts +++ b/src/backend/model/fileprocessing/GPXProcessing.ts @@ -1,21 +1,27 @@ import * as path from 'path'; import {constants as fsConstants, promises as fsp} from 'fs'; import * as xml2js from 'xml2js'; -import {ProjectPath} from '../ProjectPath'; -import {Config} from '../../common/config/private/Config'; +import {ProjectPath} from '../../ProjectPath'; +import {Config} from '../../../common/config/private/Config'; +import {SupportedFormats} from '../../../common/SupportedFormats'; type gpxEntry = { '$': { lat: string, lon: string }, ele: string[], time: string[], extensions: unknown }; export class GPXProcessing { + public static isMetaFile(fullPath: string): boolean { + const extension = path.extname(fullPath).toLowerCase(); + return SupportedFormats.WithDots.MetaFiles.indexOf(extension) !== -1; + } public static generateConvertedPath(filePath: string): string { - const file = path.basename(filePath); return path.join( ProjectPath.TranscodedFolder, ProjectPath.getRelativePathToImages(path.dirname(filePath)), - file - ); + path.basename(filePath) + + '_' + Config.Server.MetaFile.GPXCompressing.minDistance + 'm' + + Config.Server.MetaFile.GPXCompressing.minTimeDistance + 'ms' + + path.extname(filePath)); } public static async isValidConvertedPath( @@ -25,7 +31,7 @@ export class GPXProcessing { ProjectPath.ImageFolder, path.relative( ProjectPath.TranscodedFolder, - convertedPath + convertedPath.substring(0, convertedPath.lastIndexOf('_')) ) ); diff --git a/src/backend/model/jobs/jobs/GPXCompressionJob.ts b/src/backend/model/jobs/jobs/GPXCompressionJob.ts index b2ec97ec..ed22d3c4 100644 --- a/src/backend/model/jobs/jobs/GPXCompressionJob.ts +++ b/src/backend/model/jobs/jobs/GPXCompressionJob.ts @@ -2,7 +2,7 @@ import {Config} from '../../../../common/config/private/Config'; import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; import {FileJob} from './FileJob'; import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing'; -import {GPXProcessing} from '../../GPXProcessing'; +import {GPXProcessing} from '../../fileprocessing/GPXProcessing'; import {FileDTO} from '../../../../common/entities/FileDTO'; import {Logger} from '../../../Logger'; diff --git a/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts b/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts index 28d08287..10e64c33 100644 --- a/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts +++ b/src/backend/model/jobs/jobs/TempFolderCleaningJob.ts @@ -4,10 +4,12 @@ import { } from '../../../../common/entities/job/JobDTO'; import * as path from 'path'; import * as fs from 'fs'; -import { Job } from './Job'; -import { ProjectPath } from '../../../ProjectPath'; -import { PhotoProcessing } from '../../fileprocessing/PhotoProcessing'; -import { VideoProcessing } from '../../fileprocessing/VideoProcessing'; +import {Job} from './Job'; +import {ProjectPath} from '../../../ProjectPath'; +import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing'; +import {VideoProcessing} from '../../fileprocessing/VideoProcessing'; +import {DiskMangerWorker} from '../../threading/DiskMangerWorker'; +import {GPXProcessing} from '../../fileprocessing/GPXProcessing'; export class TempFolderCleaningJob extends Job { public readonly Name = DefaultsJobs[DefaultsJobs['Temp Folder Cleaning']]; @@ -31,6 +33,10 @@ export class TempFolderCleaningJob extends Job { return VideoProcessing.isValidConvertedPath(filePath); } + if (GPXProcessing.isMetaFile(filePath)) { + return GPXProcessing.isValidConvertedPath(filePath); + } + return false; } @@ -62,7 +68,7 @@ export class TempFolderCleaningJob extends Job { this.Progress.log('processing: ' + file); this.Progress.Processed++; if ((await fs.promises.stat(file)).isDirectory()) { - await fs.promises.rm(file, { recursive: true }); + await fs.promises.rm(file, {recursive: true}); } else { await fs.promises.unlink(file); } @@ -84,7 +90,7 @@ export class TempFolderCleaningJob extends Job { if ((await this.isValidDirectory(filePath)) === false) { this.Progress.log('processing: ' + filePath); this.Progress.Processed++; - await fs.promises.rm(filePath, { recursive: true }); + await fs.promises.rm(filePath, {recursive: true}); } else { this.Progress.log('skipping: ' + filePath); this.Progress.Skipped++; diff --git a/src/backend/model/threading/DiskMangerWorker.ts b/src/backend/model/threading/DiskMangerWorker.ts index fcdec1d9..d6f5ef36 100644 --- a/src/backend/model/threading/DiskMangerWorker.ts +++ b/src/backend/model/threading/DiskMangerWorker.ts @@ -1,20 +1,20 @@ -import { promises as fsp, Stats } from 'fs'; +import {promises as fsp, Stats} from 'fs'; import * as path from 'path'; import { ParentDirectoryDTO, SubDirectoryDTO, } from '../../../common/entities/DirectoryDTO'; -import { PhotoDTO } from '../../../common/entities/PhotoDTO'; -import { ProjectPath } from '../../ProjectPath'; -import { Config } from '../../../common/config/private/Config'; -import { VideoDTO } from '../../../common/entities/VideoDTO'; -import { FileDTO } from '../../../common/entities/FileDTO'; -import { MetadataLoader } from './MetadataLoader'; -import { Logger } from '../../Logger'; -import { SupportedFormats } from '../../../common/SupportedFormats'; -import { VideoProcessing } from '../fileprocessing/VideoProcessing'; -import { PhotoProcessing } from '../fileprocessing/PhotoProcessing'; -import { Utils } from '../../../common/Utils'; +import {PhotoDTO} from '../../../common/entities/PhotoDTO'; +import {ProjectPath} from '../../ProjectPath'; +import {Config} from '../../../common/config/private/Config'; +import {VideoDTO} from '../../../common/entities/VideoDTO'; +import {FileDTO} from '../../../common/entities/FileDTO'; +import {MetadataLoader} from './MetadataLoader'; +import {Logger} from '../../Logger'; +import {VideoProcessing} from '../fileprocessing/VideoProcessing'; +import {PhotoProcessing} from '../fileprocessing/PhotoProcessing'; +import {Utils} from '../../../common/Utils'; +import {GPXProcessing} from '../fileprocessing/GPXProcessing'; export class DiskMangerWorker { public static calcLastModified(stat: Stats): number { @@ -164,7 +164,7 @@ export class DiskMangerWorker { } )) as SubDirectoryDTO; - d.lastScanned = 0; // it was not a fully scan + d.lastScanned = 0; // it was not a fully scanned d.isPartial = true; directory.directories.push(d); @@ -218,12 +218,12 @@ export class DiskMangerWorker { } catch (e) { Logger.warn( 'Media loading error, skipping: ' + - file + - ', reason: ' + - e.toString() + file + + ', reason: ' + + e.toString() ); } - } else if (DiskMangerWorker.isMetaFile(fullFilePath)) { + } else if (GPXProcessing.isMetaFile(fullFilePath)) { if ( !DiskMangerWorker.isEnabledMetaFile(fullFilePath) || settings.noMetaFile === true || @@ -243,10 +243,6 @@ export class DiskMangerWorker { return directory; } - private static isMetaFile(fullPath: string): boolean { - const extension = path.extname(fullPath).toLowerCase(); - return SupportedFormats.WithDots.MetaFiles.indexOf(extension) !== -1; - } private static isEnabledMetaFile(fullPath: string): boolean { const extension = path.extname(fullPath).toLowerCase();