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:
parent
baf426ff76
commit
2bb686997e
@ -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(
|
||||||
|
@ -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('_'))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -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';
|
||||||
|
|
||||||
|
@ -4,10 +4,12 @@ import {
|
|||||||
} from '../../../../common/entities/job/JobDTO';
|
} from '../../../../common/entities/job/JobDTO';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { Job } from './Job';
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +68,7 @@ export class TempFolderCleaningJob extends Job {
|
|||||||
this.Progress.log('processing: ' + file);
|
this.Progress.log('processing: ' + file);
|
||||||
this.Progress.Processed++;
|
this.Progress.Processed++;
|
||||||
if ((await fs.promises.stat(file)).isDirectory()) {
|
if ((await fs.promises.stat(file)).isDirectory()) {
|
||||||
await fs.promises.rm(file, { recursive: true });
|
await fs.promises.rm(file, {recursive: true});
|
||||||
} else {
|
} else {
|
||||||
await fs.promises.unlink(file);
|
await fs.promises.unlink(file);
|
||||||
}
|
}
|
||||||
@ -84,7 +90,7 @@ export class TempFolderCleaningJob extends Job {
|
|||||||
if ((await this.isValidDirectory(filePath)) === false) {
|
if ((await this.isValidDirectory(filePath)) === false) {
|
||||||
this.Progress.log('processing: ' + filePath);
|
this.Progress.log('processing: ' + filePath);
|
||||||
this.Progress.Processed++;
|
this.Progress.Processed++;
|
||||||
await fs.promises.rm(filePath, { recursive: true });
|
await fs.promises.rm(filePath, {recursive: true});
|
||||||
} else {
|
} else {
|
||||||
this.Progress.log('skipping: ' + filePath);
|
this.Progress.log('skipping: ' + filePath);
|
||||||
this.Progress.Skipped++;
|
this.Progress.Skipped++;
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
import { promises as fsp, Stats } from 'fs';
|
import {promises as fsp, Stats} from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {
|
import {
|
||||||
ParentDirectoryDTO,
|
ParentDirectoryDTO,
|
||||||
SubDirectoryDTO,
|
SubDirectoryDTO,
|
||||||
} from '../../../common/entities/DirectoryDTO';
|
} from '../../../common/entities/DirectoryDTO';
|
||||||
import { PhotoDTO } from '../../../common/entities/PhotoDTO';
|
import {PhotoDTO} from '../../../common/entities/PhotoDTO';
|
||||||
import { ProjectPath } from '../../ProjectPath';
|
import {ProjectPath} from '../../ProjectPath';
|
||||||
import { Config } from '../../../common/config/private/Config';
|
import {Config} from '../../../common/config/private/Config';
|
||||||
import { VideoDTO } from '../../../common/entities/VideoDTO';
|
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);
|
||||||
@ -218,12 +218,12 @@ export class DiskMangerWorker {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.warn(
|
Logger.warn(
|
||||||
'Media loading error, skipping: ' +
|
'Media loading error, skipping: ' +
|
||||||
file +
|
file +
|
||||||
', reason: ' +
|
', reason: ' +
|
||||||
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user