mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:31:22 +00:00
fix(slack): override video/* MIME to audio/* for voice messages (#14941)
* fix(slack): override video/* MIME to audio/* for voice messages * fix(slack): preserve overridden MIME in return value * test(slack): fix media monitor MIME mock wiring --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -238,6 +238,80 @@ describe("resolveSlackMedia", () => {
|
||||
expect(mockFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("overrides video/* MIME to audio/* for slack_audio voice messages", async () => {
|
||||
// saveMediaBuffer re-detects MIME from buffer bytes, so it may return
|
||||
// video/mp4 for MP4 containers. Verify resolveSlackMedia preserves
|
||||
// the overridden audio/* type in its return value despite this.
|
||||
const saveMediaBufferMock = vi.spyOn(mediaStore, "saveMediaBuffer").mockResolvedValue({
|
||||
path: "/tmp/voice.mp4",
|
||||
contentType: "video/mp4",
|
||||
});
|
||||
|
||||
const mockResponse = new Response(Buffer.from("audio data"), {
|
||||
status: 200,
|
||||
headers: { "content-type": "video/mp4" },
|
||||
});
|
||||
mockFetch.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await resolveSlackMedia({
|
||||
files: [
|
||||
{
|
||||
url_private: "https://files.slack.com/voice.mp4",
|
||||
name: "audio_message.mp4",
|
||||
mimetype: "video/mp4",
|
||||
subtype: "slack_audio",
|
||||
},
|
||||
],
|
||||
token: "xoxb-test-token",
|
||||
maxBytes: 16 * 1024 * 1024,
|
||||
});
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
// saveMediaBuffer should receive the overridden audio/mp4
|
||||
expect(saveMediaBufferMock).toHaveBeenCalledWith(
|
||||
expect.any(Buffer),
|
||||
"audio/mp4",
|
||||
"inbound",
|
||||
16 * 1024 * 1024,
|
||||
);
|
||||
// Returned contentType must be the overridden value, not the
|
||||
// re-detected video/mp4 from saveMediaBuffer
|
||||
expect(result!.contentType).toBe("audio/mp4");
|
||||
});
|
||||
|
||||
it("preserves original MIME for non-voice Slack files", async () => {
|
||||
const saveMediaBufferMock = vi.spyOn(mediaStore, "saveMediaBuffer").mockResolvedValue({
|
||||
path: "/tmp/video.mp4",
|
||||
contentType: "video/mp4",
|
||||
});
|
||||
|
||||
const mockResponse = new Response(Buffer.from("video data"), {
|
||||
status: 200,
|
||||
headers: { "content-type": "video/mp4" },
|
||||
});
|
||||
mockFetch.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await resolveSlackMedia({
|
||||
files: [
|
||||
{
|
||||
url_private: "https://files.slack.com/clip.mp4",
|
||||
name: "recording.mp4",
|
||||
mimetype: "video/mp4",
|
||||
},
|
||||
],
|
||||
token: "xoxb-test-token",
|
||||
maxBytes: 16 * 1024 * 1024,
|
||||
});
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(saveMediaBufferMock).toHaveBeenCalledWith(
|
||||
expect.any(Buffer),
|
||||
"video/mp4",
|
||||
"inbound",
|
||||
16 * 1024 * 1024,
|
||||
);
|
||||
});
|
||||
|
||||
it("falls through to next file when first file returns error", async () => {
|
||||
vi.spyOn(mediaStore, "saveMediaBuffer").mockResolvedValue({
|
||||
path: "/tmp/test.jpg",
|
||||
|
||||
Reference in New Issue
Block a user