Create fetch single queue item endpoint
This commit is contained in:
parent
f3fb370b6f
commit
aafdc9b04c
43
functions/api/mod-queue/[type]/[id].ts
Normal file
43
functions/api/mod-queue/[type]/[id].ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
export async function onRequestGet(context: RequestContext) {
|
||||||
|
const types: { [k: string]: { permissions: number[]; prefix: string } } = {
|
||||||
|
appeal: {
|
||||||
|
permissions: [1 << 0, 1 << 1],
|
||||||
|
prefix: `appeal_`,
|
||||||
|
},
|
||||||
|
gma: {
|
||||||
|
permissions: [1 << 5],
|
||||||
|
prefix: `gameappeal_`,
|
||||||
|
},
|
||||||
|
report: {
|
||||||
|
permissions: [1 << 5],
|
||||||
|
prefix: `report_`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const type = context.params.type as string;
|
||||||
|
const itemId = context.params.id as string;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!types[type]?.permissions.find(
|
||||||
|
(p) => context.data.current_user.permissions & p
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return new Response('{"error":"You cannot use this filter"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: 403,
|
||||||
|
});
|
||||||
|
|
||||||
|
let item = await context.env.DATA.get(`${types[type].prefix}${itemId}`);
|
||||||
|
|
||||||
|
if (!item)
|
||||||
|
item = await context.env.DATA.get(`closed${types[type].prefix}${itemId}`);
|
||||||
|
|
||||||
|
return new Response(item ? item : '{"error":"Not found"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: item ? 200 : 404,
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user