const fs = require("fs"); const path = require("path"); const ROOT = path.resolve(__dirname, ".."); const DATA = path.join(ROOT, "data"); function ensureDataDirs() { for (const name of ["logs", "models", "runtime", "tmp"]) fs.mkdirSync(path.join(DATA, name), { recursive: true }); } function dataPath(...parts) { const target = path.resolve(DATA, ...parts); if (target !== DATA && !target.startsWith(`${DATA}${path.sep}`)) throw new Error("Path escapes transcription plugin data."); return target; } function resolveWorkerExecutable(override = "") { const requested = String(override || "").trim(); if (requested) return fs.existsSync(requested) ? path.resolve(requested) : requested; const executable = process.platform === "win32" ? "lumi-whisper-worker.exe" : "lumi-whisper-worker"; const candidates = [ dataPath("runtime", "worker", process.platform === "win32" ? "windows-x64-cuda" : `${process.platform}-${process.arch}-cuda`, "bin", executable), dataPath("runtime", "worker", process.platform === "win32" ? "windows-x64-cpu" : `${process.platform}-${process.arch}`, "bin", executable), path.join(ROOT, "backend", "transcription", "worker-native", "build", executable) ]; return candidates.find((candidate) => fs.existsSync(candidate) && fs.statSync(candidate).isFile()) || ""; } module.exports = { ROOT, DATA, ensureDataDirs, dataPath, resolveWorkerExecutable };