Add cross-platform path handling (#89)

Add cross-platform path handling support

- Add sanitizePath, joinPath, buildOutputPath utilities
- Add operatingSystem to Settings interface
- Replace hardcoded Windows paths with dynamic path handling
- Support Windows, Linux, and macOS
This commit is contained in:
Ahmed Alghafri
2025-11-21 20:36:25 -07:00
committed by GitHub
parent bb9e2dcbb6
commit a49bb560bd
3 changed files with 51 additions and 18 deletions
+29
View File
@@ -1,6 +1,35 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
import type { Settings } from "./settings";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function sanitizePath(input: string, os: string): string {
if (os === "Windows") {
return input.replace(/[<>:"/\\|?*]/g, "_");
}
// unix-based OS
return input.replace(/\//g, "_");
}
export function joinPath(os: string, ...parts: string[]): string {
const sep = os === "Windows" ? "\\" : "/";
return parts
.filter(Boolean)
.map(p => p.replace(/^[/\\]+|[/\\]+$/g, ""))
.join(sep);
}
export function buildOutputPath(settings: Settings, folder?: string) {
const os = settings.operatingSystem;
const base = settings.downloadPath || "";
const sanitized = folder ? sanitizePath(folder, os) : undefined;
return sanitized ? joinPath(os, base, sanitized) : base;
}