@xmoxmo/bncr 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
1
4
|
type RuntimeMediaLoaded = {
|
|
2
5
|
buffer: Buffer;
|
|
3
6
|
contentType?: string;
|
|
@@ -40,6 +43,23 @@ export function isOpenClawRemoteHttpMediaUrl(mediaUrl: string): boolean {
|
|
|
40
43
|
return /^https?:\/\//i.test(String(mediaUrl || '').trim());
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Try to resolve a relative media path against each local root.
|
|
48
|
+
* Returns the first absolute path that exists on disk, or the original
|
|
49
|
+
* relative path if nothing is found (the host will then emit its own error).
|
|
50
|
+
*/
|
|
51
|
+
export function resolveRelativeMediaPath(mediaUrl: string, localRoots?: readonly string[]): string {
|
|
52
|
+
if (!mediaUrl || !localRoots?.length) return mediaUrl;
|
|
53
|
+
if (path.isAbsolute(mediaUrl)) return mediaUrl;
|
|
54
|
+
// HTTP / file:// / data: / ~ paths are handled elsewhere
|
|
55
|
+
if (/^(https?|file|data):/i.test(mediaUrl) || mediaUrl.startsWith('~')) return mediaUrl;
|
|
56
|
+
for (const root of localRoots) {
|
|
57
|
+
const candidate = path.resolve(root, mediaUrl);
|
|
58
|
+
if (existsSync(candidate)) return candidate;
|
|
59
|
+
}
|
|
60
|
+
return mediaUrl;
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
export async function loadOpenClawWebMedia(
|
|
44
64
|
api: RuntimeApiHolder,
|
|
45
65
|
mediaUrl: string,
|
|
@@ -54,7 +74,11 @@ export async function loadOpenClawWebMedia(
|
|
|
54
74
|
if (typeof loadWebMedia !== 'function') {
|
|
55
75
|
throw new Error('OpenClaw runtime media loadWebMedia API is unavailable');
|
|
56
76
|
}
|
|
57
|
-
|
|
77
|
+
|
|
78
|
+
// Resolve relative paths against local roots before handing off to the host
|
|
79
|
+
const resolvedUrl = resolveRelativeMediaPath(mediaUrl, options?.localRoots);
|
|
80
|
+
|
|
81
|
+
return loadWebMedia(resolvedUrl, options);
|
|
58
82
|
}
|
|
59
83
|
|
|
60
84
|
export async function saveOpenClawChannelMediaBuffer(
|