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 -->
25 lines
638 B
TypeScript
25 lines
638 B
TypeScript
import type { BandwidthLimit } from "~/schemas/restic";
|
|
|
|
export const formatBandwidthLimit = (limit?: BandwidthLimit): string => {
|
|
if (!limit || !limit.enabled || limit.value <= 0) {
|
|
return "";
|
|
}
|
|
|
|
let kibibytesPerSecond: number;
|
|
switch (limit.unit) {
|
|
case "Kbps":
|
|
kibibytesPerSecond = (limit.value * 1000) / 8 / 1024;
|
|
break;
|
|
case "Mbps":
|
|
kibibytesPerSecond = (limit.value * 1000000) / (8 * 1024);
|
|
break;
|
|
case "Gbps":
|
|
kibibytesPerSecond = (limit.value * 1000000000) / (8 * 1024);
|
|
break;
|
|
default:
|
|
return "";
|
|
}
|
|
|
|
const limitValue = Math.max(1, Math.floor(kibibytesPerSecond));
|
|
return `${limitValue}`;
|
|
};
|