High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
import { InjectKysely } from 'nestjs-kysely';
import type { Kysely } from 'kysely';
import { DummyValue, GenerateSql } from 'src/decorators.js';
import { AssetStatus } from 'src/enum.js';
import { DB } from 'src/schema/index.js';
export class TrashRepository {
constructor(@InjectKysely() private db: Kysely<DB>) {}
getDeletedIds(): AsyncIterableIterator<{ id: string }> {
return this.db.selectFrom('asset').select(['id']).where('status', '=', AssetStatus.Deleted).stream();
}
@GenerateSql({ params: [DummyValue.UUID] })
async restore(userId: string): Promise<number> {
const { numUpdatedRows } = await this.db
.updateTable('asset')
.where('ownerId', '=', userId)
.where('status', '=', AssetStatus.Trashed)
.set({ status: AssetStatus.Active, deletedAt: null })
.executeTakeFirst();
return Number(numUpdatedRows);
}
@GenerateSql({ params: [DummyValue.UUID] })
async empty(userId: string): Promise<number> {
const { numUpdatedRows } = await this.db
.updateTable('asset')
.where('ownerId', '=', userId)
.where('status', '=', AssetStatus.Trashed)
.set({ status: AssetStatus.Deleted })
.executeTakeFirst();
return Number(numUpdatedRows);
}
@GenerateSql({ params: [[DummyValue.UUID]] })
async restoreAll(ids: string[]): Promise<number> {
if (ids.length === 0) {
return 0;
}
const { numUpdatedRows } = await this.db
.updateTable('asset')
.where('status', '=', AssetStatus.Trashed)
.where('id', 'in', ids)
.set({ status: AssetStatus.Active, deletedAt: null })
.executeTakeFirst();
return Number(numUpdatedRows);
}
}