openclaw-channel-dmwork 0.4.0 → 0.4.2
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/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/api-fetch.ts +1 -1
- package/src/channel.ts +22 -1
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
package/src/api-fetch.ts
CHANGED
|
@@ -56,7 +56,7 @@ export async function uploadFile(params: {
|
|
|
56
56
|
contentType: string;
|
|
57
57
|
signal?: AbortSignal;
|
|
58
58
|
}): Promise<{ url: string }> {
|
|
59
|
-
const url = `${params.apiUrl.replace(/\/+$/, "")}/v1/bot/upload`;
|
|
59
|
+
const url = `${params.apiUrl.replace(/\/+$/, "")}/v1/bot/file/upload`;
|
|
60
60
|
const formData = new FormData();
|
|
61
61
|
const blob = new Blob([new Uint8Array(params.fileBuffer)], { type: params.contentType });
|
|
62
62
|
formData.append("file", blob, params.filename);
|
package/src/channel.ts
CHANGED
|
@@ -263,7 +263,28 @@ export const dmworkPlugin: ChannelPlugin<ResolvedDmworkAccount> = {
|
|
|
263
263
|
let contentType: string | undefined;
|
|
264
264
|
let filename: string;
|
|
265
265
|
|
|
266
|
-
if (mediaUrl.startsWith("
|
|
266
|
+
if (mediaUrl.startsWith("data:")) {
|
|
267
|
+
// Parse data URI: data:[<mediatype>][;base64],<data>
|
|
268
|
+
const match = mediaUrl.match(/^data:([^;,]+)?(?:;base64)?,(.*)$/);
|
|
269
|
+
if (!match) {
|
|
270
|
+
throw new Error("Invalid data URI format");
|
|
271
|
+
}
|
|
272
|
+
contentType = match[1] || "application/octet-stream";
|
|
273
|
+
fileBuffer = Buffer.from(match[2], "base64");
|
|
274
|
+
// Generate a reasonable filename from MIME type
|
|
275
|
+
const extMap: Record<string, string> = {
|
|
276
|
+
"text/markdown": ".md", "text/plain": ".txt", "application/pdf": ".pdf",
|
|
277
|
+
"image/png": ".png", "image/jpeg": ".jpg", "image/gif": ".gif", "image/webp": ".webp",
|
|
278
|
+
"application/json": ".json", "application/zip": ".zip",
|
|
279
|
+
"audio/mpeg": ".mp3", "video/mp4": ".mp4",
|
|
280
|
+
};
|
|
281
|
+
const ext = extMap[contentType] || ".bin";
|
|
282
|
+
filename = `file${ext}`;
|
|
283
|
+
// If OpenClaw provides a filename hint via ctx, prefer it
|
|
284
|
+
if ((ctx as Record<string, unknown>).filename) {
|
|
285
|
+
filename = String((ctx as Record<string, unknown>).filename);
|
|
286
|
+
}
|
|
287
|
+
} else if (mediaUrl.startsWith("file://")) {
|
|
267
288
|
const filePath = decodeURIComponent(mediaUrl.slice(7));
|
|
268
289
|
fileBuffer = await readFile(filePath);
|
|
269
290
|
filename = path.basename(filePath);
|