refactor(restic): split each command into its own file refactor: add missing await before promise expects <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Tests** * Improved async assertion handling across test suites for enhanced test reliability * Expanded test coverage for backup, restore, and other core operations * **Refactor** * Reorganized internal utility structure for improved code maintainability * **Chores** * Updated linting configuration and TypeScript dependencies <!-- end of auto-generated comment: release notes by coderabbit.ai -->
34 lines
973 B
TypeScript
34 lines
973 B
TypeScript
import type { RepositoryConfig } from "~/schemas/restic";
|
|
|
|
export const buildRepoUrl = (config: RepositoryConfig): string => {
|
|
switch (config.backend) {
|
|
case "local":
|
|
return config.path;
|
|
case "s3": {
|
|
const endpoint = config.endpoint.trim().replace(/\/$/, "");
|
|
return `s3:${endpoint}/${config.bucket}`;
|
|
}
|
|
case "r2": {
|
|
const endpoint = config.endpoint
|
|
.trim()
|
|
.replace(/^https?:\/\//, "")
|
|
.replace(/\/$/, "");
|
|
return `s3:${endpoint}/${config.bucket}`;
|
|
}
|
|
case "gcs":
|
|
return `gs:${config.bucket}:/`;
|
|
case "azure":
|
|
return `azure:${config.container}:/`;
|
|
case "rclone":
|
|
return `rclone:${config.remote}:${config.path}`;
|
|
case "rest": {
|
|
const pathSuffix = config.path ? `/${config.path}` : "";
|
|
return `rest:${config.url}${pathSuffix}`;
|
|
}
|
|
case "sftp":
|
|
return `sftp:${config.user}@${config.host}:${config.path}`;
|
|
default: {
|
|
throw new Error(`Unsupported repository backend: ${JSON.stringify(config)}`);
|
|
}
|
|
}
|
|
};
|