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:
parent
8fda60094d
commit
acc7b6871e
@ -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')
|
||||||
|
@ -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)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Config } from '../../../../common/config/private/Config';
|
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 { ThumbnailSourceType } from '../../threading/PhotoWorker';
|
import {ThumbnailSourceType} from '../../threading/PhotoWorker';
|
||||||
import { MediaDTOUtils } from '../../../../common/entities/MediaDTO';
|
import {MediaDTOUtils} from '../../../../common/entities/MediaDTO';
|
||||||
import { FileDTO } from '../../../../common/entities/FileDTO';
|
import {FileDTO} from '../../../../common/entities/FileDTO';
|
||||||
import { backendTexts } from '../../../../common/BackendTexts';
|
import {backendTexts} from '../../../../common/BackendTexts';
|
||||||
|
|
||||||
export class ThumbnailGenerationJob extends FileJob<{
|
export class ThumbnailGenerationJob extends FileJob<{
|
||||||
sizes: number[];
|
sizes: number[];
|
||||||
@ -14,7 +14,7 @@ export class ThumbnailGenerationJob extends FileJob<{
|
|||||||
public readonly Name = DefaultsJobs[DefaultsJobs['Thumbnail Generation']];
|
public readonly Name = DefaultsJobs[DefaultsJobs['Thumbnail Generation']];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({ noMetaFile: true });
|
super({noMetaFile: true});
|
||||||
this.ConfigTemplate.push({
|
this.ConfigTemplate.push({
|
||||||
id: 'sizes',
|
id: 'sizes',
|
||||||
type: 'number-array',
|
type: 'number-array',
|
||||||
@ -33,12 +33,19 @@ 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(
|
||||||
'unknown thumbnails size: ' +
|
'unknown thumbnails size: ' +
|
||||||
item +
|
item +
|
||||||
'. Add it to the possible thumbnail sizes.'
|
'. Add it to the possible thumbnail sizes.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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> {
|
||||||
|
Loading…
Reference in New Issue
Block a user