feat: asset copy (#23172)

This commit is contained in:
Daniel Dietzler
2025-10-29 14:43:47 +01:00
committed by GitHub
parent fdfb04d83c
commit 4ae7cadeae
20 changed files with 644 additions and 2 deletions

View File

@@ -397,4 +397,18 @@ export class AlbumRepository {
.orderBy('assetCount', 'desc')
.execute();
}
@GenerateSql({ params: [{ sourceAssetId: DummyValue.UUID, targetAssetId: DummyValue.UUID }] })
async copyAlbums({ sourceAssetId, targetAssetId }: { sourceAssetId: string; targetAssetId: string }) {
return this.db
.insertInto('album_asset')
.expression((eb) =>
eb
.selectFrom('album_asset')
.select((eb) => ['album_asset.albumsId', eb.val(targetAssetId).as('assetsId')])
.where('album_asset.assetsId', '=', sourceAssetId),
)
.onConflict((oc) => oc.doNothing())
.execute();
}
}

View File

@@ -1,5 +1,6 @@
import { Kysely } from 'kysely';
import { InjectKysely } from 'nestjs-kysely';
import { DummyValue, GenerateSql } from 'src/decorators';
import { DB } from 'src/schema';
export class SharedLinkAssetRepository {
@@ -15,4 +16,18 @@ export class SharedLinkAssetRepository {
return deleted.map((row) => row.assetsId);
}
@GenerateSql({ params: [{ sourceAssetId: DummyValue.UUID, targetAssetId: DummyValue.UUID }] })
async copySharedLinks({ sourceAssetId, targetAssetId }: { sourceAssetId: string; targetAssetId: string }) {
return this.db
.insertInto('shared_link_asset')
.expression((eb) =>
eb
.selectFrom('shared_link_asset')
.select((eb) => [eb.val(targetAssetId).as('assetsId'), 'shared_link_asset.sharedLinksId'])
.where('shared_link_asset.assetsId', '=', sourceAssetId),
)
.onConflict((oc) => oc.doNothing())
.execute();
}
}

View File

@@ -162,4 +162,9 @@ export class StackRepository {
.where('asset.id', '=', assetId)
.executeTakeFirst();
}
@GenerateSql({ params: [{ sourceId: DummyValue.UUID, targetId: DummyValue.UUID }] })
merge({ sourceId, targetId }: { sourceId: string; targetId: string }) {
return this.db.updateTable('asset').set({ stackId: targetId }).where('asset.stackId', '=', sourceId).execute();
}
}