Download src/lib/dataPaths.ts from shimen/shinroute: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/shimen/shinroute/resolve/main/src/lib/dataPaths.ts
- Command line
-
hf download hf://spaces/shimen/shinroute/src/lib/dataPaths.ts
-
curl -L -o dataPaths.ts https://huggingface.co/spaces/shimen/shinroute/resolve/main/src/lib/dataPaths.ts
1.48 kB
| import path from "node:path"; | |
| import os from "node:os"; | |
| export const APP_NAME = "omniroute"; | |
| function safeHomeDir() { | |
| try { | |
| return os.homedir(); | |
| } catch { | |
| return process.cwd(); | |
| } | |
| } | |
| function normalizeConfiguredPath(dir) { | |
| if (typeof dir !== "string") return null; | |
| const trimmed = dir.trim(); | |
| if (!trimmed) return null; | |
| return path.resolve(trimmed); | |
| } | |
| export function getLegacyDotDataDir() { | |
| return path.join(safeHomeDir(), `.${APP_NAME}`); | |
| } | |
| export function getDefaultDataDir() { | |
| const homeDir = safeHomeDir(); | |
| if (process.platform === "win32") { | |
| const appData = process.env.APPDATA || path.join(homeDir, "AppData", "Roaming"); | |
| return path.join(appData, APP_NAME); | |
| } | |
| // Support XDG on Linux/macOS when explicitly configured. | |
| const xdgConfigHome = normalizeConfiguredPath(process.env.XDG_CONFIG_HOME); | |
| if (xdgConfigHome) { | |
| return path.join(xdgConfigHome, APP_NAME); | |
| } | |
| return getLegacyDotDataDir(); | |
| } | |
| export function resolveDataDir({ isCloud = false } = {}) { | |
| if (isCloud) return "/tmp"; | |
| const configured = normalizeConfiguredPath(process.env.DATA_DIR); | |
| if (configured) return configured; | |
| return getDefaultDataDir(); | |
| } | |
| export function isSamePath(a, b) { | |
| if (!a || !b) return false; | |
| const normalizedA = path.resolve(a); | |
| const normalizedB = path.resolve(b); | |
| if (process.platform === "win32") { | |
| return normalizedA.toLowerCase() === normalizedB.toLowerCase(); | |
| } | |
| return normalizedA === normalizedB; | |
| } | |