|
@@ -1,3 +1,4 @@
|
|
|
|
+import { ImmichLogLevel } from '@app/common/constants/log-level.constant';
|
|
import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
|
|
import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
|
|
import {
|
|
import {
|
|
WebpGeneratorProcessor,
|
|
WebpGeneratorProcessor,
|
|
@@ -11,6 +12,7 @@ import {
|
|
} from '@app/job';
|
|
} from '@app/job';
|
|
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
|
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
|
import { Logger } from '@nestjs/common';
|
|
import { Logger } from '@nestjs/common';
|
|
|
|
+import { ConfigService } from '@nestjs/config';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { mapAsset } from 'apps/immich/src/api-v1/asset/response-dto/asset-response.dto';
|
|
import { mapAsset } from 'apps/immich/src/api-v1/asset/response-dto/asset-response.dto';
|
|
import { Job, Queue } from 'bull';
|
|
import { Job, Queue } from 'bull';
|
|
@@ -23,6 +25,8 @@ import { CommunicationGateway } from '../../../immich/src/api-v1/communication/c
|
|
|
|
|
|
@Processor(thumbnailGeneratorQueueName)
|
|
@Processor(thumbnailGeneratorQueueName)
|
|
export class ThumbnailGeneratorProcessor {
|
|
export class ThumbnailGeneratorProcessor {
|
|
|
|
+ private logLevel: ImmichLogLevel;
|
|
|
|
+
|
|
constructor(
|
|
constructor(
|
|
@InjectRepository(AssetEntity)
|
|
@InjectRepository(AssetEntity)
|
|
private assetRepository: Repository<AssetEntity>,
|
|
private assetRepository: Repository<AssetEntity>,
|
|
@@ -34,7 +38,11 @@ export class ThumbnailGeneratorProcessor {
|
|
|
|
|
|
@InjectQueue(metadataExtractionQueueName)
|
|
@InjectQueue(metadataExtractionQueueName)
|
|
private metadataExtractionQueue: Queue,
|
|
private metadataExtractionQueue: Queue,
|
|
- ) {}
|
|
|
|
|
|
+
|
|
|
|
+ private configService: ConfigService,
|
|
|
|
+ ) {
|
|
|
|
+ this.logLevel = this.configService.get('LOG_LEVEL') || ImmichLogLevel.SIMPLE;
|
|
|
|
+ }
|
|
|
|
|
|
@Process({ name: generateJPEGThumbnailProcessorName, concurrency: 3 })
|
|
@Process({ name: generateJPEGThumbnailProcessorName, concurrency: 3 })
|
|
async generateJPEGThumbnail(job: Job<JpegGeneratorProcessor>) {
|
|
async generateJPEGThumbnail(job: Job<JpegGeneratorProcessor>) {
|
|
@@ -51,8 +59,16 @@ export class ThumbnailGeneratorProcessor {
|
|
const jpegThumbnailPath = resizePath + originalFilename + '.jpeg';
|
|
const jpegThumbnailPath = resizePath + originalFilename + '.jpeg';
|
|
|
|
|
|
if (asset.type == AssetType.IMAGE) {
|
|
if (asset.type == AssetType.IMAGE) {
|
|
- await sharp(asset.originalPath).resize(1440, 2560, { fit: 'inside' }).jpeg().rotate().toFile(jpegThumbnailPath);
|
|
|
|
- await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
|
|
|
|
|
|
+ try {
|
|
|
|
+ await sharp(asset.originalPath).resize(1440, 2560, { fit: 'inside' }).jpeg().rotate().toFile(jpegThumbnailPath);
|
|
|
|
+ await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ Logger.error('Failed to generate jpeg thumbnail for asset: ' + asset.id);
|
|
|
|
+
|
|
|
|
+ if (this.logLevel == ImmichLogLevel.VERBOSE) {
|
|
|
|
+ console.trace('Failed to generate jpeg thumbnail for asset', error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
// Update resize path to send to generate webp queue
|
|
// Update resize path to send to generate webp queue
|
|
asset.resizePath = jpegThumbnailPath;
|
|
asset.resizePath = jpegThumbnailPath;
|
|
@@ -105,7 +121,15 @@ export class ThumbnailGeneratorProcessor {
|
|
|
|
|
|
const webpPath = asset.resizePath.replace('jpeg', 'webp');
|
|
const webpPath = asset.resizePath.replace('jpeg', 'webp');
|
|
|
|
|
|
- await sharp(asset.resizePath).resize(250).webp().rotate().toFile(webpPath);
|
|
|
|
- await this.assetRepository.update({ id: asset.id }, { webpPath: webpPath });
|
|
|
|
|
|
+ try {
|
|
|
|
+ await sharp(asset.resizePath).resize(250).webp().rotate().toFile(webpPath);
|
|
|
|
+ await this.assetRepository.update({ id: asset.id }, { webpPath: webpPath });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ Logger.error('Failed to generate webp thumbnail for asset: ' + asset.id);
|
|
|
|
+
|
|
|
|
+ if (this.logLevel == ImmichLogLevel.VERBOSE) {
|
|
|
|
+ console.trace('Failed to generate webp thumbnail for asset', error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|