UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.66 kB
import{s as relativePathEscapesRoot}from"./path-guards-DGttsOJI.mjs";import{i as realpathViaExistingPrefix}from"./path-containment-Drv7Ulmz.mjs";import{t as hasHttpUrlPrefix}from"./url-protocol-BLfSvQhh.mjs";import{n as normalizeMediaReferenceSource,r as parseInboundMediaUri,t as MediaReferenceError}from"./inbound-media-uri-COqbYFEq.mjs";import{t as getMediaDir}from"./store-path-CwOJyIi3.mjs";import{n as maybeLocalPathFromSource}from"./inbound-media-path-7gWp5rZS.mjs";import{u as resolveMediaBufferPath}from"./store-wPqhY4JR.mjs";import path from"node:path"; //!src/media/media-reference.ts function classifyMediaReferenceSource(e,t){const n=t?.allowDataUrl??true;const r=/^[a-zA-Z]:[\\/]/.test(e);const i=/^[a-z][a-z0-9+.-]*:/i.test(e);const a=/^file:/i.test(e);const o=hasHttpUrlPrefix(e);const s=/^data:/i.test(e);const c=/^media:\/\//i.test(e);return{hasUnsupportedScheme:i&&!r&&!a&&!o&&!c&&!(n&&s),isDataUrl:s,isFileUrl:a,isHttpUrl:o,isMediaStoreUrl:c,looksLikeWindowsDrivePath:r}}function resolveMediaReferenceSandboxPath(e,t=`media/inbound`){const n=normalizeMediaReferenceSource(e);const r=parseInboundMediaUri(n);if(!r)return{resolved:n};return{resolved:path.posix.join(t.replace(/\\/g,`/`),r.id),rewrittenFrom:r.normalizedSource}}async function resolveInboundMediaReference(e){const t=normalizeMediaReferenceSource(e);if(!t)return null;const n=parseInboundMediaUri(t);if(n)return{id:n.id,physicalPath:await resolveInboundMediaPath(n.id,n.normalizedSource)};const r=maybeLocalPathFromSource(t);if(!r)return null;const i=path.resolve(getMediaDir(),`inbound`);const a=path.resolve(r);const o=path.relative(i,a);let s=o;if(!o||relativePathEscapesRoot(o)){const[e,t]=await Promise.all([realpathViaExistingPrefix(i),realpathViaExistingPrefix(r)]);if(!e||!t)return null;s=path.relative(e,t)}if(!s||relativePathEscapesRoot(s)||s.includes(path.sep))return null;return{id:s,physicalPath:await resolveInboundMediaPath(s,t)}}async function resolveMediaReferenceLocalPathInfo(e){const t=normalizeMediaReferenceSource(e);const n=await resolveInboundMediaReference(t);return n?{kind:`inbound`,path:n.physicalPath}:{kind:`local`,path:t}}async function resolveMediaReferenceLocalPath(e){return(await resolveMediaReferenceLocalPathInfo(e)).path}async function resolveInboundMediaPath(e,t){try{return await resolveMediaBufferPath(e,`inbound`)}catch(e){throw new MediaReferenceError(`invalid-path`,e instanceof Error?e.message:`Invalid media reference: ${t}`,{cause:e})}}export{resolveMediaReferenceSandboxPath as a,resolveMediaReferenceLocalPathInfo as i,resolveInboundMediaReference as n,resolveMediaReferenceLocalPath as r,classifyMediaReferenceSource as t};