Return mobile client hint and user agent in thrown responses and handle direct entity requests

This commit is contained in:
regalijan 2023-10-19 16:49:54 -04:00
parent 680d916894
commit 7dc655dea7
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -26,11 +26,19 @@ import NewInactivityNotice from "../../components/NewInactivityNotice.js";
export async function loader({ context }: { context: RequestContext }) { export async function loader({ context }: { context: RequestContext }) {
const { current_user: currentUser } = context.data; const { current_user: currentUser } = context.data;
const ch = context.request.headers.get("sec-ch-ua-mobile");
const ua = context.request.headers.get("user-agent");
if (!currentUser) if (!currentUser)
throw new Response(null, { throw new Response(
status: 401, JSON.stringify({
}); ch,
ua,
}),
{
status: 401,
}
);
const departments = { const departments = {
DM: 1 << 2, DM: 1 << 2,
@ -77,7 +85,7 @@ export async function loader({ context }: { context: RequestContext }) {
} }
if (!allowedTypes.length) if (!allowedTypes.length)
throw new Response(null, { throw new Response(JSON.stringify({ ch, ua }), {
status: 403, status: 403,
}); });
@ -119,7 +127,7 @@ export default function () {
async function updateQueue( async function updateQueue(
queue_type: string, queue_type: string,
before = 0, before = Date.now(),
show_closed = false show_closed = false
): Promise<void> { ): Promise<void> {
const queueReq = await fetch( const queueReq = await fetch(
@ -140,9 +148,33 @@ export default function () {
return; return;
} }
const searchParams = new URLSearchParams(location.search);
const itemId = searchParams.get("id");
const itemType = searchParams.get("type");
const entryData: { [k: string]: any }[] = await queueReq.json(); const entryData: { [k: string]: any }[] = await queueReq.json();
const newEntries = [...entries]; const newEntries = [...entries];
if (itemId && itemType && ["appeal", "gma", "report"].includes(itemType)) {
const itemReq = await fetch(`/api/mod-queue/${itemType}/${itemId}`);
if (!itemReq.ok) {
useToast()({
description: ((await itemReq.json()) as { error: string }).error,
duration: 10000,
isClosable: true,
status: "error",
title: "Failed to load item with id " + itemId,
});
} else {
const itemData: { [k: string]: any } = await itemReq.json();
entryData.unshift(itemData);
}
}
if (!entryData.length) return;
for (const entry of entryData) { for (const entry of entryData) {
switch (queue_type) { switch (queue_type) {
case "appeal": case "appeal":
@ -180,6 +212,10 @@ export default function () {
}; };
useEffect(() => { useEffect(() => {
(async function () {
await updateQueue(pageProps.entry_types[0].value);
})();
const searchParams = new URLSearchParams(location.search); const searchParams = new URLSearchParams(location.search);
const modal = searchParams.get("modal"); const modal = searchParams.get("modal");