| 78 | logDir, |
| 79 | enablePersistedEvents: options.enablePersistedEvents || false, |
| 80 | enableConsoleLog: options.enableConsoleLog || false, |
| 81 | enableMetrics: options.enableMetrics || false, |
| 82 | logLevel, |
| 83 | credentialsStore: parseCredentialsStore(process.env.PROTON_DRIVE_CREDENTIALS_STORE), |
| 84 | unsafeCache: parseBooleanEnv(process.env.PROTON_DRIVE_UNSAFE_CACHE), |
| 85 | }; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Derives the account URL from the API base URL by swapping the `drive-api` host label for `account`, |
| 90 | * e.g. `drive-api.houssay.proton.black` into `account.houssay.proton.black`. |
| 91 | * Falls back to `account.proton.black`/`account.proton.me` when the base URL doesn't follow that pattern. |
| 92 | */ |
| 93 | function accountUrlFromBaseUrl(baseUrl: string): string { |
| 94 | if (baseUrl.startsWith('drive-api.')) { |
| 95 | return baseUrl.replace(/^drive-api\./, 'account.'); |
| 96 | } |
| 97 | return baseUrl.endsWith('.black') ? 'account.proton.black' : 'account.proton.me'; |
| 98 | } |
| 99 | |
| 100 | function defaultDataDirs(): Pick<Config, 'cacheDir' | 'appDir' | 'logDir'> { |
| 101 | const home = homedir(); |
| 102 | const override = process.env.PROTON_DRIVE_CACHE_DIR; |
| 103 | if (override) { |
| 104 | return { cacheDir: override, appDir: override, logDir: override }; |
| 105 | } |
| 106 | |
| 107 | if (process.platform === 'darwin') { |
| 108 | return { |
| 109 | cacheDir: path.join(home, 'Library', 'Caches', APP_DIR_NAME), |
| 110 | appDir: path.join(home, 'Library', 'Application Support', APP_DIR_NAME), |
| 111 | logDir: path.join(home, 'Library', 'Logs', APP_DIR_NAME), |
| 112 | }; |
| 113 | } |
| 114 | |
| 115 | if (process.platform === 'win32') { |
| 116 | const localAppData = process.env.LOCALAPPDATA || path.join(home, 'AppData', 'Local'); |