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

Function syncGenericDocument

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

* Generic document sync for other platforms

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

Source from the content-addressed store, hash-verified

131 * Generic document sync for other platforms
132 */
133async function syncGenericDocument(
134 projectId: string,
135 adapter: ReturnType<typeof useAdapter>,
136 options?: SyncOptions,
137): Promise<SyncResult> {
138 logInfo(`[Generic Sync] Starting sync for project: ${projectId}`);
139 options?.onProgress?.(10);
140
141 try {
142 const fullText = await adapter.getFullText();
143 options?.onProgress?.(50);
144
145 const projectSnapshot: PlainMessage<UpsertProjectRequest> = {
146 projectId,
147 name: "Document",
148 rootDocId: "main",
149 docs: [
150 {
151 id: "main",
152 version: Math.floor(Date.now() / 1000),
153 filepath: "document.txt",
154 lines: fullText.split("\n"),
155 } as PlainMessage<ProjectDoc>,
156 ],
157 };
158 options?.onProgress?.(70);
159
160 await upsertProject(projectSnapshot);
161 options?.onProgress?.(100);
162 logInfo("[Generic Sync] Successfully synced document to server");
163 return { success: true };
164 } catch (error) {
165 logError("[Generic Sync] Failed to sync:", error);
166 return { success: false, error: error as Error };
167 }
168}

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