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 { export class PhotoProcessing {
private static initDone = false; private static initDone = false;
private static taskQue: ITaskExecuter<RendererInput, void> = null; private static taskQue: ITaskExecuter<RendererInput, void> = null;
private static readonly CONVERTED_EXTENSION = '.webp';
public static init(): void { public static init(): void {
if (this.initDone === true) { if (this.initDone === true) {
@ -122,7 +123,7 @@ export class PhotoProcessing {
return path.join( return path.join(
ProjectPath.TranscodedFolder, ProjectPath.TranscodedFolder,
ProjectPath.getRelativePathToImages(path.dirname(mediaPath)), 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') + .digest('hex') +
'_' + '_' +
size + 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( const sizeStr = convertedPath.substring(
convertedPath.lastIndexOf('_') + 1, convertedPath.lastIndexOf('_') + 1,
convertedPath.lastIndexOf('q') 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'); Logger.silly(LOG_TAG, 'Loading files from db');
const connection = await SQLConnection.getConnection(); const connection = await SQLConnection.getConnection();
if (this.scanFilter.noVideo === false || if (!this.scanFilter.noVideo ||
this.scanFilter.noPhoto === false) { !this.scanFilter.noPhoto) {
let usedEntity = MediaEntity; 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 const result = await connection
.getRepository(FileEntity) .getRepository(FileEntity)

View File

@ -33,6 +33,13 @@ export class ThumbnailGenerationJob extends FileJob<{
soloRun = false, soloRun = false,
allowParallelRun = false allowParallelRun = false
): Promise<void> { ): 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) { for (const item of config.sizes) {
if (Config.Client.Media.Thumbnail.thumbnailSizes.indexOf(item) === -1) { if (Config.Client.Media.Thumbnail.thumbnailSizes.indexOf(item) === -1) {
throw new Error( throw new Error(
@ -60,6 +67,7 @@ export class ThumbnailGenerationJob extends FileJob<{
return true; return true;
} }
} }
return false;
} }
protected async processFile(mPath: string): Promise<void> { protected async processFile(mPath: string): Promise<void> {