From f3547138e9db8a43beac2e689cbb5e5d4a4461b3 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:49:15 -0400 Subject: [PATCH] Create roblox open cloud helper --- functions/roblox-open-cloud.ts | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 functions/roblox-open-cloud.ts diff --git a/functions/roblox-open-cloud.ts b/functions/roblox-open-cloud.ts new file mode 100644 index 0000000..5b21277 --- /dev/null +++ b/functions/roblox-open-cloud.ts @@ -0,0 +1,38 @@ +const DATASTORE_URL = + "https://apis.roblox.com/datastores/v1/universes/274816972/standard-datastores/datastore/entries/entry?datastoreName=BanData&entryKey=CloudBanList"; + +export async function getBanList(context: RequestContext) { + const data = await fetch(DATASTORE_URL, { + headers: { + "x-api-key": context.env.ROBLOX_OPENCLOUD_KEY, + }, + }); + + if (!data.ok) { + console.log(await data.json()); + throw new Error("Failed to retrieve ban list"); + } + + return await data.json(); +} + +export async function setBanList( + context: RequestContext, + data: { [k: string]: { [k: string]: any } } +) { + const setRequest = await fetch(DATASTORE_URL, { + body: JSON.stringify(data), + headers: { + "content-type": "application/json", + "x-api-key": context.env.ROBLOX_OPENCLOUD_KEY, + }, + method: "POST", + }); + + if (!setRequest.ok) { + console.log(await setRequest.json()); + throw new Error("Failed to set ban list"); + } + + return await setRequest.json(); +}