( backend: ISyncBackend, )
| 576 | } |
| 577 | |
| 578 | async function listRemoteDeviceFiles( |
| 579 | backend: ISyncBackend, |
| 580 | ): Promise<{ deviceId: string; path: string }[]> { |
| 581 | const deviceFilesById = new Map<string, { deviceId: string; path: string }>(); |
| 582 | const index = await loadDeviceSyncIndex(backend); |
| 583 | if (index) { |
| 584 | for (const [deviceId, entry] of Object.entries(index.devices)) { |
| 585 | if (!entry?.path) continue; |
| 586 | deviceFilesById.set(deviceId, { deviceId, path: entry.path }); |
| 587 | } |
| 588 | console.log( |
| 589 | `[SimpleSync] Remote device index listed ${deviceFilesById.size} device snapshot candidate(s)`, |
| 590 | ); |
| 591 | } |
| 592 | |
| 593 | try { |
| 594 | const files = await backend.listDir(SYNC_DIR); |
| 595 | const deviceFiles = files |
| 596 | .filter((f) => !f.isDirectory && f.name.startsWith("device-") && f.name.endsWith(".json")) |
| 597 | .map((f) => ({ |
| 598 | deviceId: f.name.replace(/^device-/, "").replace(/\.json$/, ""), |
| 599 | path: f.path || `${SYNC_DIR}/${f.name}`, |
| 600 | })); |
| 601 | for (const file of deviceFiles) { |
| 602 | deviceFilesById.set(file.deviceId, file); |
| 603 | } |
| 604 | |
| 605 | console.log( |
| 606 | `[SimpleSync] Remote sync dir listed ${files.length} item(s), ${deviceFiles.length} device snapshot candidate(s)`, |
| 607 | ); |
| 608 | } catch (error) { |
| 609 | console.warn( |
| 610 | `[SimpleSync] Failed to list remote device snapshots: ${error instanceof Error ? error.message : String(error)}`, |
| 611 | ); |
| 612 | } |
| 613 | |
| 614 | return [...deviceFilesById.values()]; |
| 615 | } |
| 616 | |
| 617 | async function saveDeviceSnapshot( |
| 618 | backend: ISyncBackend, |
no test coverage detected