Create queue list endpoint
This commit is contained in:
parent
71b7104502
commit
cc0bc16967
@ -1,20 +1,49 @@
|
|||||||
export async function onRequestGet(context: RequestContext) {
|
export async function onRequestGet(context: RequestContext) {
|
||||||
const { searchParams } = new URL(context.request.url);
|
const { searchParams } = new URL(context.request.url);
|
||||||
const entryType = searchParams.get("type") ?? "all";
|
const cursor = searchParams.get("cursor");
|
||||||
|
const entryType = searchParams.get("type");
|
||||||
const showClosed = searchParams.get("showClosed") === "true";
|
const showClosed = searchParams.get("showClosed") === "true";
|
||||||
const items: { type: string; data: { [k: string]: any } }[] = [];
|
const types: { [k: string]: string } = {
|
||||||
const types = {
|
|
||||||
appeal: `appeal_`,
|
appeal: `appeal_`,
|
||||||
gma: `gameappeal_`,
|
gma: `gameappeal_`,
|
||||||
report: `report_`,
|
report: `report_`,
|
||||||
};
|
};
|
||||||
const permissions = {
|
const permissions: { [k: string]: number[] } = {
|
||||||
appeal: [1 << 0, 1 << 1],
|
appeal: [1 << 0, 1 << 1],
|
||||||
gma: [1 << 5],
|
gma: [1 << 5],
|
||||||
report: [1 << 5],
|
report: [1 << 5],
|
||||||
};
|
};
|
||||||
const { current_user: currentUser } = context.data;
|
const { current_user: currentUser } = context.data;
|
||||||
|
|
||||||
|
if (!entryType || !types[entryType])
|
||||||
|
return new Response('{"error":"Invalid filter type"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: 400,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!permissions[entryType].find((p) => currentUser.permissions & p))
|
||||||
|
return new Response('{"error":"You cannot use this filter"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: 403,
|
||||||
|
});
|
||||||
|
|
||||||
|
let prefix = types[entryType];
|
||||||
|
|
||||||
|
if (showClosed) prefix = `closed${prefix}`;
|
||||||
|
|
||||||
|
const { keys } = await context.env.DATA.list({ cursor, limit: 20, prefix });
|
||||||
|
const items = [];
|
||||||
|
|
||||||
|
for (const key of keys) {
|
||||||
|
const listItem = await context.env.DATA.get(key.name);
|
||||||
|
|
||||||
|
if (listItem) items.push(JSON.parse(listItem));
|
||||||
|
}
|
||||||
|
|
||||||
return new Response(JSON.stringify(items), {
|
return new Response(JSON.stringify(items), {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user