Skip to content

Commit

Permalink
feat: hide assets when deleting library
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Jan 16, 2025
1 parent 9d8a9d9 commit 0669169
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export interface IAssetRepository {
getAllByDeviceId(userId: string, deviceId: string): Promise<string[]>;
getLivePhotoCount(motionId: string): Promise<number>;
updateAll(ids: string[], options: Updateable<Assets>): Promise<void>;
updateByLibraryId(libraryId: string, options: Updateable<Assets>): Promise<void>;
updateDuplicates(options: AssetUpdateDuplicateOptions): Promise<void>;
update(asset: Updateable<Assets> & { id: string }): Promise<AssetEntity>;
remove(asset: AssetEntity): Promise<void>;
Expand Down
4 changes: 4 additions & 0 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ export class AssetRepository implements IAssetRepository {
await this.db.updateTable('assets').set(options).where('id', '=', anyUuid(ids)).execute();
}

async updateByLibraryId(libraryId: string, options: Updateable<Assets>): Promise<void> {
await this.db.updateTable('assets').set(options).where('libraryId', '=', asUuid(libraryId)).execute();
}

@GenerateSql({
params: [{ targetDuplicateId: DummyValue.UUID, duplicateIds: [DummyValue.UUID], assetIds: [DummyValue.UUID] }],
})
Expand Down
3 changes: 3 additions & 0 deletions server/src/services/library.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ export class LibraryService extends BaseService {
async handleDeleteLibrary(job: JobOf<JobName.LIBRARY_DELETE>): Promise<JobStatus> {
const libraryId = job.id;

// Hide all assets in the library before deleting them
await this.assetRepository.updateByLibraryId(libraryId, { deletedAt: new Date() });

const assetPagination = usePagination(JOBS_LIBRARY_PAGINATION_SIZE, (pagination) =>
this.assetRepository.getAll(pagination, { libraryId, withDeleted: true }),
);
Expand Down

0 comments on commit 0669169

Please sign in to comment.