( table: 'remoteNote' | 'remoteTemplate', isCreate: boolean, remoteIdByLocal: Map< readonly [NoteId, RemoteTemplateId] | readonly [TemplateId, NookId], readonly [RemoteNoteId | RemoteTemplateId, Array<[Base64, RemoteMediaId]>] >, )
| 230 | ) |
| 231 | } |
| 232 | export async function updateRemotes( |
| 233 | table: 'remoteNote' | 'remoteTemplate', |
| 234 | isCreate: boolean, |
| 235 | remoteIdByLocal: Map< |
| 236 | readonly [NoteId, RemoteTemplateId] | readonly [TemplateId, NookId], |
| 237 | readonly [RemoteNoteId | RemoteTemplateId, Array<[Base64, RemoteMediaId]>] |
| 238 | >, |
| 239 | ) { |
| 240 | const now = C.getDate().getTime() |
| 241 | await tx(async (db) => { |
| 242 | for (const [ |
| 243 | [entityId, nOrT], |
| 244 | [remoteId, hashAndRemoteMediaIds], |
| 245 | ] of remoteIdByLocal) { |
| 246 | const entityDbId = toLDbId(entityId) |
| 247 | const r = await db |
| 248 | .updateTable(table) |
| 249 | .$if(table === 'remoteTemplate' && nOrT !== nullNook, (eb) => |
| 250 | eb |
| 251 | .set({ remoteId: toLDbId(remoteId), uploadDate: now }) |
| 252 | .where('nook', '=', nOrT as NookId), |
| 253 | ) |
| 254 | .$if(table === 'remoteTemplate' && nOrT === nullNook, (eb) => |
| 255 | eb |
| 256 | .set({ uploadDate: now }) // |
| 257 | .where('remoteId', '=', toLDbId(remoteId)), |
| 258 | ) |
| 259 | .$if(table === 'remoteNote', (eb) => |
| 260 | eb |
| 261 | .set({ |
| 262 | remoteId: isCreate ? toLDbId(remoteId) : undefined, |
| 263 | uploadDate: now, |
| 264 | }) |
| 265 | .where((eb) => |
| 266 | eb.exists( |
| 267 | eb |
| 268 | .selectFrom('remoteNote') |
| 269 | .select(sql`1`.as('_')) |
| 270 | .innerJoin('note', 'note.id', 'remoteNote.localId') |
| 271 | .innerJoin( |
| 272 | 'remoteTemplate', |
| 273 | 'remoteTemplate.localId', |
| 274 | 'note.templateId', |
| 275 | ) |
| 276 | .where( |
| 277 | 'remoteTemplate.remoteId', |
| 278 | '=', |
| 279 | toLDbId(nOrT as RemoteTemplateId), |
| 280 | ) |
| 281 | .where('remoteNote.localId', '=', entityDbId), |
| 282 | ), |
| 283 | ), |
| 284 | ) |
| 285 | .where('localId', '=', entityDbId) |
| 286 | .returningAll() |
| 287 | .execute() |
| 288 | for (const [hash, remoteMediaId] of hashAndRemoteMediaIds) { |
| 289 | await db |
nothing calls this directly
no test coverage detected