mirror of
https://github.com/immich-app/immich.git
synced 2025-03-11 02:23:09 -05:00
add mock endpoint
This commit is contained in:
parent
002ef492f8
commit
1a06de01b7
4 changed files with 51 additions and 2 deletions
|
@ -29,8 +29,12 @@ class SyncApiRepository extends ApiRepository implements ISyncApiRepository {
|
|||
final client = http.Client();
|
||||
|
||||
try {
|
||||
final request = http.Request('GET', url);
|
||||
final request = http.Request('POST', url);
|
||||
request.headers['x-immich-user-token'] = accessToken;
|
||||
final payload = {
|
||||
'types': ["asset"],
|
||||
};
|
||||
request.body = jsonEncode(payload);
|
||||
final response = await client.send(request);
|
||||
|
||||
// Read and print the chunks from the response stream
|
||||
|
|
|
@ -5778,6 +5778,20 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"/sync": {
|
||||
"post": {
|
||||
"operationId": "sync",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Sync"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/sync/delta-sync": {
|
||||
"post": {
|
||||
"operationId": "getDeltaSync",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Body, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Header, HttpCode, HttpStatus, Post, Res } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Response } from 'express';
|
||||
import { AssetResponseDto } from 'src/dtos/asset-response.dto';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import { AssetDeltaSyncDto, AssetDeltaSyncResponseDto, AssetFullSyncDto } from 'src/dtos/sync.dto';
|
||||
|
@ -24,4 +25,14 @@ export class SyncController {
|
|||
getDeltaSync(@Auth() auth: AuthDto, @Body() dto: AssetDeltaSyncDto): Promise<AssetDeltaSyncResponseDto> {
|
||||
return this.service.getDeltaSync(auth, dto);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Header('Content-Type', 'application/jsonlines+json')
|
||||
sync(@Res() res: Response) {
|
||||
try {
|
||||
this.service.sync(res);
|
||||
} catch {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { DateTime } from 'luxon';
|
||||
import { Writable } from 'node:stream';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
import { AUDIT_LOG_MAX_DURATION } from 'src/constants';
|
||||
import { AssetResponseDto, mapAsset } from 'src/dtos/asset-response.dto';
|
||||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
|
@ -11,6 +13,24 @@ import { setIsEqual } from 'src/utils/set';
|
|||
const FULL_SYNC = { needsFullSync: true, deleted: [], upserted: [] };
|
||||
|
||||
export class SyncService extends BaseService {
|
||||
sync(stream: Writable) {
|
||||
void this.streamWrites(stream);
|
||||
}
|
||||
|
||||
async streamWrites(stream: Writable) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const delay = 100;
|
||||
|
||||
console.log(`waiting ${delay}ms`);
|
||||
|
||||
await setTimeout(delay);
|
||||
|
||||
stream.write(JSON.stringify({ id: i, type: 'Test' }) + '\n');
|
||||
}
|
||||
|
||||
stream.end();
|
||||
}
|
||||
|
||||
async getFullSync(auth: AuthDto, dto: AssetFullSyncDto): Promise<AssetResponseDto[]> {
|
||||
// mobile implementation is faster if this is a single id
|
||||
const userId = dto.userId || auth.user.id;
|
||||
|
|
Loading…
Add table
Reference in a new issue