feat: bulk asset metadata endpoints (#25133)

This commit is contained in:
Jason Rasmussen
2026-01-08 14:52:16 -05:00
committed by GitHub
parent 109c79125d
commit a2ba36c16d
29 changed files with 1325 additions and 200 deletions

View File

@@ -5,11 +5,12 @@ import { InjectKysely } from 'nestjs-kysely';
import { LockableProperty, Stack } from 'src/database';
import { Chunked, ChunkedArray, DummyValue, GenerateSql } from 'src/decorators';
import { AuthDto } from 'src/dtos/auth.dto';
import { AssetFileType, AssetMetadataKey, AssetOrder, AssetStatus, AssetType, AssetVisibility } from 'src/enum';
import { AssetFileType, AssetOrder, AssetStatus, AssetType, AssetVisibility } from 'src/enum';
import { DB } from 'src/schema';
import { AssetExifTable } from 'src/schema/tables/asset-exif.table';
import { AssetFileTable } from 'src/schema/tables/asset-file.table';
import { AssetJobStatusTable } from 'src/schema/tables/asset-job-status.table';
import { AssetMetadataTable } from 'src/schema/tables/asset-metadata.table';
import { AssetTable } from 'src/schema/tables/asset.table';
import {
anyUuid,
@@ -256,7 +257,7 @@ export class AssetRepository {
.execute();
}
upsertMetadata(id: string, items: Array<{ key: AssetMetadataKey; value: object }>) {
upsertMetadata(id: string, items: Array<{ key: string; value: object }>) {
return this.db
.insertInto('asset_metadata')
.values(items.map((item) => ({ assetId: id, ...item })))
@@ -269,8 +270,21 @@ export class AssetRepository {
.execute();
}
upsertBulkMetadata(items: Insertable<AssetMetadataTable>[]) {
return this.db
.insertInto('asset_metadata')
.values(items)
.onConflict((oc) =>
oc
.columns(['assetId', 'key'])
.doUpdateSet((eb) => ({ key: eb.ref('excluded.key'), value: eb.ref('excluded.value') })),
)
.returning(['assetId', 'key', 'value', 'updatedAt'])
.execute();
}
@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
getMetadataByKey(assetId: string, key: AssetMetadataKey) {
getMetadataByKey(assetId: string, key: string) {
return this.db
.selectFrom('asset_metadata')
.select(['key', 'value', 'updatedAt'])
@@ -280,10 +294,23 @@ export class AssetRepository {
}
@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
async deleteMetadataByKey(id: string, key: AssetMetadataKey) {
async deleteMetadataByKey(id: string, key: string) {
await this.db.deleteFrom('asset_metadata').where('assetId', '=', id).where('key', '=', key).execute();
}
@GenerateSql({ params: [[{ assetId: DummyValue.UUID, key: DummyValue.STRING }]] })
async deleteBulkMetadata(items: Array<{ assetId: string; key: string }>) {
if (items.length === 0) {
return;
}
await this.db.transaction().execute(async (tx) => {
for (const { assetId, key } of items) {
await tx.deleteFrom('asset_metadata').where('assetId', '=', assetId).where('key', '=', key).execute();
}
});
}
create(asset: Insertable<AssetTable>) {
return this.db.insertInto('asset').values(asset).returningAll().executeTakeFirstOrThrow();
}