mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix remove assets from shared link
This commit is contained in:
parent
7b7d91a5e1
commit
42c16022ac
4 changed files with 25 additions and 1 deletions
|
|
@ -31,6 +31,7 @@ import { ProcessRepository } from 'src/repositories/process.repository';
|
|||
import { SearchRepository } from 'src/repositories/search.repository';
|
||||
import { ServerInfoRepository } from 'src/repositories/server-info.repository';
|
||||
import { SessionRepository } from 'src/repositories/session.repository';
|
||||
import { SharedLinkAssetRepository } from 'src/repositories/shared-link-asset.repository';
|
||||
import { SharedLinkRepository } from 'src/repositories/shared-link.repository';
|
||||
import { StackRepository } from 'src/repositories/stack.repository';
|
||||
import { StorageRepository } from 'src/repositories/storage.repository';
|
||||
|
|
@ -79,6 +80,7 @@ export const repositories = [
|
|||
SessionRepository,
|
||||
ServerInfoRepository,
|
||||
SharedLinkRepository,
|
||||
SharedLinkAssetRepository,
|
||||
StackRepository,
|
||||
StorageRepository,
|
||||
SyncRepository,
|
||||
|
|
|
|||
18
server/src/repositories/shared-link-asset.repository.ts
Normal file
18
server/src/repositories/shared-link-asset.repository.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Kysely } from 'kysely';
|
||||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import { DB } from 'src/schema';
|
||||
|
||||
export class SharedLinkAssetRepository {
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
async remove(sharedLinkId: string, assetsId: string[]) {
|
||||
const deleted = await this.db
|
||||
.deleteFrom('shared_link_asset')
|
||||
.where('shared_link_asset.sharedLinksId', '=', sharedLinkId)
|
||||
.where('shared_link_asset.assetsId', 'in', assetsId)
|
||||
.returning('assetsId')
|
||||
.execute();
|
||||
|
||||
return deleted.map((row) => row.assetsId);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@ import { ProcessRepository } from 'src/repositories/process.repository';
|
|||
import { SearchRepository } from 'src/repositories/search.repository';
|
||||
import { ServerInfoRepository } from 'src/repositories/server-info.repository';
|
||||
import { SessionRepository } from 'src/repositories/session.repository';
|
||||
import { SharedLinkAssetRepository } from 'src/repositories/shared-link-asset.repository';
|
||||
import { SharedLinkRepository } from 'src/repositories/shared-link.repository';
|
||||
import { StackRepository } from 'src/repositories/stack.repository';
|
||||
import { StorageRepository } from 'src/repositories/storage.repository';
|
||||
|
|
@ -141,6 +142,7 @@ export class BaseService {
|
|||
protected serverInfoRepository: ServerInfoRepository,
|
||||
protected sessionRepository: SessionRepository,
|
||||
protected sharedLinkRepository: SharedLinkRepository,
|
||||
protected sharedLinkAssetRepository: SharedLinkAssetRepository,
|
||||
protected stackRepository: StackRepository,
|
||||
protected storageRepository: StorageRepository,
|
||||
protected syncRepository: SyncRepository,
|
||||
|
|
|
|||
|
|
@ -175,9 +175,11 @@ export class SharedLinkService extends BaseService {
|
|||
throw new BadRequestException('Invalid shared link type');
|
||||
}
|
||||
|
||||
const removedAssetIds = await this.sharedLinkAssetRepository.remove(id, dto.assetIds);
|
||||
|
||||
const results: AssetIdsResponseDto[] = [];
|
||||
for (const assetId of dto.assetIds) {
|
||||
const hasAsset = sharedLink.assets.find((asset) => asset.id === assetId);
|
||||
const hasAsset = removedAssetIds.find((id) => id === assetId);
|
||||
if (!hasAsset) {
|
||||
results.push({ assetId, success: false, error: AssetIdErrorReason.NOT_FOUND });
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue