This module provides a comprehensive, unified interface for all rclone-related functionality including file transfers, file ID resolution, configuration management, and React hooks.
The unified rclone transfer service provides a single interface for all file and folder transfers using the existing rclone + Fly.io infrastructure. It includes proper TypeScript interfaces, error handling, and progress tracking callbacks.
Features
Single File Transfer: Transfer individual files between cloud services.
Folder Transfer: Transfer entire folders with structure preservation.
Batch Transfer: Transfer multiple files in a single batch operation.
Progress Tracking: Real-time progress updates with callbacks.
Error Handling: Comprehensive error handling with typed error codes.
Cancellation: Cancel individual operations or all active transfers.
Status Monitoring: Get real-time status of transfer operations.
Automatic File Filtering: Skips files that cannot be properly transferred by rclone.
File Filtering
The transfer service automatically filters out files that rclone cannot properly transfer between cloud storage services. This includes:
For batch transfers, filtered files are skipped and reported in the result. For single file transfers, an error is thrown if the file cannot be transferred.
See src/config/transfer-filters.ts for the complete list of filter rules.
import{ batchTransferFiles }from"~/lib/transfer/rclone-transfer-service";const result =awaitbatchTransferFiles({ operations:[{ sourceService:"google", sourceAccountId:"default", sourceFileId:"file1", destService:"onedrive", destAccountId:"default", destFolderId:"root",},{ sourceService:"google", sourceAccountId:"default", sourceFileId:"file2", destService:"onedrive", destAccountId:"default", destFolderId:"root",},]},{onStart:(metadata)=>console.log(`Operation ${metadata.data?.batchIndex} started`),onProgress:(metadata)=>console.log(`Operation ${metadata.operationId} progress: ${metadata.progress?.percentage}%`),onComplete:(metadata)=>console.log(`Operation ${metadata.operationId} completed`),});// Check for skipped files in batch transfersif(result.skippedFiles&& result.skippedFiles.length>0){console.log(`${result.skippedFiles.length} files were skipped:`); result.skippedFiles.forEach(file =>{console.log(`- ${file.fileName}: ${file.skipReason}`);});}
Using the Service Class Directly
import{RcloneTransferService}from"~/lib/rclone";// Create a custom service instance with different configurationconst transferService =newRcloneTransferService({ defaultPollInterval:1000,// Poll every second maxRetries:5, retryDelay:2000, timeout:60000,});// Use the serviceconst result =await transferService.transferFile(request, callbacks);// Get all active transfersconst activeTransfers = transferService.getActiveTransfers();// Cancel all transfersawait transferService.cancelAllTransfers();// Clean up when donetransferService.dispose();
Monitoring Transfer Status
import{ getTransferStatus, getActiveTransfers }from"~/lib/rclone";// Get status of a specific transferconst status =awaitgetTransferStatus("operation-id");if(status){console.log(`Status: ${status.status}, Progress: ${status.progress?.percentage}%`);}// Get all active transfersconst activeTransfers =getActiveTransfers();console.log(`${activeTransfers.length} transfers in progress`);
Cancelling Transfers
import{ cancelTransfer, cancelAllTransfers }from"~/lib/rclone";// Cancel a specific transferconst cancelled =awaitcancelTransfer("operation-id");// Cancel all active transfersconst allCancelled =awaitcancelAllTransfers();