From a02cecb23bd25f6e676959660ece8c666b5e6d87 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:49:44 -0400 Subject: [PATCH] Handle quicktime movies on mobile devices --- components/NewGameBan.tsx | 86 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/components/NewGameBan.tsx b/components/NewGameBan.tsx index 8de4055..34e3128 100644 --- a/components/NewGameBan.tsx +++ b/components/NewGameBan.tsx @@ -27,6 +27,22 @@ import { useState } from "react"; export default function (props: { isOpen: boolean; onClose: () => void }) { const actionMap: { [k: string]: number } = {}; const [rows, setRows] = useState([] as JSX.Element[]); + const fileTypes: { [k: string]: string } = { + gif: "image/gif", + heic: "image/heic", + heif: "image/heif", + jfif: "image/jpeg", + jpeg: "image/jpeg", + jpg: "image/jpg", + m4v: "video/x-m4v", + mkv: "video/x-matroska", + mov: "video/quicktime", + mp4: "video/mp4", + png: "image/png", + webp: "image/webp", + webm: "video/webm", + wmv: "video/x-ms-wmv", + }; function addUser(user: string) { const newRows = [...rows]; @@ -81,6 +97,63 @@ export default function (props: { isOpen: boolean; onClose: () => void }) { props.onClose(); } + async function submit() { + const actions: number[] = []; + const usernames: string[] = []; + + for (const [u, a] of Object.entries(actionMap)) { + actions.push(a); + usernames.push(u); + } + + if (!usernames.length || !actions.length) return; + + const files = (document.getElementById("evidence") as HTMLInputElement) + .files; + + if (!files) return; + + const [evidence] = files; + + const submitReq = await fetch("/api/reports/submit", { + body: JSON.stringify({ + actions, + bypass: true, + filename: evidence.name, + filesize: evidence.size, + usernames, + }), + headers: { + "content-type": "application/json", + }, + method: "POST", + }); + + if (!submitReq.ok) { + useToast()({ + description: ((await submitReq.json()) as { error: string }).error, + status: "error", + title: "Failed to submit report", + }); + + return; + } + + const { id, upload_url }: { [k: string]: string } = await submitReq.json(); + + const fileUpload = await fetch(upload_url, { + body: evidence, + headers: { + "content-type": + evidence.type || + fileTypes[ + evidence.name.split(".")[evidence.name.split(".").length - 1] + ], + }, + method: "PUT", + }); + } + return ( @@ -147,7 +220,18 @@ export default function (props: { isOpen: boolean; onClose: () => void }) { -