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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "openclaw-channel-dmwork",
2
+ "id": "dmwork",
3
3
  "channels": [
4
4
  "dmwork"
5
5
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-channel-dmwork",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "DMWork channel plugin for OpenClaw via WuKongIM WebSocket",
5
5
  "main": "index.ts",
6
6
  "type": "module",
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("file://")) {
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);