openclaw-channel-dmwork 0.5.10 → 0.5.11

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,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-channel-dmwork",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "description": "DMWork channel plugin for OpenClaw via WuKongIM WebSocket",
5
5
  "main": "index.ts",
6
6
  "type": "module",
@@ -716,3 +716,81 @@ describe("sendMediaMessage", () => {
716
716
  expect(payload.height).toBeUndefined();
717
717
  });
718
718
  });
719
+
720
+ // ---------------------------------------------------------------------------
721
+ // ensureTextCharset
722
+ // ---------------------------------------------------------------------------
723
+ describe("ensureTextCharset", () => {
724
+ it("appends charset=utf-8 to text/plain", async () => {
725
+ const { ensureTextCharset } = await import("./api-fetch.js");
726
+ expect(ensureTextCharset("text/plain")).toBe("text/plain; charset=utf-8");
727
+ });
728
+
729
+ it("appends charset=utf-8 to text/markdown", async () => {
730
+ const { ensureTextCharset } = await import("./api-fetch.js");
731
+ expect(ensureTextCharset("text/markdown")).toBe("text/markdown; charset=utf-8");
732
+ });
733
+
734
+ it("appends charset=utf-8 to text/html", async () => {
735
+ const { ensureTextCharset } = await import("./api-fetch.js");
736
+ expect(ensureTextCharset("text/html")).toBe("text/html; charset=utf-8");
737
+ });
738
+
739
+ it("does not modify image/jpeg", async () => {
740
+ const { ensureTextCharset } = await import("./api-fetch.js");
741
+ expect(ensureTextCharset("image/jpeg")).toBe("image/jpeg");
742
+ });
743
+
744
+ it("does not double-add charset if already present", async () => {
745
+ const { ensureTextCharset } = await import("./api-fetch.js");
746
+ expect(ensureTextCharset("text/plain; charset=utf-8")).toBe("text/plain; charset=utf-8");
747
+ });
748
+
749
+ it("does not override existing charset=gbk", async () => {
750
+ const { ensureTextCharset } = await import("./api-fetch.js");
751
+ expect(ensureTextCharset("text/plain; charset=gbk")).toBe("text/plain; charset=gbk");
752
+ });
753
+
754
+ it("does not modify application/json", async () => {
755
+ const { ensureTextCharset } = await import("./api-fetch.js");
756
+ expect(ensureTextCharset("application/json")).toBe("application/json");
757
+ });
758
+ });
759
+
760
+ // ---------------------------------------------------------------------------
761
+ // uploadFileToCOS — putParams includes ContentType
762
+ // ---------------------------------------------------------------------------
763
+ describe("uploadFileToCOS putParams ContentType", () => {
764
+ it("passes ContentType to cos.putObject", async () => {
765
+ let capturedParams: any = null;
766
+
767
+ vi.resetModules();
768
+
769
+ // Mock cos-nodejs-sdk-v5 before importing api-fetch
770
+ vi.doMock("cos-nodejs-sdk-v5", () => {
771
+ return {
772
+ default: class FakeCOS {
773
+ putObject(params: any, cb: any) {
774
+ capturedParams = params;
775
+ cb(null, { Location: "bucket.cos.region.myqcloud.com/key" });
776
+ }
777
+ },
778
+ };
779
+ });
780
+
781
+ const { uploadFileToCOS } = await import("./api-fetch.js");
782
+ await uploadFileToCOS({
783
+ credentials: { tmpSecretId: "id", tmpSecretKey: "key", sessionToken: "tok" },
784
+ startTime: 0,
785
+ expiredTime: 9999999999,
786
+ bucket: "test-bucket",
787
+ region: "ap-test",
788
+ key: "test/file.txt",
789
+ fileBody: Buffer.from("hello"),
790
+ contentType: "text/plain; charset=utf-8",
791
+ });
792
+
793
+ expect(capturedParams).not.toBeNull();
794
+ expect(capturedParams.ContentType).toBe("text/plain; charset=utf-8");
795
+ });
796
+ });
package/src/api-fetch.ts CHANGED
@@ -114,11 +114,25 @@ export function inferContentType(filename: string): string {
114
114
  ".pdf": "application/pdf", ".zip": "application/zip",
115
115
  ".doc": "application/msword", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
116
116
  ".xls": "application/vnd.ms-excel", ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
117
- ".txt": "text/plain", ".json": "application/json",
117
+ ".txt": "text/plain", ".md": "text/markdown", ".markdown": "text/markdown",
118
+ ".csv": "text/csv", ".html": "text/html", ".htm": "text/html",
119
+ ".css": "text/css", ".xml": "text/xml", ".yaml": "text/yaml", ".yml": "text/yaml",
120
+ ".json": "application/json",
118
121
  };
119
122
  return map[ext] ?? "application/octet-stream";
120
123
  }
121
124
 
125
+ /**
126
+ * Ensure text/* content types include a charset parameter.
127
+ * If the content type starts with "text/" and has no charset, appends "; charset=utf-8".
128
+ */
129
+ export function ensureTextCharset(contentType: string): string {
130
+ if (contentType.startsWith("text/") && !contentType.includes("charset")) {
131
+ return contentType + "; charset=utf-8";
132
+ }
133
+ return contentType;
134
+ }
135
+
122
136
  /**
123
137
  * Parse image dimensions from buffer (PNG/JPEG/GIF/WebP).
124
138
  * Lightweight — reads only the header bytes, no external dependencies.
@@ -577,6 +591,7 @@ export async function uploadFileToCOS(params: {
577
591
  Region: params.region,
578
592
  Key: params.key,
579
593
  Body: params.fileBody,
594
+ ContentType: params.contentType,
580
595
  };
581
596
  if (params.fileSize != null) {
582
597
  putParams.ContentLength = params.fileSize;
package/src/channel.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  resolveDmworkAccount,
12
12
  type ResolvedDmworkAccount,
13
13
  } from "./accounts.js";
14
- import { registerBot, sendMessage, sendHeartbeat, sendMediaMessage, inferContentType, fetchBotGroups, getGroupMd, parseImageDimensions, parseImageDimensionsFromFile, getUploadCredentials, uploadFileToCOS } from "./api-fetch.js";
14
+ import { registerBot, sendMessage, sendHeartbeat, sendMediaMessage, inferContentType, ensureTextCharset, fetchBotGroups, getGroupMd, parseImageDimensions, parseImageDimensionsFromFile, getUploadCredentials, uploadFileToCOS } from "./api-fetch.js";
15
15
  import { WKSocket } from "./socket.js";
16
16
  import { handleInboundMessage, type DmworkStatusSink } from "./inbound.js";
17
17
  import { ChannelType, MessageType, type BotMessage, type MessagePayload } from "./types.js";
@@ -445,7 +445,7 @@ export const dmworkPlugin: ChannelPlugin<ResolvedDmworkAccount> = {
445
445
  tempPath = dl.tempPath;
446
446
  localFilePath = dl.tempPath;
447
447
  contentType = dl.contentType;
448
- if (!contentType) contentType = inferContentType(filename);
448
+ if (!contentType || contentType === "application/octet-stream") contentType = inferContentType(filename);
449
449
  const st = statSync(tempPath);
450
450
  fileBody = createReadStream(tempPath);
451
451
  fileSize = st.size;
@@ -469,7 +469,7 @@ export const dmworkPlugin: ChannelPlugin<ResolvedDmworkAccount> = {
469
469
  key: creds.key,
470
470
  fileBody,
471
471
  fileSize,
472
- contentType,
472
+ contentType: ensureTextCharset(contentType),
473
473
  cdnBaseUrl: creds.cdnBaseUrl,
474
474
  });
475
475
 
package/src/inbound.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ChannelLogSink, OpenClawConfig } from "openclaw/plugin-sdk";
2
- import { sendMessage, sendReadReceipt, sendTyping, getChannelMessages, getGroupMembers, getGroupMd, postJson, sendMediaMessage, inferContentType, parseImageDimensions, parseImageDimensionsFromFile, getUploadCredentials, uploadFileToCOS } from "./api-fetch.js";
2
+ import { sendMessage, sendReadReceipt, sendTyping, getChannelMessages, getGroupMembers, getGroupMd, postJson, sendMediaMessage, inferContentType, ensureTextCharset, parseImageDimensions, parseImageDimensionsFromFile, getUploadCredentials, uploadFileToCOS } from "./api-fetch.js";
3
3
  import type { ResolvedDmworkAccount } from "./accounts.js";
4
4
  import type { BotMessage } from "./types.js";
5
5
  import { ChannelType, MessageType } from "./types.js";
@@ -160,7 +160,7 @@ export async function uploadAndSendMedia(params: {
160
160
  key: creds.key,
161
161
  fileBody,
162
162
  fileSize,
163
- contentType,
163
+ contentType: ensureTextCharset(contentType),
164
164
  cdnBaseUrl: creds.cdnBaseUrl,
165
165
  });
166
166