mirror of
https://github.com/immich-app/immich.git
synced 2025-12-25 01:11:43 +03:00
feat: sync implementation for the user entity (#16234)
* ci: print out typeorm generation changes * feat: sync implementation for the user entity wip --------- Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
@@ -12,6 +12,7 @@ import { writeFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { SystemConfig } from 'src/config';
|
||||
import { CLIP_MODEL_INFO, serverVersion } from 'src/constants';
|
||||
import { extraSyncModels } from 'src/dtos/sync.dto';
|
||||
import { ImmichCookie, ImmichHeader, MetadataKey } from 'src/enum';
|
||||
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||
|
||||
@@ -245,6 +246,7 @@ export const useSwagger = (app: INestApplication, { write }: { write: boolean })
|
||||
|
||||
const options: SwaggerDocumentOptions = {
|
||||
operationIdFactory: (controllerKey: string, methodKey: string) => methodKey,
|
||||
extraModels: extraSyncModels,
|
||||
};
|
||||
|
||||
const specification = SwaggerModule.createDocument(app, config, options);
|
||||
|
||||
30
server/src/utils/sync.ts
Normal file
30
server/src/utils/sync.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { SyncItem } from 'src/dtos/sync.dto';
|
||||
import { SyncEntityType } from 'src/enum';
|
||||
import { SyncAck } from 'src/types';
|
||||
|
||||
type Impossible<K extends keyof any> = {
|
||||
[P in K]: never;
|
||||
};
|
||||
|
||||
type Exact<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
|
||||
|
||||
export const fromAck = (ack: string): SyncAck => {
|
||||
const [type, timestamp, ...ids] = ack.split('|');
|
||||
return { type: type as SyncEntityType, ackEpoch: timestamp, ids };
|
||||
};
|
||||
|
||||
export const toAck = ({ type, ackEpoch, ids }: SyncAck) => [type, ackEpoch, ...ids].join('|');
|
||||
|
||||
export const mapJsonLine = (object: unknown) => JSON.stringify(object) + '\n';
|
||||
|
||||
export const serialize = <T extends keyof SyncItem, D extends SyncItem[T]>({
|
||||
type,
|
||||
ackEpoch,
|
||||
ids,
|
||||
data,
|
||||
}: {
|
||||
type: T;
|
||||
ackEpoch: string;
|
||||
ids: string[];
|
||||
data: Exact<SyncItem[T], D>;
|
||||
}) => mapJsonLine({ type, data, ack: toAck({ type, ackEpoch, ids }) });
|
||||
Reference in New Issue
Block a user