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

fixing thumbnail generation and temp folder cleaning #558

This commit is contained in:
Patrik J. Braun 2022-11-25 23:29:32 +01:00
parent 8fda60094d
commit acc7b6871e
3 changed files with 29 additions and 16 deletions

View File

@ -17,6 +17,7 @@ import {PersonWithSampleRegion} from '../../../common/entities/PersonDTO';
export class PhotoProcessing {
private static initDone = false;
private static taskQue: ITaskExecuter<RendererInput, void> = null;
private static readonly CONVERTED_EXTENSION = '.webp';
public static init(): void {
if (this.initDone === true) {
@ -122,7 +123,7 @@ export class PhotoProcessing {
return path.join(
ProjectPath.TranscodedFolder,
ProjectPath.getRelativePathToImages(path.dirname(mediaPath)),
file + '_' + size + 'q' + Config.Server.Media.Thumbnail.quality + '.webp'
file + '_' + size + 'q' + Config.Server.Media.Thumbnail.quality + PhotoProcessing.CONVERTED_EXTENSION
);
}
@ -147,7 +148,7 @@ export class PhotoProcessing {
.digest('hex') +
'_' +
size +
'.webp'
PhotoProcessing.CONVERTED_EXTENSION
);
}
@ -162,6 +163,10 @@ export class PhotoProcessing {
)
);
if (path.extname(convertedPath) !== PhotoProcessing.CONVERTED_EXTENSION) {
return false;
}
const sizeStr = convertedPath.substring(
convertedPath.lastIndexOf('_') + 1,
convertedPath.lastIndexOf('q')

View File

@ -149,8 +149,8 @@ export abstract class FileJob<S extends { indexedOnly: boolean } = { indexedOnly
Logger.silly(LOG_TAG, 'Loading files from db');
const connection = await SQLConnection.getConnection();
if (this.scanFilter.noVideo === false ||
this.scanFilter.noPhoto === false) {
if (!this.scanFilter.noVideo ||
!this.scanFilter.noPhoto) {
let usedEntity = MediaEntity;
@ -179,7 +179,7 @@ export abstract class FileJob<S extends { indexedOnly: boolean } = { indexedOnly
);
}
}
if (this.scanFilter.noMetaFile === false) {
if (!this.scanFilter.noMetaFile) {
const result = await connection
.getRepository(FileEntity)

View File

@ -1,11 +1,11 @@
import { Config } from '../../../../common/config/private/Config';
import { DefaultsJobs } from '../../../../common/entities/job/JobDTO';
import { FileJob } from './FileJob';
import { PhotoProcessing } from '../../fileprocessing/PhotoProcessing';
import { ThumbnailSourceType } from '../../threading/PhotoWorker';
import { MediaDTOUtils } from '../../../../common/entities/MediaDTO';
import { FileDTO } from '../../../../common/entities/FileDTO';
import { backendTexts } from '../../../../common/BackendTexts';
import {Config} from '../../../../common/config/private/Config';
import {DefaultsJobs} from '../../../../common/entities/job/JobDTO';
import {FileJob} from './FileJob';
import {PhotoProcessing} from '../../fileprocessing/PhotoProcessing';
import {ThumbnailSourceType} from '../../threading/PhotoWorker';
import {MediaDTOUtils} from '../../../../common/entities/MediaDTO';
import {FileDTO} from '../../../../common/entities/FileDTO';
import {backendTexts} from '../../../../common/BackendTexts';
export class ThumbnailGenerationJob extends FileJob<{
sizes: number[];
@ -14,7 +14,7 @@ export class ThumbnailGenerationJob extends FileJob<{
public readonly Name = DefaultsJobs[DefaultsJobs['Thumbnail Generation']];
constructor() {
super({ noMetaFile: true });
super({noMetaFile: true});
this.ConfigTemplate.push({
id: 'sizes',
type: 'number-array',
@ -33,12 +33,19 @@ export class ThumbnailGenerationJob extends FileJob<{
soloRun = false,
allowParallelRun = false
): Promise<void> {
if (!config.sizes || !Array.isArray(config.sizes) || config.sizes.length === 0) {
throw new Error(
'unknown thumbnails sizes: ' +
config.sizes +
'. It should be an array from:' + Config.Client.Media.Thumbnail.thumbnailSizes
);
}
for (const item of config.sizes) {
if (Config.Client.Media.Thumbnail.thumbnailSizes.indexOf(item) === -1) {
throw new Error(
'unknown thumbnails size: ' +
item +
'. Add it to the possible thumbnail sizes.'
item +
'. Add it to the possible thumbnail sizes.'
);
}
}
@ -60,6 +67,7 @@ export class ThumbnailGenerationJob extends FileJob<{
return true;
}
}
return false;
}
protected async processFile(mPath: string): Promise<void> {