refactor(server): view repository (#12755)

This commit is contained in:
Jason Rasmussen
2024-09-17 16:32:09 -04:00
committed by GitHub
parent f53e4721cf
commit 1e6ef5c9e4
11 changed files with 159 additions and 166 deletions
@@ -836,50 +836,6 @@ export class AssetRepository implements IAssetRepository {
return builder.getMany();
}
async getUniqueOriginalPaths(userId: string): Promise<string[]> {
const builder = this.getBuilder({
userIds: [userId],
exifInfo: false,
withStacked: false,
isArchived: false,
isTrashed: false,
});
const results = await builder
.select("DISTINCT substring(asset.originalPath FROM '^(.*/)[^/]*$')", 'directoryPath')
.getRawMany();
return results.map((row: { directoryPath: string }) => row.directoryPath.replaceAll(/^\/|\/$/g, ''));
}
@GenerateSql({ params: [DummyValue.UUID, DummyValue.STRING] })
async getAssetsByOriginalPath(userId: string, partialPath: string): Promise<AssetEntity[]> {
const normalizedPath = partialPath.replaceAll(/^\/|\/$/g, '');
const builder = this.getBuilder({
userIds: [userId],
exifInfo: true,
withStacked: false,
isArchived: false,
isTrashed: false,
});
const assets = await builder
.where('asset.ownerId = :userId', { userId })
.andWhere(
new Brackets((qb) => {
qb.where('asset.originalPath LIKE :likePath', { likePath: `%${normalizedPath}/%` }).andWhere(
'asset.originalPath NOT LIKE :notLikePath',
{ notLikePath: `%${normalizedPath}/%/%` },
);
}),
)
.orderBy(String.raw`regexp_replace(asset.originalPath, '.*/(.+)', '\1')`, 'ASC')
.getMany();
return assets;
}
@GenerateSql({ params: [{ assetId: DummyValue.UUID, type: AssetFileType.PREVIEW, path: '/path/to/file' }] })
async upsertFile({ assetId, type, path }: { assetId: string; type: AssetFileType; path: string }): Promise<void> {
await this.fileRepository.upsert({ assetId, type, path }, { conflictPaths: ['assetId', 'type'] });