tfrere's picture
tfrere HF Staff
refactor(backend): modular server split with new routes, persistence and agent layer
f6678ab
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const DEFAULT_DATA_DIR = join(__dirname, "..", "data");
let _dataDir: string | undefined;
/** Override DATA_DIR for testing. Pass undefined to reset to default. */
export function setDataDir(dir: string | undefined) {
_dataDir = dir;
}
export function getDataDir(): string {
return _dataDir ?? process.env.DATA_DIR ?? DEFAULT_DATA_DIR;
}
/** @deprecated Use getDataDir() instead */
export const DATA_DIR = DEFAULT_DATA_DIR;
export function sanitizeName(name: string): string {
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
}
export function docPath(name: string): string {
return join(getDataDir(), `${sanitizeName(name)}.yjs`);
}