The oneDrivePathResolver.js utility centralizes all OneDrive path resolution logic into reusable functions.
Usage
Basic Resolution
const{ resolveOneDriveDestinationPath,}=require("./utils/oneDrivePathResolver");// For folder operationsconst result =awaitresolveOneDriveDestinationPath({destPath:"3EC4DC457B29B213!sd0d5f4f552b94e23bd77deb55fd7c165",destRemote:"onedrive-account",config: rcloneConfig,folderName:"new-folder",// OptionalisFileOperation:false,});console.log(result.resolvedPath);// 'resolved/path/new-folder'console.log(result.wasResolved);// trueconsole.log(result.originalPath);// '3EC4DC457B29B213!sd0d5f4f552b94e23bd77deb55fd7c165'
File Operations
// For file operationsconst result =awaitresolveOneDriveDestinationPath({destPath:"3EC4DC457B29B213!sd0d5f4f552b94e23bd77deb55fd7c165",destRemote:"onedrive-account",config: rcloneConfig,fileName:"document.pdf",// OptionalisFileOperation:true,});
The Dropbox Path Resolver provides utilities for converting Dropbox folder IDs to paths for rclone operations.
Basic Usage
const{ resolveDropboxDestinationPath,}=require("./utils/dropboxPathResolver");// For folder operationsconst result =awaitresolveDropboxDestinationPath({destPath:"id:2V5kn5RRfnAAAAAAAADjCA",destRemote:"dropbox-account",config: rcloneConfig,folderName:"new-folder",// OptionalisFileOperation:false,});console.log(result.resolvedPath);// '/google to dropbox/new-folder'console.log(result.wasResolved);// trueconsole.log(result.originalPath);// 'id:2V5kn5RRfnAAAAAAAADjCA'
File Operations
// For file operationsconst result =awaitresolveDropboxDestinationPath({destPath:"id:2V5kn5RRfnAAAAAAAADjCA",destRemote:"dropbox-account",config: rcloneConfig,fileName:"document.pdf",// OptionalisFileOperation:true,});
Simplified version for basic Dropbox resolution without additional handling.
Returns:Promise<string> - The resolved path
needsDropboxResolution(destPath, destRemote)
Checks if Dropbox path resolution is needed. Returns true for Dropbox file IDs and for "root" paths (which need to be converted to empty strings for Dropbox).
Returns:boolean - Whether resolution is needed
isDropboxFileId(path)
Checks if a path is a Dropbox folder ID.
Returns:boolean - Whether the path is a Dropbox folder ID
convertDropboxIdToPath(dropboxId, accessToken)
Converts a Dropbox folder ID to a path using the Dropbox API.
Returns:Promise<string> - The resolved folder path
Error Handling
The utility throws descriptive errors when:
Access token cannot be extracted from config.
OneDrive API calls fail.
Invalid folder IDs are provided.
Testing
Run tests with:
npmtest -- oneDrivePathResolver.test.js
Migration Guide
Before (Duplicated Logic)
// In multiple filesif( destRemote.startsWith("onedrive")&& destPath && destPath !=="root"&&isOneDriveFileId(destPath)){const decodedDestPath =decodeURIComponent(destPath);const accessToken =extractAccessTokenFromConfig(config, destRemote);// ... more logic}
After (Using Utility)
// Single line replacementif(destRemote.startsWith("onedrive")){const oneDriveResult =awaitresolveOneDriveDestinationPath({ destPath, destRemote, config, folderName,// if applicableisFileOperation:false,}); resolvedDestPath = oneDriveResult.resolvedPath;}
Benefits
DRY Principle: Eliminates code duplication
Consistent Behavior: Same logic across all operations
Better Error Handling: Centralized error messages
Easier Testing: Single place to test resolution logic
Maintainability: Updates only need to be made in one place