Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
car-crushers-portal/functions/roblox-open-cloud.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (49 sloc)
1.51 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DATASTORE_URL = | |
"https://apis.roblox.com/datastores/v1/universes/274816972/standard-datastores/datastore/entries/entry?datastoreName=BanData&entryKey=CloudBanList"; | |
const SAVE_DATA_URL = | |
"https://apis.roblox.com/datastores/v1/universes/274816972/standard-datastores/datastore/entries/entry?datastoreName=RealData&entryKey="; | |
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 getSaveData( | |
context: RequestContext, | |
user: number, | |
): Promise<string> { | |
const data = await fetch(`${SAVE_DATA_URL}${user}`, { | |
headers: { | |
"x-api-key": context.env.ROBLOX_OPENCLOUD_KEY, | |
}, | |
}); | |
if (!data.ok) { | |
console.log(await data.json()); | |
throw new Error(`Failed to retrieve save data for ${user}`); | |
} | |
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(); | |
} |