mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 22:30:21 +00:00
fix(whatsapp): add HTML/XML/CSS to MIME map + fallback for unknown media types (#51562)
Merged via squash.
Prepared head SHA: 83f2eabd49
Co-authored-by: bobbyt74 <262672147+bobbyt74@users.noreply.github.com>
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Reviewed-by: @mcaxtr
This commit is contained in:
@@ -88,6 +88,28 @@ describe("mime detection", () => {
|
||||
expected,
|
||||
});
|
||||
});
|
||||
|
||||
it("detects HTML files by extension (no magic bytes)", async () => {
|
||||
const buf = Buffer.from("<!DOCTYPE html><html><body>test</body></html>");
|
||||
const mime = await detectMime({ buffer: buf, filePath: "/tmp/report.html" });
|
||||
expect(mime).toBe("text/html");
|
||||
});
|
||||
|
||||
it("detects .htm files by extension", async () => {
|
||||
const buf = Buffer.from("<html><body>test</body></html>");
|
||||
const mime = await detectMime({ buffer: buf, filePath: "/tmp/page.htm" });
|
||||
expect(mime).toBe("text/html");
|
||||
});
|
||||
|
||||
it("detects XML files by extension", async () => {
|
||||
const mime = await detectMime({ filePath: "/tmp/data.xml" });
|
||||
expect(mime).toBe("text/xml");
|
||||
});
|
||||
|
||||
it("detects CSS files by extension", async () => {
|
||||
const mime = await detectMime({ filePath: "/tmp/style.css" });
|
||||
expect(mime).toBe("text/css");
|
||||
});
|
||||
});
|
||||
|
||||
describe("extensionForMime", () => {
|
||||
@@ -113,6 +135,10 @@ describe("extensionForMime", () => {
|
||||
{ mime: "application/pdf", expected: ".pdf" },
|
||||
{ mime: "text/plain", expected: ".txt" },
|
||||
{ mime: "text/markdown", expected: ".md" },
|
||||
{ mime: "text/html", expected: ".html" },
|
||||
{ mime: "text/xml", expected: ".xml" },
|
||||
{ mime: "text/css", expected: ".css" },
|
||||
{ mime: "application/xml", expected: ".xml" },
|
||||
{ mime: "IMAGE/JPEG", expected: ".jpg" },
|
||||
{ mime: "Audio/X-M4A", expected: ".m4a" },
|
||||
{ mime: "Video/QuickTime", expected: ".mov" },
|
||||
|
||||
@@ -36,6 +36,10 @@ const EXT_BY_MIME: Record<string, string> = {
|
||||
"text/csv": ".csv",
|
||||
"text/plain": ".txt",
|
||||
"text/markdown": ".md",
|
||||
"text/html": ".html",
|
||||
"text/xml": ".xml",
|
||||
"text/css": ".css",
|
||||
"application/xml": ".xml",
|
||||
};
|
||||
|
||||
const MIME_BY_EXT: Record<string, string> = {
|
||||
@@ -43,6 +47,8 @@ const MIME_BY_EXT: Record<string, string> = {
|
||||
// Additional extension aliases
|
||||
".jpeg": "image/jpeg",
|
||||
".js": "text/javascript",
|
||||
".htm": "text/html",
|
||||
".xml": "text/xml", // pin text/xml as canonical (application/xml also maps to .xml in EXT_BY_MIME)
|
||||
};
|
||||
|
||||
const AUDIO_FILE_EXTENSIONS = new Set([
|
||||
|
||||
Reference in New Issue
Block a user