mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
fix(web+server): showing assets without thumbnail (#2652)
* fix(web+server): showing assets without thumbnail * missed change
This commit is contained in:
@@ -6,7 +6,7 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm/repository/Repository';
|
||||
import { CuratedObjectsResponseDto } from './response-dto/curated-objects-response.dto';
|
||||
import { AssetCountByTimeBucket } from './response-dto/asset-count-by-time-group-response.dto';
|
||||
import { TimeGroupEnum } from './dto/get-asset-count-by-time-bucket.dto';
|
||||
import { GetAssetCountByTimeBucketDto, TimeGroupEnum } from './dto/get-asset-count-by-time-bucket.dto';
|
||||
import { GetAssetByTimeBucketDto } from './dto/get-asset-by-time-bucket.dto';
|
||||
import { AssetCountByUserIdResponseDto } from './response-dto/asset-count-by-user-id-response.dto';
|
||||
import { CheckExistingAssetsDto } from './dto/check-existing-assets.dto';
|
||||
@@ -37,7 +37,7 @@ export interface IAssetRepository {
|
||||
getLocationsByUserId(userId: string): Promise<CuratedLocationsResponseDto[]>;
|
||||
getDetectedObjectsByUserId(userId: string): Promise<CuratedObjectsResponseDto[]>;
|
||||
getSearchPropertiesByUserId(userId: string): Promise<SearchPropertiesDto[]>;
|
||||
getAssetCountByTimeBucket(userId: string, timeBucket: TimeGroupEnum): Promise<AssetCountByTimeBucket[]>;
|
||||
getAssetCountByTimeBucket(userId: string, dto: GetAssetCountByTimeBucketDto): Promise<AssetCountByTimeBucket[]>;
|
||||
getAssetCountByUserId(userId: string): Promise<AssetCountByUserIdResponseDto>;
|
||||
getArchivedAssetCountByUserId(userId: string): Promise<AssetCountByUserIdResponseDto>;
|
||||
getAssetByTimeBucket(userId: string, getAssetByTimeBucketDto: GetAssetByTimeBucketDto): Promise<AssetEntity[]>;
|
||||
@@ -119,36 +119,35 @@ export class AssetRepository implements IAssetRepository {
|
||||
return builder.getMany();
|
||||
}
|
||||
|
||||
async getAssetCountByTimeBucket(userId: string, timeBucket: TimeGroupEnum) {
|
||||
let result: AssetCountByTimeBucket[] = [];
|
||||
async getAssetCountByTimeBucket(
|
||||
userId: string,
|
||||
dto: GetAssetCountByTimeBucketDto,
|
||||
): Promise<AssetCountByTimeBucket[]> {
|
||||
const builder = this.assetRepository
|
||||
.createQueryBuilder('asset')
|
||||
.select(`COUNT(asset.id)::int`, 'count')
|
||||
.where('"ownerId" = :userId', { userId: userId })
|
||||
.andWhere('asset.isVisible = true')
|
||||
.andWhere('asset.isArchived = false');
|
||||
|
||||
if (timeBucket === TimeGroupEnum.Month) {
|
||||
result = await this.assetRepository
|
||||
.createQueryBuilder('asset')
|
||||
.select(`COUNT(asset.id)::int`, 'count')
|
||||
// Using a parameter for this doesn't work https://github.com/typeorm/typeorm/issues/7308
|
||||
if (dto.timeGroup === TimeGroupEnum.Month) {
|
||||
builder
|
||||
.addSelect(`date_trunc('month', "fileCreatedAt")`, 'timeBucket')
|
||||
.where('"ownerId" = :userId', { userId: userId })
|
||||
.andWhere('asset.resizePath is not NULL')
|
||||
.andWhere('asset.isVisible = true')
|
||||
.andWhere('asset.isArchived = false')
|
||||
.groupBy(`date_trunc('month', "fileCreatedAt")`)
|
||||
.orderBy(`date_trunc('month', "fileCreatedAt")`, 'DESC')
|
||||
.getRawMany();
|
||||
} else if (timeBucket === TimeGroupEnum.Day) {
|
||||
result = await this.assetRepository
|
||||
.createQueryBuilder('asset')
|
||||
.select(`COUNT(asset.id)::int`, 'count')
|
||||
.orderBy(`date_trunc('month', "fileCreatedAt")`, 'DESC');
|
||||
} else if (dto.timeGroup === TimeGroupEnum.Day) {
|
||||
builder
|
||||
.addSelect(`date_trunc('day', "fileCreatedAt")`, 'timeBucket')
|
||||
.where('"ownerId" = :userId', { userId: userId })
|
||||
.andWhere('asset.resizePath is not NULL')
|
||||
.andWhere('asset.isVisible = true')
|
||||
.andWhere('asset.isArchived = false')
|
||||
.groupBy(`date_trunc('day', "fileCreatedAt")`)
|
||||
.orderBy(`date_trunc('day', "fileCreatedAt")`, 'DESC')
|
||||
.getRawMany();
|
||||
.orderBy(`date_trunc('day', "fileCreatedAt")`, 'DESC');
|
||||
}
|
||||
|
||||
return result;
|
||||
if (!dto.withoutThumbs) {
|
||||
builder.andWhere('asset.resizePath is not NULL');
|
||||
}
|
||||
|
||||
return builder.getRawMany();
|
||||
}
|
||||
|
||||
async getSearchPropertiesByUserId(userId: string): Promise<SearchPropertiesDto[]> {
|
||||
@@ -231,7 +230,7 @@ export class AssetRepository implements IAssetRepository {
|
||||
return this.assetRepository.find({
|
||||
where: {
|
||||
ownerId,
|
||||
resizePath: Not(IsNull()),
|
||||
resizePath: dto.withoutThumbs ? undefined : Not(IsNull()),
|
||||
isVisible: true,
|
||||
isFavorite: dto.isFavorite,
|
||||
isArchived: dto.isArchived,
|
||||
|
||||
@@ -533,7 +533,7 @@ export class AssetService {
|
||||
|
||||
const result = await this._assetRepository.getAssetCountByTimeBucket(
|
||||
getAssetCountByTimeBucketDto.userId || authUser.id,
|
||||
getAssetCountByTimeBucketDto.timeGroup,
|
||||
getAssetCountByTimeBucketDto,
|
||||
);
|
||||
|
||||
return mapAssetCountByTimeBucket(result);
|
||||
|
||||
@@ -16,6 +16,14 @@ export class AssetSearchDto {
|
||||
@Transform(toBoolean)
|
||||
isArchived?: boolean;
|
||||
|
||||
/**
|
||||
* Include assets without thumbnails
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(toBoolean)
|
||||
withoutThumbs?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
skip?: number;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsOptional, IsUUID } from 'class-validator';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsBoolean, IsNotEmpty, IsOptional, IsUUID } from 'class-validator';
|
||||
import { toBoolean } from '../../../utils/transform.util';
|
||||
|
||||
export enum TimeGroupEnum {
|
||||
Day = 'day',
|
||||
@@ -19,4 +21,12 @@ export class GetAssetCountByTimeBucketDto {
|
||||
@IsUUID('4')
|
||||
@ApiProperty({ format: 'uuid' })
|
||||
userId?: string;
|
||||
|
||||
/**
|
||||
* Include assets without thumbnails
|
||||
*/
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform(toBoolean)
|
||||
withoutThumbs?: boolean;
|
||||
}
|
||||
|
||||
@@ -3380,6 +3380,15 @@
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "withoutThumbs",
|
||||
"required": false,
|
||||
"in": "query",
|
||||
"description": "Include assets without thumbnails",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "skip",
|
||||
"required": false,
|
||||
@@ -6221,6 +6230,10 @@
|
||||
"userId": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"withoutThumbs": {
|
||||
"type": "boolean",
|
||||
"description": "Include assets without thumbnails"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
Reference in New Issue
Block a user