mirror of
https://github.com/immich-app/immich.git
synced 2024-09-21 10:37:20 +00:00
handle notify
This commit is contained in:
parent
7ef63e69a0
commit
d208589389
@ -267,7 +267,7 @@ export class JobService {
|
||||
}
|
||||
|
||||
case JobName.GENERATE_THUMBNAILS: {
|
||||
if (item.data.source !== 'upload') {
|
||||
if (!item.data.notify && item.data.source !== 'upload') {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -254,9 +254,28 @@ export class MediaService {
|
||||
}
|
||||
|
||||
private async generateVideoThumbnails(asset: AssetEntity) {
|
||||
const { image } = await this.configCore.getConfig({ withCache: true });
|
||||
const previewPath = await this.generateVideoThumbnail(asset, AssetPathType.PREVIEW, image.previewFormat);
|
||||
const thumbnailPath = await this.generateVideoThumbnail(asset, AssetPathType.THUMBNAIL, image.thumbnailFormat);
|
||||
const { image, ffmpeg } = await this.configCore.getConfig({ withCache: true });
|
||||
const previewPath = StorageCore.getImagePath(asset, AssetPathType.PREVIEW, image.previewFormat);
|
||||
const thumbnailPath = StorageCore.getImagePath(asset, AssetPathType.THUMBNAIL, image.thumbnailFormat);
|
||||
this.storageCore.ensureFolders(previewPath);
|
||||
|
||||
const { audioStreams, videoStreams } = await this.mediaRepository.probe(asset.originalPath);
|
||||
const mainVideoStream = this.getMainStream(videoStreams);
|
||||
if (!mainVideoStream) {
|
||||
throw new Error(`No video streams found for asset ${asset.id}`);
|
||||
}
|
||||
const mainAudioStream = this.getMainStream(audioStreams);
|
||||
|
||||
const previewConfig = ThumbnailConfig.create({ ...ffmpeg, targetResolution: image.previewSize.toString() });
|
||||
const thumbnailConfig = ThumbnailConfig.create({ ...ffmpeg, targetResolution: image.thumbnailSize.toString() });
|
||||
|
||||
const previewOptions = previewConfig.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
|
||||
const thumbnailOptions = thumbnailConfig.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
|
||||
await Promise.all([
|
||||
this.mediaRepository.transcode(asset.originalPath, previewPath, previewOptions),
|
||||
this.mediaRepository.transcode(asset.originalPath, thumbnailPath, thumbnailOptions),
|
||||
]);
|
||||
|
||||
const thumbhash = await this.mediaRepository.generateThumbnails(previewPath, {
|
||||
thumbhash: true,
|
||||
processInvalidImages: process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true',
|
||||
@ -289,29 +308,6 @@ export class MediaService {
|
||||
};
|
||||
}
|
||||
|
||||
private async generateVideoThumbnail(asset: AssetEntity, type: GeneratedImageType, format: ImageFormat) {
|
||||
const { image, ffmpeg } = await this.configCore.getConfig({ withCache: true });
|
||||
const path = StorageCore.getImagePath(asset, type, format);
|
||||
const size = type === AssetPathType.PREVIEW ? image.previewSize : image.thumbnailSize;
|
||||
this.storageCore.ensureFolders(path);
|
||||
|
||||
const { audioStreams, videoStreams } = await this.mediaRepository.probe(asset.originalPath);
|
||||
const mainVideoStream = this.getMainStream(videoStreams);
|
||||
if (!mainVideoStream) {
|
||||
throw new Error(`No video streams found for asset ${asset.id}`);
|
||||
}
|
||||
const mainAudioStream = this.getMainStream(audioStreams);
|
||||
const config = ThumbnailConfig.create({ ...ffmpeg, targetResolution: size.toString() });
|
||||
const options = config.getCommand(TranscodeTarget.VIDEO, mainVideoStream, mainAudioStream);
|
||||
await this.mediaRepository.transcode(asset.originalPath, path, options);
|
||||
|
||||
this.logger.log(
|
||||
`Successfully generated ${format.toUpperCase()} ${asset.type.toLowerCase()} ${type} for asset ${asset.id}`,
|
||||
);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
async handleQueueVideoConversion(job: IBaseJob): Promise<JobStatus> {
|
||||
const { force } = job;
|
||||
|
||||
|
@ -155,7 +155,7 @@ describe(NotificationService.name, () => {
|
||||
it('should queue the generate thumbnail job', async () => {
|
||||
await sut.onAssetShow({ assetId: 'asset-id', userId: 'user-id' });
|
||||
expect(jobMock.queue).toHaveBeenCalledWith({
|
||||
name: JobName.GENERATE_THUMBNAIL,
|
||||
name: JobName.GENERATE_THUMBNAILS,
|
||||
data: { id: 'asset-id', notify: true },
|
||||
});
|
||||
});
|
||||
|
@ -65,7 +65,7 @@ export class NotificationService {
|
||||
|
||||
@OnEmit({ event: 'asset.show' })
|
||||
async onAssetShow({ assetId }: ArgOf<'asset.show'>) {
|
||||
await this.jobRepository.queue({ name: JobName.GENERATE_THUMBNAIL, data: { id: assetId, notify: true } });
|
||||
await this.jobRepository.queue({ name: JobName.GENERATE_THUMBNAILS, data: { id: assetId, notify: true } });
|
||||
}
|
||||
|
||||
@OnEmit({ event: 'asset.trash' })
|
||||
|
Loading…
Reference in New Issue
Block a user