(auth: AuthDto, response: Writable, dto: SyncStreamDto)
| 130 | } |
| 131 | |
| 132 | async stream(auth: AuthDto, response: Writable, dto: SyncStreamDto) { |
| 133 | const session = auth.session; |
| 134 | if (!session) { |
| 135 | return throwSessionRequired(); |
| 136 | } |
| 137 | |
| 138 | if (dto.reset) { |
| 139 | await this.sessionRepository.resetSyncProgress(session.id); |
| 140 | } |
| 141 | |
| 142 | const isPendingSyncReset = await this.sessionRepository.isPendingSyncReset(session.id); |
| 143 | if (isPendingSyncReset) { |
| 144 | send(response, { type: SyncEntityType.SyncResetV1, ids: ['reset'], data: {} }); |
| 145 | response.end(); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | const checkpoints = await this.syncCheckpointRepository.getAll(session.id); |
| 150 | const checkpointMap: CheckpointMap = Object.fromEntries(checkpoints.map(({ type, ack }) => [type, fromAck(ack)])); |
| 151 | |
| 152 | if (this.needsFullSync(checkpointMap)) { |
| 153 | send(response, { type: SyncEntityType.SyncResetV1, ids: ['reset'], data: {} }); |
| 154 | response.end(); |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | const { nowId } = await this.syncCheckpointRepository.getNow(); |
| 159 | const options: SyncQueryOptions = { nowId, userId: auth.user.id }; |
| 160 | |
| 161 | const handlers: Record<SyncRequestType, () => Promise<void>> = { |
| 162 | // deprecated handlers |
| 163 | [SyncRequestType.AssetsV1]: () => this.syncAssetsV1(), |
| 164 | [SyncRequestType.AssetFacesV1]: () => this.syncAssetFacesV1(), |
| 165 | [SyncRequestType.PartnerAssetsV1]: () => this.syncPartnerAssetsV1(), |
| 166 | [SyncRequestType.AlbumAssetsV1]: () => this.syncAlbumAssetsV1(), |
| 167 | |
| 168 | [SyncRequestType.AuthUsersV1]: () => this.syncAuthUsersV1(options, response, checkpointMap), |
| 169 | [SyncRequestType.UsersV1]: () => this.syncUsersV1(options, response, checkpointMap), |
| 170 | [SyncRequestType.PartnersV1]: () => this.syncPartnersV1(options, response, checkpointMap), |
| 171 | [SyncRequestType.AssetsV2]: () => this.syncAssetsV2(options, response, checkpointMap), |
| 172 | [SyncRequestType.AssetExifsV1]: () => this.syncAssetExifsV1(options, response, checkpointMap), |
| 173 | [SyncRequestType.AssetEditsV1]: () => this.syncAssetEditsV1(options, response, checkpointMap), |
| 174 | [SyncRequestType.PartnerAssetsV2]: () => this.syncPartnerAssetsV2(options, response, checkpointMap, session.id), |
| 175 | [SyncRequestType.AssetMetadataV1]: () => this.syncAssetMetadataV1(options, response, checkpointMap, auth), |
| 176 | [SyncRequestType.PartnerAssetExifsV1]: () => |
| 177 | this.syncPartnerAssetExifsV1(options, response, checkpointMap, session.id), |
| 178 | [SyncRequestType.AlbumsV1]: () => this.syncAlbumsV1(options, response, checkpointMap), |
| 179 | [SyncRequestType.AlbumsV2]: () => this.syncAlbumsV2(options, response, checkpointMap), |
| 180 | [SyncRequestType.AlbumUsersV1]: () => this.syncAlbumUsersV1(options, response, checkpointMap, session.id), |
| 181 | [SyncRequestType.AlbumAssetsV2]: () => this.syncAlbumAssetsV2(options, response, checkpointMap, session.id), |
| 182 | [SyncRequestType.AlbumToAssetsV1]: () => this.syncAlbumToAssetsV1(options, response, checkpointMap, session.id), |
| 183 | [SyncRequestType.AlbumAssetExifsV1]: () => |
| 184 | this.syncAlbumAssetExifsV1(options, response, checkpointMap, session.id), |
| 185 | [SyncRequestType.MemoriesV1]: () => this.syncMemoriesV1(options, response, checkpointMap), |
| 186 | [SyncRequestType.MemoryToAssetsV1]: () => this.syncMemoryAssetsV1(options, response, checkpointMap), |
| 187 | [SyncRequestType.StacksV1]: () => this.syncStackV1(options, response, checkpointMap), |
| 188 | [SyncRequestType.PartnerStacksV1]: () => this.syncPartnerStackV1(options, response, checkpointMap, session.id), |
| 189 | [SyncRequestType.PeopleV1]: () => this.syncPeopleV1(options, response, checkpointMap), |
no test coverage detected