Skip to content

Commit 981da82

Browse files
committed
fix(clickclack): preserve MIME extension for unnamed uploads
1 parent 36ee98d commit 981da82

2 files changed

Lines changed: 86 additions & 3 deletions

File tree

‎extensions/clickclack/src/outbound.test.ts‎

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ describe("sendClickClackMedia", () => {
221221
});
222222

223223
it("preserves filename and MIME while uploading before channel delivery", async () => {
224+
loadOutboundMediaFromUrl.mockResolvedValueOnce({
225+
buffer: Buffer.from("const proof = true;"),
226+
contentType: "image/png",
227+
fileName: "viewer-proof.ts",
228+
});
224229
const order: string[] = [];
225230
createUpload.mockImplementationOnce(async () => {
226231
order.push("upload");
@@ -254,7 +259,7 @@ describe("sendClickClackMedia", () => {
254259
workspaceId: "wsp_1",
255260
buffer: Buffer.from("const proof = true;"),
256261
filename: "viewer-proof.ts",
257-
contentType: "text/typescript",
262+
contentType: "image/png",
258263
});
259264
expect(createChannelMessage).toHaveBeenCalledWith(
260265
"general",
@@ -266,6 +271,83 @@ describe("sendClickClackMedia", () => {
266271
expect(messageId).toBe("msg_out");
267272
});
268273

274+
it("derives an extension from the MIME type when media has no filename", async () => {
275+
loadOutboundMediaFromUrl.mockResolvedValueOnce({
276+
buffer: Buffer.from("fake png bytes"),
277+
contentType: "image/png",
278+
});
279+
280+
await sendClickClackMedia({
281+
cfg,
282+
to: "channel:general",
283+
text: "",
284+
mediaUrl: "https://files.example/unnamed",
285+
});
286+
287+
expect(createUpload).toHaveBeenCalledWith({
288+
workspaceId: "wsp_1",
289+
buffer: Buffer.from("fake png bytes"),
290+
filename: "attachment.png",
291+
contentType: "image/png",
292+
});
293+
expect(createChannelMessage).toHaveBeenCalledWith(
294+
"general",
295+
"attachment.png",
296+
expect.objectContaining({ quotedMessageId: undefined }),
297+
);
298+
});
299+
300+
it("keeps the generic fallback when MIME type has no known extension", async () => {
301+
loadOutboundMediaFromUrl.mockResolvedValueOnce({
302+
buffer: Buffer.from("unknown bytes"),
303+
contentType: "application/x-unknown",
304+
});
305+
306+
await sendClickClackMedia({
307+
cfg,
308+
to: "channel:general",
309+
text: "",
310+
mediaUrl: "https://files.example/unknown",
311+
});
312+
313+
expect(createUpload).toHaveBeenCalledWith({
314+
workspaceId: "wsp_1",
315+
buffer: Buffer.from("unknown bytes"),
316+
filename: "attachment",
317+
contentType: "application/x-unknown",
318+
});
319+
expect(createChannelMessage).toHaveBeenCalledWith(
320+
"general",
321+
"attachment",
322+
expect.objectContaining({ quotedMessageId: undefined }),
323+
);
324+
});
325+
326+
it("keeps the generic fallback when MIME type is missing", async () => {
327+
loadOutboundMediaFromUrl.mockResolvedValueOnce({
328+
buffer: Buffer.from("opaque bytes"),
329+
});
330+
331+
await sendClickClackMedia({
332+
cfg,
333+
to: "channel:general",
334+
text: "",
335+
mediaUrl: "https://files.example/missing-type",
336+
});
337+
338+
expect(createUpload).toHaveBeenCalledWith({
339+
workspaceId: "wsp_1",
340+
buffer: Buffer.from("opaque bytes"),
341+
filename: "attachment",
342+
contentType: "application/octet-stream",
343+
});
344+
expect(createChannelMessage).toHaveBeenCalledWith(
345+
"general",
346+
"attachment",
347+
expect.objectContaining({ quotedMessageId: undefined }),
348+
);
349+
});
350+
269351
it("uses the filename as the minimal media-only body and routes DMs", async () => {
270352
const messageId = await sendClickClackMedia({
271353
cfg,

‎extensions/clickclack/src/outbound.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type ChannelMessageUnknownSendContext,
99
type ChannelMessageUnknownSendReconciliationResult,
1010
} from "openclaw/plugin-sdk/channel-outbound";
11+
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
1112
import {
1213
loadOutboundMediaFromUrl,
1314
type OutboundMediaLoadOptions,
@@ -263,9 +264,9 @@ export async function sendClickClackMedia(params: {
263264
mediaLocalRoots: params.mediaLocalRoots,
264265
mediaReadFile: params.mediaReadFile,
265266
}));
266-
const filename = media.fileName?.trim() || "attachment";
267-
mediaFilename = filename;
268267
const contentType = media.contentType?.trim() || "application/octet-stream";
268+
const filename = media.fileName?.trim() || `attachment${extensionForMime(contentType) ?? ""}`;
269+
mediaFilename = filename;
269270
await dispatch();
270271
upload = await client.createUpload({
271272
workspaceId,

0 commit comments

Comments
 (0)