feat(server): apply storage migration after exif completes (#2093)

* feat(server): apply storage migraiton after exif completes

* feat: same for videos

* fix: migration for live photos
This commit is contained in:
Jason Rasmussen
2023-03-28 16:04:11 -04:00
committed by GitHub
parent 3497a0de54
commit b0d5c7035b
10 changed files with 54 additions and 78 deletions

View File

@@ -4,6 +4,10 @@ export function getFileNameWithoutExtension(path: string): string {
return basename(path, extname(path));
}
export function getLivePhotoMotionFilename(stillName: string, motionName: string) {
return getFileNameWithoutExtension(stillName) + extname(motionName);
}
const KiB = Math.pow(1024, 1);
const MiB = Math.pow(1024, 2);
const GiB = Math.pow(1024, 3);

View File

@@ -41,6 +41,7 @@ export enum JobName {
// storage template
STORAGE_TEMPLATE_MIGRATION = 'storage-template-migration',
STORAGE_TEMPLATE_MIGRATION_SINGLE = 'storage-template-migration-single',
SYSTEM_CONFIG_CHANGE = 'system-config-change',
// object tagging

View File

@@ -36,6 +36,7 @@ export type JobItem =
// Storage Template
| { name: JobName.STORAGE_TEMPLATE_MIGRATION }
| { name: JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE; data: IAssetJob }
| { name: JobName.SYSTEM_CONFIG_CHANGE }
// Metadata Extraction

View File

@@ -2,6 +2,8 @@ import { AssetEntity, SystemConfig } from '@app/infra/db/entities';
import { Inject, Injectable, Logger } from '@nestjs/common';
import { IAssetRepository } from '../asset/asset.repository';
import { APP_MEDIA_LOCATION } from '../domain.constant';
import { getLivePhotoMotionFilename } from '../domain.util';
import { IAssetJob } from '../job';
import { IStorageRepository } from '../storage/storage.repository';
import { INITIAL_SYSTEM_CONFIG, ISystemConfigRepository } from '../system-config';
import { StorageTemplateCore } from './storage-template.core';
@@ -20,6 +22,24 @@ export class StorageTemplateService {
this.core = new StorageTemplateCore(configRepository, config, storageRepository);
}
async handleTemplateMigrationSingle(data: IAssetJob) {
const { asset } = data;
try {
const filename = asset.exifInfo?.imageName || asset.id;
await this.moveAsset(asset, filename);
// move motion part of live photo
if (asset.livePhotoVideoId) {
const [livePhotoVideo] = await this.assetRepository.getByIds([asset.livePhotoVideoId]);
const motionFilename = getLivePhotoMotionFilename(filename, livePhotoVideo.originalPath);
await this.moveAsset(livePhotoVideo, motionFilename);
}
} catch (error: any) {
this.logger.error('Error running single template migration', error);
}
}
async handleTemplateMigration() {
try {
console.time('migrating-time');

View File

@@ -99,6 +99,10 @@ export class JobRepository implements IJobRepository {
await this.storageTemplateMigration.add(item.name);
break;
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE:
await this.storageTemplateMigration.add(item.name, item.data);
break;
case JobName.SYSTEM_CONFIG_CHANGE:
await this.backgroundTask.add(item.name, {});
break;