fix: refine mime type checks and improve MediaInfoModal layout

Updated tests to check for mime types using `toStartWith` for better validation. Adjusted mime type patterns in DropzoneInner for XML handling. Modified MediaInfoModal to enhance layout responsiveness and broaden text format support for previews, ensuring better file handling and user experience.
This commit is contained in:
dswbx
2025-09-29 16:07:40 +02:00
parent d31416f85d
commit d1ba638cd5
4 changed files with 7 additions and 7 deletions

View File

@@ -104,7 +104,7 @@ describe("MediaController", () => {
body: file, body: file,
}); });
const result = (await res.json()) as any; const result = (await res.json()) as any;
expect(result.data.mime_type).toBe("audio/mpeg"); expect(result.data.mime_type).toStartWith("audio/mpeg");
expect(result.name).toBe(name); expect(result.name).toBe(name);
const destFile = Bun.file(assetsTmpPath + "/" + name); const destFile = Bun.file(assetsTmpPath + "/" + name);
@@ -121,7 +121,7 @@ describe("MediaController", () => {
body: file, body: file,
}); });
const result = (await res.json()) as any; const result = (await res.json()) as any;
expect(result.data.mime_type).toBe("text/plain"); expect(result.data.mime_type).toStartWith("text/plain");
expect(result.name).toBe(name); expect(result.name).toBe(name);
const destFile = Bun.file(assetsTmpPath + "/" + name); const destFile = Bun.file(assetsTmpPath + "/" + name);

View File

@@ -2,8 +2,8 @@ export const Q = {
video: ["mp4", "webm"], video: ["mp4", "webm"],
audio: ["ogg"], audio: ["ogg"],
image: ["jpeg", "png", "gif", "webp", "bmp", "tiff", "avif", "heic", "heif"], image: ["jpeg", "png", "gif", "webp", "bmp", "tiff", "avif", "heic", "heif"],
text: ["html", "css", "mdx", "yaml", "vcard", "csv", "vtt", "xml"], text: ["html", "css", "mdx", "yaml", "vcard", "csv", "vtt"],
application: ["zip", "toml", "json", "json5", "pdf", "sql"], application: ["zip", "toml", "json", "json5", "pdf", "xml"],
font: ["woff", "woff2", "ttf", "otf"], font: ["woff", "woff2", "ttf", "otf"],
} as const; } as const;

View File

@@ -296,7 +296,7 @@ const Previews = [
Icon: TbFileTypeCsv, Icon: TbFileTypeCsv,
}, },
{ {
mime: "text/xml", mime: /(text|application)\/xml/,
Icon: TbFileTypeXml, Icon: TbFileTypeXml,
}, },
{ {

View File

@@ -43,7 +43,7 @@ export function MediaInfoModal({
return ( return (
<div className="flex flex-col md:flex-row"> <div className="flex flex-col md:flex-row">
<div className="flex w-full md:w-[calc(100%-300px)] justify-center items-center bg-lightest min-w-0"> <div className="flex w-full md:w-[calc(100%-300px)] justify-center items-center bg-lightest min-w-50">
<FilePreview file={file} /> <FilePreview file={file} />
</div> </div>
<div className="w-full md:!w-[300px] flex flex-col"> <div className="w-full md:!w-[300px] flex flex-col">
@@ -156,7 +156,7 @@ const Item = ({
); );
}; };
const textFormats = [/^text\/.*$/, /application\/(json|ld\+json|javascript|xml|rtf|sql)/]; const textFormats = [/^text\/.*$/, /application\/(x\-)?(json|json|yaml|javascript|xml|rtf|sql)/];
const FilePreview = ({ file }: { file: FileState }) => { const FilePreview = ({ file }: { file: FileState }) => {
const objectUrl = typeof file.body === "string" ? file.body : URL.createObjectURL(file.body); const objectUrl = typeof file.body === "string" ? file.body : URL.createObjectURL(file.body);