mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
Implemented load new image when navigating back from backup page (#9)
This commit is contained in:
parent
1d3ee2008c
commit
c24fb403c5
12 changed files with 133 additions and 38 deletions
|
|
@ -29,6 +29,7 @@ import { Response as Res } from 'express';
|
|||
import { promisify } from 'util';
|
||||
import { stat } from 'fs';
|
||||
import { pipeline } from 'stream';
|
||||
import { GetNewAssetQueryDto } from './dto/get-new-asset-query.dto';
|
||||
|
||||
const fileInfo = promisify(stat);
|
||||
|
||||
|
|
@ -141,6 +142,11 @@ export class AssetController {
|
|||
console.log('SHOULD NOT BE HERE');
|
||||
}
|
||||
|
||||
@Get('/new')
|
||||
async getNewAssets(@GetAuthUser() authUser: AuthUserDto, @Query(ValidationPipe) query: GetNewAssetQueryDto) {
|
||||
return await this.assetService.getNewAssets(authUser, query.latestDate);
|
||||
}
|
||||
|
||||
@Get('/all')
|
||||
async getAllAssets(@GetAuthUser() authUser: AuthUserDto, @Query(ValidationPipe) query: GetAllAssetQueryDto) {
|
||||
return await this.assetService.getAllAssets(authUser, query);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { MoreThan, Repository } from 'typeorm';
|
||||
import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
||||
import { CreateAssetDto } from './dto/create-asset.dto';
|
||||
import { UpdateAssetDto } from './dto/update-asset.dto';
|
||||
|
|
@ -8,6 +8,7 @@ import { AssetEntity, AssetType } from './entities/asset.entity';
|
|||
import _ from 'lodash';
|
||||
import { GetAllAssetQueryDto } from './dto/get-all-asset-query.dto';
|
||||
import { GetAllAssetReponseDto } from './dto/get-all-asset-response.dto';
|
||||
import { Greater } from '@tensorflow/tfjs-core';
|
||||
|
||||
@Injectable()
|
||||
export class AssetService {
|
||||
|
|
@ -53,8 +54,6 @@ export class AssetService {
|
|||
}
|
||||
|
||||
public async getAllAssets(authUser: AuthUserDto, query: GetAllAssetQueryDto): Promise<GetAllAssetReponseDto> {
|
||||
// Each page will take 100 images.
|
||||
|
||||
try {
|
||||
const assets = await this.assetRepository
|
||||
.createQueryBuilder('a')
|
||||
|
|
@ -63,7 +62,7 @@ export class AssetService {
|
|||
lastQueryCreatedAt: query.nextPageKey || new Date().toISOString(),
|
||||
})
|
||||
.orderBy('a."createdAt"::date', 'DESC')
|
||||
// .take(500)
|
||||
.take(5000)
|
||||
.getMany();
|
||||
|
||||
if (assets.length > 0) {
|
||||
|
|
@ -102,4 +101,16 @@ export class AssetService {
|
|||
|
||||
return rows[0] as AssetEntity;
|
||||
}
|
||||
|
||||
public async getNewAssets(authUser: AuthUserDto, latestDate: string) {
|
||||
return await this.assetRepository.find({
|
||||
where: {
|
||||
userId: authUser.id,
|
||||
createdAt: MoreThan(latestDate),
|
||||
},
|
||||
order: {
|
||||
createdAt: 'ASC', // ASC order to add existed asset the latest group first before creating a new date group.
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
class GetAssetDto {
|
||||
export class GetAssetDto {
|
||||
@IsNotEmpty()
|
||||
deviceId: string;
|
||||
}
|
||||
|
|
|
|||
6
server/src/api-v1/asset/dto/get-new-asset-query.dto.ts
Normal file
6
server/src/api-v1/asset/dto/get-new-asset-query.dto.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class GetNewAssetQueryDto {
|
||||
@IsNotEmpty()
|
||||
latestDate: string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue