mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 11:31:26 +00:00
fix: correct camera snap mime mapping
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import JSZip from "jszip";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { detectMime } from "./mime.js";
|
||||
import { detectMime, imageMimeFromFormat } from "./mime.js";
|
||||
|
||||
async function makeOoxmlZip(opts: {
|
||||
mainMime: string;
|
||||
@@ -17,6 +17,15 @@ async function makeOoxmlZip(opts: {
|
||||
}
|
||||
|
||||
describe("mime detection", () => {
|
||||
it("maps common image formats to mime types", () => {
|
||||
expect(imageMimeFromFormat("jpg")).toBe("image/jpeg");
|
||||
expect(imageMimeFromFormat("jpeg")).toBe("image/jpeg");
|
||||
expect(imageMimeFromFormat("png")).toBe("image/png");
|
||||
expect(imageMimeFromFormat("webp")).toBe("image/webp");
|
||||
expect(imageMimeFromFormat("gif")).toBe("image/gif");
|
||||
expect(imageMimeFromFormat("unknown")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects docx from buffer", async () => {
|
||||
const buf = await makeOoxmlZip({
|
||||
mainMime:
|
||||
|
||||
@@ -107,6 +107,25 @@ export function extensionForMime(mime?: string | null): string | undefined {
|
||||
return EXT_BY_MIME[mime.toLowerCase()];
|
||||
}
|
||||
|
||||
export function imageMimeFromFormat(
|
||||
format?: string | null,
|
||||
): string | undefined {
|
||||
if (!format) return undefined;
|
||||
switch (format.toLowerCase()) {
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
return "image/jpeg";
|
||||
case "png":
|
||||
return "image/png";
|
||||
case "webp":
|
||||
return "image/webp";
|
||||
case "gif":
|
||||
return "image/gif";
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function kindFromMime(mime?: string | null): MediaKind {
|
||||
return mediaKindFromMime(mime);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user