MCPcopy
hub / github.com/codedogQBY/ReadAny / buildDownloadFileTask

Function buildDownloadFileTask

packages/core/src/sync/sync-files.ts:991–1019  ·  view source on GitHub ↗
(
  backend: ISyncBackend,
  info: BookInfo,
  setBookSyncStatus: (id: string, status: "local" | "remote") => Promise<void>,
)

Source from the content-addressed store, hash-verified

989}
990
991function buildDownloadFileTask(
992 backend: ISyncBackend,
993 info: BookInfo,
994 setBookSyncStatus: (id: string, status: "local" | "remote") => Promise<void>,
995): FileTask {
996 const bookTitle = info.book.title || "未知书籍";
997 return {
998 label: bookTitle,
999 run: async (onProgress) => {
1000 const taskStart = Date.now();
1001 try {
1002 console.log(`[Sync] 📥 Downloading book: ${bookTitle} ← ${info.remoteFilePath}`);
1003 const bytes = await downloadRemoteFileToPath(
1004 backend,
1005 info.remoteFilePath,
1006 info.localFilePath,
1007 onProgress,
1008 );
1009 await setBookSyncStatus(info.book.id, "local");
1010 const size = bytes === null ? "" : ` (${(bytes / 1024 / 1024).toFixed(2)} MB)`;
1011 console.log(`[Sync] ✓ Downloaded "${bookTitle}"${size} in ${Date.now() - taskStart}ms`);
1012 return true;
1013 } catch (e) {
1014 console.log(`[Sync] ✗ Failed to download "${bookTitle}": ${e}`);
1015 return false;
1016 }
1017 },
1018 };
1019}
1020
1021function buildUploadCoverTask(backend: ISyncBackend, info: BookInfo): FileTask {
1022 const bookTitle = info.book.title || "未知书籍";

Callers 1

syncFilesFunction · 0.85

Calls 2

downloadRemoteFileToPathFunction · 0.85
setBookSyncStatusFunction · 0.85

Tested by

no test coverage detected