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 * 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(

View File

@ -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('_'))
)
);

View File

@ -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';

View File

@ -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++;

View File

@ -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();