MCPcopy Create free account
hub / github.com/ZToolsCenter/ZTools / forceDownloadFromCloud

Method forceDownloadFromCloud

src/main/core/sync/syncEngine.ts:179–273  ·  view source on GitHub ↗

* 强制从云端下载所有数据到本地(覆盖本地数据)

()

Source from the content-addressed store, hash-verified

177 * 强制从云端下载所有数据到本地(覆盖本地数据)
178 */
179 async forceDownloadFromCloud(): Promise<SyncResult> {
180 console.log('[Sync] 开始强制从云端同步到本地...')
181
182 try {
183 // 获取云端所有文件列表
184 const remoteFiles = await this.webdavClient.listRemoteDocsWithMeta()
185
186 if (remoteFiles.length === 0) {
187 console.log('[Sync] 云端没有数据')
188 return { uploaded: 0, downloaded: 0, conflicts: 0, errors: 0 }
189 }
190
191 console.log(`[Sync] 云端共有 ${remoteFiles.length} 个文档需要下载`)
192
193 let downloaded = 0
194 let errors = 0
195
196 for (const file of remoteFiles) {
197 try {
198 const remoteDoc = await this.webdavClient.downloadDoc(file.docId)
199 if (!remoteDoc) {
200 console.warn(`[Sync] 无法下载文档: ${file.docId}`)
201 errors++
202 continue
203 }
204
205 // 强制覆盖本地数据(不检查冲突)
206 remoteDoc._cloudSynced = true
207 await this.updateDocSyncStatus(file.docId, remoteDoc, true)
208
209 downloaded++
210 console.log(`[Sync] 强制下载成功: ${file.docId}`)
211 } catch (error) {
212 console.error(`[Sync] 强制下载失败: ${file.docId}`, error)
213 errors++
214 }
215 }
216
217 // 如果启用了插件同步,强制从远端下载所有插件
218 let pluginsDownloaded = 0
219 const config = await this.loadSyncConfig()
220 if (config?.syncPlugins) {
221 try {
222 pluginSyncWatcher.pause()
223 const remoteManifest = await this.webdavClient.downloadPluginManifest()
224 const hashRecords = loadHashRecords()
225
226 for (const [pluginName, entry] of Object.entries(remoteManifest)) {
227 try {
228 console.log(`[Sync] 强制下载插件: ${pluginName}`)
229 const zipBuffer = await this.webdavClient.downloadPluginZip(pluginName)
230 if (!zipBuffer) {
231 console.warn(`[Sync] 远端插件 zip 不存在: ${pluginName}`)
232 continue
233 }
234
235 await this.installPluginFromSyncZip(pluginName, zipBuffer)
236

Callers 1

setupIPCMethod · 0.80

Calls 12

updateDocSyncStatusMethod · 0.95
loadSyncConfigMethod · 0.95
updateLastSyncTimeMethod · 0.95
loadHashRecordsFunction · 0.90
saveHashRecordsFunction · 0.90
downloadDocMethod · 0.80
pauseMethod · 0.80
downloadPluginZipMethod · 0.80
resumeMethod · 0.80

Tested by

no test coverage detected