feat(server): add originalFileName to asset table (#2231)

This commit is contained in:
Alex 2023-04-11 05:23:39 -05:00 committed by GitHub
parent db628cec11
commit a1a62b00a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 143 additions and 60 deletions

View file

@ -2,6 +2,7 @@ import { AuthUserDto, IJobRepository, JobName } from '@app/domain';
import { AssetEntity, UserEntity } from '@app/infra/entities';
import { IAssetRepository } from './asset-repository';
import { CreateAssetDto, UploadFile } from './dto/create-asset.dto';
import { parse } from 'node:path';
export class AssetCore {
constructor(private repository: IAssetRepository, private jobRepository: IJobRepository) {}
@ -35,6 +36,7 @@ export class AssetCore {
encodedVideoPath: null,
tags: [],
sharedLinks: [],
originalFileName: parse(file.originalName).name,
});
await this.jobRepository.queue({ name: JobName.ASSET_UPLOADED, data: { asset, fileName: file.originalName } });

View file

@ -10,9 +10,6 @@ export class CreateExifDto {
@IsOptional()
model?: string;
@IsOptional()
imageName?: string;
@IsOptional()
exifImageWidth?: number;

View file

@ -28,8 +28,8 @@ export class DownloadService {
let fileCount = 0;
let complete = true;
for (const { id, originalPath, exifInfo } of assets) {
const name = `${exifInfo?.imageName || id}${extname(originalPath)}`;
for (const { originalPath, exifInfo, originalFileName } of assets) {
const name = `${originalFileName}${extname(originalPath)}`;
archive.file(originalPath, { name });
totalSize += Number(exifInfo?.fileSizeInByte || 0);
fileCount++;

View file

@ -1,6 +1,5 @@
import {
AssetCore,
getFileNameWithoutExtension,
IAssetRepository,
IAssetUploadedJob,
IBaseJob,
@ -21,7 +20,6 @@ import { ExifDateTime, exiftool, Tags } from 'exiftool-vendored';
import ffmpeg, { FfprobeData } from 'fluent-ffmpeg';
import { Duration } from 'luxon';
import fs from 'node:fs';
import path from 'path';
import sharp from 'sharp';
import { Repository } from 'typeorm/repository/Repository';
import { promisify } from 'util';
@ -79,7 +77,7 @@ export class MetadataExtractionProcessor {
: await this.assetRepository.getWithout(WithoutProperty.EXIF);
for (const asset of assets) {
const fileName = asset.exifInfo?.imageName ?? getFileNameWithoutExtension(asset.originalPath);
const fileName = asset.originalFileName;
const name = asset.type === AssetType.VIDEO ? JobName.EXTRACT_VIDEO_METADATA : JobName.EXIF_EXTRACTION;
await this.jobRepository.queue({ name, data: { asset, fileName } });
}
@ -92,7 +90,6 @@ export class MetadataExtractionProcessor {
async extractExifInfo(job: Job<IAssetUploadedJob>) {
try {
let asset = job.data.asset;
const fileName = job.data.fileName;
const exifData = await exiftool.read<ImmichTags>(asset.originalPath).catch((e) => {
this.logger.warn(`The exifData parsing failed due to: ${e} on file ${asset.originalPath}`);
return null;
@ -126,7 +123,6 @@ export class MetadataExtractionProcessor {
const newExif = new ExifEntity();
newExif.assetId = asset.id;
newExif.imageName = path.parse(fileName).name;
newExif.fileSizeInByte = fileSizeInBytes;
newExif.make = exifData?.Make || null;
newExif.model = exifData?.Model || null;
@ -191,7 +187,6 @@ export class MetadataExtractionProcessor {
@Process({ name: JobName.EXTRACT_VIDEO_METADATA, concurrency: 2 })
async extractVideoMetadata(job: Job<IAssetUploadedJob>) {
let asset = job.data.asset;
const fileName = job.data.fileName;
if (!asset.isVisible) {
return;
@ -219,7 +214,6 @@ export class MetadataExtractionProcessor {
const newExif = new ExifEntity();
newExif.assetId = asset.id;
newExif.description = '';
newExif.imageName = path.parse(fileName).name || null;
newExif.fileSizeInByte = data.format.size || null;
newExif.dateTimeOriginal = fileCreatedAt ? new Date(fileCreatedAt) : null;
newExif.modifyDate = null;
@ -242,7 +236,6 @@ export class MetadataExtractionProcessor {
if (photoAsset) {
await this.assetCore.save({ id: photoAsset.id, livePhotoVideoId: asset.id });
await this.assetCore.save({ id: asset.id, isVisible: false });
newExif.imageName = (photoAsset.exifInfo as ExifEntity).imageName;
}
}