UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

33 lines (32 loc) • 1.23 kB
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs"; import { s as relativePathEscapesRoot } from "./path-guards-TIjxtj6H.mjs"; import { r as parseInboundMediaUri } from "./inbound-media-uri-DpK4_BLW.mjs"; import { t as getMediaDir } from "./store-path-D4uVfy73.mjs"; import path from "node:path"; import { safeFileURLToPath } from "@openclaw/fs-safe/advanced"; //#region src/media/inbound-media-path.ts function maybeLocalPathFromSource(e) { if (/^file:/i.test(e)) try { return safeFileURLToPath(e); } catch { return null; } if (e.startsWith("~")) return resolveUserPath(e); if (path.isAbsolute(e)) return e; return null; } /** Converts a managed inbound path to a URI without exposing paths outside its store. */ function buildInboundMediaUriFromPath(e) { const t = maybeLocalPathFromSource(e.trim()); if (!t) return; const n = path.resolve(getMediaDir(), "inbound"); const r = path.relative(n, path.resolve(t)); if (!r || relativePathEscapesRoot(r) || r.includes(path.sep) || r.includes("\\")) return; try { return parseInboundMediaUri(`media://inbound/${r}`)?.normalizedSource; } catch { return; } } //#endregion export { maybeLocalPathFromSource as n, buildInboundMediaUriFromPath as t };