diff --git a/src/generators/rclone-conf.ts b/src/generators/rclone-conf.ts new file mode 100644 index 0000000..efcc72a --- /dev/null +++ b/src/generators/rclone-conf.ts @@ -0,0 +1,31 @@ +// src/generators/rclone-conf.ts +// Pure function: converts WizardState into a valid rclone.conf INI string. +// SECURITY: No logging — state contains credentials. Do NOT add console.log here. + +import type { WizardState } from '../store/types'; + +// Maps our BackendType to rclone's internal type string. +// IMPORTANT: s3-compatible uses 'type = s3' — rclone does not recognize 's3-compatible' as a type. +// S3-compatible backends are differentiated by provider = Other in params. +const RCLONE_TYPE_MAP: Record = { + azureblob: 'azureblob', + s3: 's3', + 's3-compatible': 's3', +}; + +export function buildRcloneConf(state: WizardState): string { + const { name, backendType, params } = state.remote; + if (!backendType) throw new Error('buildRcloneConf: backendType is required'); + if (!name) throw new Error('buildRcloneConf: remote name is required'); + + const rcloneType = RCLONE_TYPE_MAP[backendType]; + const lines: string[] = [`[${name}]`, `type = ${rcloneType}`]; + + for (const [key, value] of Object.entries(params)) { + if (value !== '') { + lines.push(`${key} = ${value}`); + } + } + + return lines.join('\n') + '\n'; +}