MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / syncWordDocument

Function syncWordDocument

webapp/_webapp/src/hooks/useSync.ts:90–128  ·  view source on GitHub ↗

* Sync Word document content to server

(
  projectId: string,
  adapter: ReturnType<typeof useAdapter>,
  options?: SyncOptions,
)

Source from the content-addressed store, hash-verified

88 * Sync Word document content to server
89 */
90async 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

Callers 1

useSyncFunction · 0.85

Calls 4

logInfoFunction · 0.90
upsertProjectFunction · 0.90
logErrorFunction · 0.90
getFullTextMethod · 0.65

Tested by

no test coverage detected