1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

implementing cleaning job for gpx files

This commit is contained in:
Patrik J. Braun 2022-11-21 20:37:29 +01:00
parent baf426ff76
commit 2bb686997e
5 changed files with 43 additions and 35 deletions

View File

@ -1,7 +1,7 @@
import {NextFunction, Request, Response} from 'express'; import {NextFunction, Request, Response} from 'express';
import * as fs from 'fs'; import * as fs from 'fs';
import { Config } from '../../common/config/private/Config'; import { Config } from '../../common/config/private/Config';
import { GPXProcessing } from '../model/GPXProcessing'; import { GPXProcessing } from '../model/fileprocessing/GPXProcessing';
export class MetaFileMWs { export class MetaFileMWs {
public static async compressGPX( public static async compressGPX(

View File

@ -1,21 +1,27 @@
import * as path from 'path'; import * as path from 'path';
import {constants as fsConstants, promises as fsp} from 'fs'; import {constants as fsConstants, promises as fsp} from 'fs';
import * as xml2js from 'xml2js'; import * as xml2js from 'xml2js';
import {ProjectPath} from '../ProjectPath'; import {ProjectPath} from '../../ProjectPath';
import {Config} from '../../common/config/private/Config'; import {Config} from '../../../common/config/private/Config';
import {SupportedFormats} from '../../../common/SupportedFormats';
type gpxEntry = { '$': { lat: string, lon: string }, ele: string[], time: string[], extensions: unknown }; type gpxEntry = { '$': { lat: string, lon: string }, ele: string[], time: string[], extensions: unknown };
export class GPXProcessing { 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 { public static generateConvertedPath(filePath: string): string {
const file = path.basename(filePath);
return path.join( return path.join(
ProjectPath.TranscodedFolder, ProjectPath.TranscodedFolder,
ProjectPath.getRelativePathToImages(path.dirname(filePath)), 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( public static async isValidConvertedPath(
@ -25,7 +31,7 @@ export class GPXProcessing {
ProjectPath.ImageFolder, ProjectPath.ImageFolder,
path.relative( path.relative(
ProjectPath.TranscodedFolder, ProjectPath.TranscodedFolder,
convertedPath convertedPath.substring(0, convertedPath.lastIndexOf('_'))
) )
); );

View File

@ -2,7 +2,7 @@ import {Config} from '../../../../common/config/private/Config';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO'; import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import {FileJob} from './FileJob'; import {FileJob} from './FileJob';
import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing'; import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing';
import {GPXProcessing} from '../../GPXProcessing'; import {GPXProcessing} from '../../fileprocessing/GPXProcessing';
import {FileDTO} from '../../../../common/entities/FileDTO'; import {FileDTO} from '../../../../common/entities/FileDTO';
import {Logger} from '../../../Logger'; import {Logger} from '../../../Logger';

View File

@ -8,6 +8,8 @@ import { Job } from './Job';
import {ProjectPath} from '../../../ProjectPath'; import {ProjectPath} from '../../../ProjectPath';
import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing'; import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing';
import {VideoProcessing} from '../../fileprocessing/VideoProcessing'; import {VideoProcessing} from '../../fileprocessing/VideoProcessing';
import {DiskMangerWorker} from '../../threading/DiskMangerWorker';
import {GPXProcessing} from '../../fileprocessing/GPXProcessing';
export class TempFolderCleaningJob extends Job { export class TempFolderCleaningJob extends Job {
public readonly Name = DefaultsJobs[DefaultsJobs['Temp Folder Cleaning']]; public readonly Name = DefaultsJobs[DefaultsJobs['Temp Folder Cleaning']];
@ -31,6 +33,10 @@ export class TempFolderCleaningJob extends Job {
return VideoProcessing.isValidConvertedPath(filePath); return VideoProcessing.isValidConvertedPath(filePath);
} }
if (GPXProcessing.isMetaFile(filePath)) {
return GPXProcessing.isValidConvertedPath(filePath);
}
return false; return false;
} }

View File

@ -11,10 +11,10 @@ import { VideoDTO } from '../../../common/entities/VideoDTO';
import {FileDTO} from '../../../common/entities/FileDTO'; import {FileDTO} from '../../../common/entities/FileDTO';
import {MetadataLoader} from './MetadataLoader'; import {MetadataLoader} from './MetadataLoader';
import {Logger} from '../../Logger'; import {Logger} from '../../Logger';
import { SupportedFormats } from '../../../common/SupportedFormats';
import {VideoProcessing} from '../fileprocessing/VideoProcessing'; import {VideoProcessing} from '../fileprocessing/VideoProcessing';
import {PhotoProcessing} from '../fileprocessing/PhotoProcessing'; import {PhotoProcessing} from '../fileprocessing/PhotoProcessing';
import {Utils} from '../../../common/Utils'; import {Utils} from '../../../common/Utils';
import {GPXProcessing} from '../fileprocessing/GPXProcessing';
export class DiskMangerWorker { export class DiskMangerWorker {
public static calcLastModified(stat: Stats): number { public static calcLastModified(stat: Stats): number {
@ -164,7 +164,7 @@ export class DiskMangerWorker {
} }
)) as SubDirectoryDTO; )) as SubDirectoryDTO;
d.lastScanned = 0; // it was not a fully scan d.lastScanned = 0; // it was not a fully scanned
d.isPartial = true; d.isPartial = true;
directory.directories.push(d); directory.directories.push(d);
@ -223,7 +223,7 @@ export class DiskMangerWorker {
e.toString() e.toString()
); );
} }
} else if (DiskMangerWorker.isMetaFile(fullFilePath)) { } else if (GPXProcessing.isMetaFile(fullFilePath)) {
if ( if (
!DiskMangerWorker.isEnabledMetaFile(fullFilePath) || !DiskMangerWorker.isEnabledMetaFile(fullFilePath) ||
settings.noMetaFile === true || settings.noMetaFile === true ||
@ -243,10 +243,6 @@ export class DiskMangerWorker {
return directory; 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 { private static isEnabledMetaFile(fullPath: string): boolean {
const extension = path.extname(fullPath).toLowerCase(); const extension = path.extname(fullPath).toLowerCase();