mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
feat(server): support tiff uploading (#513)
* feat(server): suport tiff uploading * remove unused variable Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
9048be4c8e
commit
ba2cda8955
@ -9,7 +9,7 @@ import { randomUUID } from 'crypto';
|
|||||||
|
|
||||||
export const assetUploadOption: MulterOptions = {
|
export const assetUploadOption: MulterOptions = {
|
||||||
fileFilter: (req: Request, file: any, cb: any) => {
|
fileFilter: (req: Request, file: any, cb: any) => {
|
||||||
if (file.mimetype.match(/\/(jpg|jpeg|png|gif|mp4|x-msvideo|quicktime|heic|heif|dng|x-adobe-dng|webp)$/)) {
|
if (file.mimetype.match(/\/(jpg|jpeg|png|gif|mp4|x-msvideo|quicktime|heic|heif|dng|x-adobe-dng|webp|tiff)$/)) {
|
||||||
cb(null, true);
|
cb(null, true);
|
||||||
} else {
|
} else {
|
||||||
cb(new HttpException(`Unsupported file type ${extname(file.originalname)}`, HttpStatus.BAD_REQUEST), false);
|
cb(new HttpException(`Unsupported file type ${extname(file.originalname)}`, HttpStatus.BAD_REQUEST), false);
|
||||||
|
@ -60,8 +60,8 @@ export class MetadataExtractionProcessor {
|
|||||||
newExif.make = exifData['Make'] || null;
|
newExif.make = exifData['Make'] || null;
|
||||||
newExif.model = exifData['Model'] || null;
|
newExif.model = exifData['Model'] || null;
|
||||||
newExif.imageName = path.parse(fileName).name || null;
|
newExif.imageName = path.parse(fileName).name || null;
|
||||||
newExif.exifImageHeight = exifData['ExifImageHeight'] || null;
|
newExif.exifImageHeight = exifData['ExifImageHeight'] || exifData['ImageHeight'] || null;
|
||||||
newExif.exifImageWidth = exifData['ExifImageWidth'] || null;
|
newExif.exifImageWidth = exifData['ExifImageWidth'] || exifData['ImageWidth'] || null;
|
||||||
newExif.fileSizeInByte = fileSize || null;
|
newExif.fileSizeInByte = fileSize || null;
|
||||||
newExif.orientation = exifData['Orientation'] || null;
|
newExif.orientation = exifData['Orientation'] || null;
|
||||||
newExif.dateTimeOriginal = exifData['DateTimeOriginal'] || null;
|
newExif.dateTimeOriginal = exifData['DateTimeOriginal'] || null;
|
||||||
|
@ -51,62 +51,47 @@ export class ThumbnailGeneratorProcessor {
|
|||||||
const jpegThumbnailPath = resizePath + originalFilename + '.jpeg';
|
const jpegThumbnailPath = resizePath + originalFilename + '.jpeg';
|
||||||
|
|
||||||
if (asset.type == AssetType.IMAGE) {
|
if (asset.type == AssetType.IMAGE) {
|
||||||
sharp(asset.originalPath)
|
await sharp(asset.originalPath).resize(1440, 2560, { fit: 'inside' }).jpeg().rotate().toFile(jpegThumbnailPath);
|
||||||
.resize(1440, 2560, { fit: 'inside' })
|
await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
|
||||||
.jpeg()
|
|
||||||
.rotate()
|
|
||||||
.toFile(jpegThumbnailPath, async (err) => {
|
|
||||||
if (!err) {
|
|
||||||
await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
|
|
||||||
|
|
||||||
// Update resize path to send to generate webp queue
|
// Update resize path to send to generate webp queue
|
||||||
asset.resizePath = jpegThumbnailPath;
|
asset.resizePath = jpegThumbnailPath;
|
||||||
|
|
||||||
await this.thumbnailGeneratorQueue.add(
|
await this.thumbnailGeneratorQueue.add(generateWEBPThumbnailProcessorName, { asset }, { jobId: randomUUID() });
|
||||||
generateWEBPThumbnailProcessorName,
|
await this.metadataExtractionQueue.add(imageTaggingProcessorName, { asset }, { jobId: randomUUID() });
|
||||||
{ asset },
|
await this.metadataExtractionQueue.add(objectDetectionProcessorName, { asset }, { jobId: randomUUID() });
|
||||||
{ jobId: randomUUID() },
|
this.wsCommunicationGateway.server.to(asset.userId).emit('on_upload_success', JSON.stringify(mapAsset(asset)));
|
||||||
);
|
|
||||||
await this.metadataExtractionQueue.add(imageTaggingProcessorName, { asset }, { jobId: randomUUID() });
|
|
||||||
await this.metadataExtractionQueue.add(objectDetectionProcessorName, { asset }, { jobId: randomUUID() });
|
|
||||||
this.wsCommunicationGateway.server
|
|
||||||
.to(asset.userId)
|
|
||||||
.emit('on_upload_success', JSON.stringify(mapAsset(asset)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset.type == AssetType.VIDEO) {
|
if (asset.type == AssetType.VIDEO) {
|
||||||
ffmpeg(asset.originalPath)
|
await new Promise((resolve, reject) => {
|
||||||
.outputOptions(['-ss 00:00:00.000', '-frames:v 1'])
|
ffmpeg(asset.originalPath)
|
||||||
.output(jpegThumbnailPath)
|
.outputOptions(['-ss 00:00:00.000', '-frames:v 1'])
|
||||||
.on('start', () => {
|
.output(jpegThumbnailPath)
|
||||||
Logger.log('Start Generating Video Thumbnail', 'generateJPEGThumbnail');
|
.on('start', () => {
|
||||||
})
|
Logger.log('Start Generating Video Thumbnail', 'generateJPEGThumbnail');
|
||||||
.on('error', (error) => {
|
})
|
||||||
Logger.error(`Cannot Generate Video Thumbnail ${error}`, 'generateJPEGThumbnail');
|
.on('error', (error) => {
|
||||||
// reject();
|
Logger.error(`Cannot Generate Video Thumbnail ${error}`, 'generateJPEGThumbnail');
|
||||||
})
|
reject(error);
|
||||||
.on('end', async () => {
|
})
|
||||||
Logger.log(`Generating Video Thumbnail Success ${asset.id}`, 'generateJPEGThumbnail');
|
.on('end', async () => {
|
||||||
await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
|
Logger.log(`Generating Video Thumbnail Success ${asset.id}`, 'generateJPEGThumbnail');
|
||||||
|
resolve(asset);
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
|
||||||
// Update resize path to send to generate webp queue
|
await this.assetRepository.update({ id: asset.id }, { resizePath: jpegThumbnailPath });
|
||||||
asset.resizePath = jpegThumbnailPath;
|
|
||||||
|
|
||||||
await this.thumbnailGeneratorQueue.add(
|
// Update resize path to send to generate webp queue
|
||||||
generateWEBPThumbnailProcessorName,
|
asset.resizePath = jpegThumbnailPath;
|
||||||
{ asset },
|
|
||||||
{ jobId: randomUUID() },
|
|
||||||
);
|
|
||||||
await this.metadataExtractionQueue.add(imageTaggingProcessorName, { asset }, { jobId: randomUUID() });
|
|
||||||
await this.metadataExtractionQueue.add(objectDetectionProcessorName, { asset }, { jobId: randomUUID() });
|
|
||||||
|
|
||||||
this.wsCommunicationGateway.server
|
await this.thumbnailGeneratorQueue.add(generateWEBPThumbnailProcessorName, { asset }, { jobId: randomUUID() });
|
||||||
.to(asset.userId)
|
await this.metadataExtractionQueue.add(imageTaggingProcessorName, { asset }, { jobId: randomUUID() });
|
||||||
.emit('on_upload_success', JSON.stringify(mapAsset(asset)));
|
await this.metadataExtractionQueue.add(objectDetectionProcessorName, { asset }, { jobId: randomUUID() });
|
||||||
})
|
|
||||||
.run();
|
this.wsCommunicationGateway.server.to(asset.userId).emit('on_upload_success', JSON.stringify(mapAsset(asset)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,16 +102,10 @@ export class ThumbnailGeneratorProcessor {
|
|||||||
if (!asset.resizePath) {
|
if (!asset.resizePath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const webpPath = asset.resizePath.replace('jpeg', 'webp');
|
const webpPath = asset.resizePath.replace('jpeg', 'webp');
|
||||||
|
|
||||||
sharp(asset.resizePath)
|
await sharp(asset.resizePath).resize(250).webp().rotate().toFile(webpPath);
|
||||||
.resize(250)
|
await this.assetRepository.update({ id: asset.id }, { webpPath: webpPath });
|
||||||
.webp()
|
|
||||||
.rotate()
|
|
||||||
.toFile(webpPath, (err) => {
|
|
||||||
if (!err) {
|
|
||||||
this.assetRepository.update({ id: asset.id }, { webpPath: webpPath });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user