mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
fix(media): preserve outbound attachment filenames
This commit is contained in:
39
src/media/outbound-attachment.test.ts
Normal file
39
src/media/outbound-attachment.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const loadWebMedia = vi.hoisted(() => vi.fn());
|
||||
const saveMediaBuffer = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("./web-media.js", () => ({
|
||||
loadWebMedia,
|
||||
}));
|
||||
|
||||
vi.mock("./store.js", () => ({
|
||||
saveMediaBuffer,
|
||||
}));
|
||||
|
||||
const { resolveOutboundAttachmentFromUrl } = await import("./outbound-attachment.js");
|
||||
|
||||
describe("resolveOutboundAttachmentFromUrl", () => {
|
||||
it("preserves the loaded file name when staging outbound media", async () => {
|
||||
const buffer = Buffer.from("pdf");
|
||||
loadWebMedia.mockResolvedValueOnce({
|
||||
buffer,
|
||||
contentType: "application/pdf",
|
||||
fileName: "report.pdf",
|
||||
});
|
||||
saveMediaBuffer.mockResolvedValueOnce({
|
||||
path: "/tmp/media/outbound/report---uuid.pdf",
|
||||
contentType: "application/pdf",
|
||||
});
|
||||
|
||||
await resolveOutboundAttachmentFromUrl("./report.pdf", 1024);
|
||||
|
||||
expect(saveMediaBuffer).toHaveBeenCalledWith(
|
||||
buffer,
|
||||
"application/pdf",
|
||||
"outbound",
|
||||
1024,
|
||||
"report.pdf",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -25,6 +25,7 @@ export async function resolveOutboundAttachmentFromUrl(
|
||||
media.contentType ?? undefined,
|
||||
"outbound",
|
||||
maxBytes,
|
||||
media.fileName,
|
||||
);
|
||||
return { path: saved.path, contentType: saved.contentType };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user