MCPcopy Create free account
hub / github.com/VirtualHotBar/NetMount / sync

Function sync

src/controller/storage/storage.ts:477–526  ·  view source on GitHub ↗
(
  storageName: string,
  path: string,
  destStoragename: string,
  destPath: string,
  bisync?: boolean
)

Source from the content-addressed store, hash-verified

475
476//sync,需完整path(pathF2f)
477async function sync(
478 storageName: string,
479 path: string,
480 destStoragename: string,
481 destPath: string,
482 bisync?: boolean
483) {
484 //bisync:双向同步
485
486 // 参数验证
487 if (!storageName || !destStoragename) {
488 throw new Error('Source or destination storage name is empty')
489 }
490 if (!path || !destPath) {
491 throw new Error('Source or destination path is empty')
492 }
493
494 let success: boolean
495 if (!bisync) {
496 const srcFs = convertStoragePath(storageName, path, true)
497 const dstFs = convertStoragePath(destStoragename, destPath, true)
498
499 if (!srcFs || !dstFs) {
500 throw new Error('Invalid source or destination path')
501 }
502
503 success = await rclone_api_exec_async('/sync/sync', {
504 srcFs,
505 dstFs,
506 })
507 if (!success) {
508 throw new Error(`Sync failed: ${srcFs} -> ${dstFs}`)
509 }
510 } else {
511 const path1 = convertStoragePath(storageName, path, true)
512 const path2 = convertStoragePath(destStoragename, destPath, true)
513
514 if (!path1 || !path2) {
515 throw new Error('Invalid source or destination path')
516 }
517
518 success = await rclone_api_exec_async('/sync/bisync', {
519 path1,
520 path2,
521 })
522 if (!success) {
523 throw new Error(`Bidirectional sync failed: ${path1} <-> ${path2}`)
524 }
525 }
526}
527
528const uploadFileRequest = (option: RequestOptions, storageName: string, path: string) => {
529 const { onProgress, onError, onSuccess, file } = option

Callers 1

executeTaskFunction · 0.90

Calls 2

rclone_api_exec_asyncFunction · 0.90
convertStoragePathFunction · 0.85

Tested by

no test coverage detected