mirror of
https://github.com/immich-app/immich.git
synced 2025-12-17 09:13:17 +03:00
* refactor serving file function asset service * Remove PhotoViewer for now since it creates a problem in 2.10 * Added error message for wrong decode file and logo for failed to load file * Fixed error when read stream cannot be created and crash server * Added method to get all assets as a raw array * Implemented cleaner way of grouping image * Implemented operation to delete assets in the database * Implemented delete on database operation * Implemented delete on device operation * Fixed issue display wrong information when the auto backup is enabled after deleting all assets
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Job, Queue } from 'bull';
|
|
import { Repository } from 'typeorm';
|
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import exifr from 'exifr';
|
|
import { readFile } from 'fs/promises';
|
|
import fs from 'fs';
|
|
import { Logger } from '@nestjs/common';
|
|
import { ExifEntity } from '../../api-v1/asset/entities/exif.entity';
|
|
|
|
@Processor('background-task')
|
|
export class BackgroundTaskProcessor {
|
|
constructor(
|
|
@InjectRepository(AssetEntity)
|
|
private assetRepository: Repository<AssetEntity>,
|
|
|
|
@InjectRepository(ExifEntity)
|
|
private exifRepository: Repository<ExifEntity>,
|
|
|
|
private configService: ConfigService,
|
|
) {}
|
|
|
|
@Process('extract-exif')
|
|
async extractExif(job: Job) {
|
|
const { savedAsset, fileName, fileSize }: { savedAsset: AssetEntity; fileName: string; fileSize: number } =
|
|
job.data;
|
|
|
|
const fileBuffer = await readFile(savedAsset.originalPath);
|
|
|
|
const exifData = await exifr.parse(fileBuffer);
|
|
|
|
const newExif = new ExifEntity();
|
|
newExif.assetId = savedAsset.id;
|
|
newExif.make = exifData['Make'] || null;
|
|
newExif.model = exifData['Model'] || null;
|
|
newExif.imageName = fileName || null;
|
|
newExif.exifImageHeight = exifData['ExifImageHeight'] || null;
|
|
newExif.exifImageWidth = exifData['ExifImageWidth'] || null;
|
|
newExif.fileSizeInByte = fileSize || null;
|
|
newExif.orientation = exifData['Orientation'] || null;
|
|
newExif.dateTimeOriginal = exifData['DateTimeOriginal'] || null;
|
|
newExif.modifyDate = exifData['ModifyDate'] || null;
|
|
newExif.lensModel = exifData['LensModel'] || null;
|
|
newExif.fNumber = exifData['FNumber'] || null;
|
|
newExif.focalLength = exifData['FocalLength'] || null;
|
|
newExif.iso = exifData['ISO'] || null;
|
|
newExif.exposureTime = exifData['ExposureTime'] || null;
|
|
newExif.latitude = exifData['latitude'] || null;
|
|
newExif.longitude = exifData['longitude'] || null;
|
|
|
|
await this.exifRepository.save(newExif);
|
|
|
|
try {
|
|
} catch (e) {
|
|
Logger.error(`Error extracting EXIF ${e.toString()}`, 'extractExif');
|
|
}
|
|
}
|
|
|
|
@Process('delete-file-on-disk')
|
|
async deleteFileOnDisk(job) {
|
|
const { assets }: { assets: AssetEntity[] } = job.data;
|
|
|
|
assets.forEach(async (asset) => {
|
|
fs.unlink(asset.originalPath, (err) => {
|
|
if (err) {
|
|
console.log('error deleting ', asset.originalPath);
|
|
}
|
|
});
|
|
|
|
fs.unlink(asset.resizePath, (err) => {
|
|
if (err) {
|
|
console.log('error deleting ', asset.originalPath);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|