* Sync Word document content to server
( projectId: string, adapter: ReturnType<typeof useAdapter>, options?: SyncOptions, )
| 88 | * Sync Word document content to server |
| 89 | */ |
| 90 | async function syncWordDocument( |
| 91 | projectId: string, |
| 92 | adapter: ReturnType<typeof useAdapter>, |
| 93 | options?: SyncOptions, |
| 94 | ): Promise<SyncResult> { |
| 95 | logInfo(`[Word Sync] Starting sync for project: ${projectId}`); |
| 96 | options?.onProgress?.(10); |
| 97 | |
| 98 | // Get full document content |
| 99 | const fullText = await adapter.getFullText(); |
| 100 | options?.onProgress?.(50); |
| 101 | |
| 102 | // Create project snapshot with single document |
| 103 | const projectSnapshot: PlainMessage<UpsertProjectRequest> = { |
| 104 | projectId, |
| 105 | name: "Word Document", // Word documents don't have a project name concept |
| 106 | rootDocId: "main", |
| 107 | docs: [ |
| 108 | { |
| 109 | id: "main", |
| 110 | version: Math.floor(Date.now() / 1000), // Use seconds timestamp (int32 safe) |
| 111 | filepath: "document.docx", |
| 112 | lines: fullText.split("\n"), |
| 113 | } as PlainMessage<ProjectDoc>, |
| 114 | ], |
| 115 | }; |
| 116 | options?.onProgress?.(70); |
| 117 | |
| 118 | // Upload to server |
| 119 | try { |
| 120 | await upsertProject(projectSnapshot); |
| 121 | options?.onProgress?.(100); |
| 122 | logInfo("[Word Sync] Successfully synced document to server"); |
| 123 | return { success: true }; |
| 124 | } catch (error) { |
| 125 | logError("[Word Sync] Failed to save project snapshot:", error); |
| 126 | return { success: false, error: error as Error }; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Generic document sync for other platforms |
no test coverage detected