feat(web): manual stacking asset (#4650)

Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
Alex 2023-10-27 15:34:01 -05:00 committed by GitHub
parent 72dcde9e0f
commit 8b5b6d0821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 437 additions and 82 deletions

View file

@ -1841,6 +1841,14 @@
"type": "boolean"
}
},
{
"name": "withStacked",
"required": false,
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "timeBucket",
"required": true,
@ -1961,6 +1969,14 @@
"type": "boolean"
}
},
{
"name": "withStacked",
"required": false,
"in": "query",
"schema": {
"type": "boolean"
}
},
{
"name": "key",
"required": false,

View file

@ -201,7 +201,7 @@ export class AssetService {
await this.timeBucketChecks(authUser, dto);
const assets = await this.assetRepository.getByTimeBucket(dto.timeBucket, dto);
if (authUser.isShowMetadata) {
return assets.map((asset) => mapAsset(asset));
return assets.map((asset) => mapAsset(asset, { withStack: true }));
} else {
return assets.map((asset) => mapAsset(asset, { stripMetadata: true }));
}

View file

@ -33,6 +33,11 @@ export class TimeBucketDto {
@IsBoolean()
@Transform(toBoolean)
isTrashed?: boolean;
@Optional()
@IsBoolean()
@Transform(toBoolean)
withStacked?: boolean;
}
export class TimeBucketAssetDto extends TimeBucketDto {

View file

@ -65,6 +65,7 @@ export interface TimeBucketOptions {
albumId?: string;
personId?: string;
userId?: string;
withStacked?: boolean;
}
export interface TimeBucketItem {

View file

@ -30,7 +30,9 @@ const truncateMap: Record<TimeBucketSize, string> = {
};
const dateTrunc = (options: TimeBucketOptions) =>
`(date_trunc('${truncateMap[options.size]}', ("localDateTime" at time zone 'UTC')) at time zone 'UTC')::timestamptz`;
`(date_trunc('${
truncateMap[options.size]
}', (asset."localDateTime" at time zone 'UTC')) at time zone 'UTC')::timestamptz`;
@Injectable()
export class AssetRepository implements IAssetRepository {
@ -505,13 +507,14 @@ export class AssetRepository implements IAssetRepository {
}
private getBuilder(options: TimeBucketOptions) {
const { isArchived, isFavorite, isTrashed, albumId, personId, userId } = options;
const { isArchived, isFavorite, isTrashed, albumId, personId, userId, withStacked } = options;
let builder = this.repository
.createQueryBuilder('asset')
.where('asset.isVisible = true')
.andWhere('asset.fileCreatedAt < NOW()')
.leftJoinAndSelect('asset.exifInfo', 'exifInfo');
.leftJoinAndSelect('asset.exifInfo', 'exifInfo')
.leftJoinAndSelect('asset.stack', 'stack');
if (albumId) {
builder = builder.leftJoin('asset.albums', 'album').andWhere('album.id = :albumId', { albumId });
@ -540,11 +543,9 @@ export class AssetRepository implements IAssetRepository {
.andWhere('person.id = :personId', { personId });
}
// Hide stack children only in main timeline
// Uncomment after adding support for stacked assets in web client
// if (!isArchived && !isFavorite && !personId && !albumId && !isTrashed) {
// builder = builder.andWhere('asset.stackParent IS NULL');
// }
if (withStacked) {
builder = builder.andWhere('asset.stackParentId IS NULL');
}
return builder;
}