mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Align attachment video detection with server
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
54c1ca5eec
commit
0da56d780f
2 changed files with 38 additions and 1 deletions
|
|
@ -207,6 +207,35 @@ describe("IssueAttachmentsSection", () => {
|
|||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not promote specific non-video content types by filename alone", async () => {
|
||||
const attachment = makeAttachment({
|
||||
id: "zip-mp4",
|
||||
originalFilename: "bundle.mp4",
|
||||
contentType: "application/zip",
|
||||
contentPath: "/api/attachments/zip-mp4/content",
|
||||
openPath: "/api/attachments/zip-mp4/content",
|
||||
downloadPath: "/api/attachments/zip-mp4/content?download=1",
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<IssueAttachmentsSection
|
||||
attachments={[attachment]}
|
||||
onDelete={vi.fn()}
|
||||
onImageClick={vi.fn()}
|
||||
/>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
});
|
||||
await flushReact();
|
||||
|
||||
expect(container.querySelector("video")).toBeNull();
|
||||
expect(container.textContent).toContain("bundle.mp4");
|
||||
expect(container.textContent).toContain("application/zip");
|
||||
expect(fetchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps generic attachments as compact file rows with open and download actions", async () => {
|
||||
const attachment = makeAttachment({
|
||||
id: "pdf-attachment",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
import type { IssueAttachment } from "@paperclipai/shared";
|
||||
import { isVideoContentType } from "./issue-output";
|
||||
|
||||
const GENERIC_ATTACHMENT_CONTENT_TYPES = new Set([
|
||||
"application/octet-stream",
|
||||
"binary/octet-stream",
|
||||
"application/x-binary",
|
||||
]);
|
||||
|
||||
function normalizedContentType(attachment: Pick<IssueAttachment, "contentType">) {
|
||||
return attachment.contentType.toLowerCase().split(";")[0]?.trim() ?? "";
|
||||
}
|
||||
|
|
@ -28,7 +34,9 @@ export function isImageAttachment(attachment: Pick<IssueAttachment, "contentType
|
|||
export function isVideoAttachment(
|
||||
attachment: Pick<IssueAttachment, "contentType" | "originalFilename">,
|
||||
) {
|
||||
if (isVideoContentType(normalizedContentType(attachment))) return true;
|
||||
const contentType = normalizedContentType(attachment);
|
||||
if (isVideoContentType(contentType)) return true;
|
||||
if (!GENERIC_ATTACHMENT_CONTENT_TYPES.has(contentType)) return false;
|
||||
|
||||
const filename = (attachment.originalFilename ?? "").toLowerCase();
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue