mirror of
https://github.com/immich-app/immich.git
synced 2025-12-10 09:33:58 +09:00
@@ -1,4 +1,5 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { StorageCore } from 'src/cores/storage.core';
|
||||
import { BulkIdErrorReason, BulkIdResponseDto } from 'src/dtos/asset-ids.response.dto';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { AssetFileEntity } from 'src/entities/asset-files.entity';
|
||||
@@ -134,8 +135,10 @@ export const getMyPartnerIds = async ({ userId, repository, timelineEnabled }: P
|
||||
return [...partnerIds];
|
||||
};
|
||||
|
||||
export type AssetHookRepositories = { asset: IAssetRepository; event: IEventRepository };
|
||||
|
||||
export const onBeforeLink = async (
|
||||
{ asset: assetRepository, event: eventRepository }: { asset: IAssetRepository; event: IEventRepository },
|
||||
{ asset: assetRepository, event: eventRepository }: AssetHookRepositories,
|
||||
{ userId, livePhotoVideoId }: { userId: string; livePhotoVideoId: string },
|
||||
) => {
|
||||
const motionAsset = await assetRepository.getById(livePhotoVideoId);
|
||||
@@ -154,3 +157,27 @@ export const onBeforeLink = async (
|
||||
await eventRepository.emit('asset.hide', { assetId: motionAsset.id, userId });
|
||||
}
|
||||
};
|
||||
|
||||
export const onBeforeUnlink = async (
|
||||
{ asset: assetRepository }: AssetHookRepositories,
|
||||
{ livePhotoVideoId }: { livePhotoVideoId: string },
|
||||
) => {
|
||||
const motion = await assetRepository.getById(livePhotoVideoId);
|
||||
if (!motion) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (StorageCore.isAndroidMotionPath(motion.originalPath)) {
|
||||
throw new BadRequestException('Cannot unlink Android motion photos');
|
||||
}
|
||||
|
||||
return motion;
|
||||
};
|
||||
|
||||
export const onAfterUnlink = async (
|
||||
{ asset: assetRepository, event: eventRepository }: AssetHookRepositories,
|
||||
{ userId, livePhotoVideoId }: { userId: string; livePhotoVideoId: string },
|
||||
) => {
|
||||
await assetRepository.update({ id: livePhotoVideoId, isVisible: true });
|
||||
await eventRepository.emit('asset.show', { assetId: livePhotoVideoId, userId });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user