feat(02-02): implement buildRcloneConf pure function
- Maps BackendType to rclone INI type strings via RCLONE_TYPE_MAP - s3-compatible correctly maps to type = s3 (not s3-compatible) - Omits empty param values from output (no 'sas_url =' when blank) - Throws on null backendType or empty remote name - All 17 rclone-conf.test.ts assertions pass GREEN
This commit is contained in:
@@ -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<string, string> = {
|
||||||
|
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';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user