Move to V2 datastore apis

This commit is contained in:
2026-03-31 03:24:13 -04:00
parent b69b5cb4eb
commit e3af1e4f37
8 changed files with 36 additions and 53 deletions

View File

@@ -49,9 +49,7 @@ export async function onRequestGet(context: RequestContext) {
let banList;
try {
banList = (await getBanList(context)) as {
[k: string]: { BanType: number };
};
banList = (await getBanList(context)).value;
} catch {
return jsonError("Failed to create data transfer request", 500);
}

View File

@@ -15,15 +15,7 @@ export async function onRequestPost(context: RequestContext) {
if (!appeal) return jsonError("Appeal not found", 400);
const banList = (await getBanList(context)) as {
[k: string]: {
BanType: number;
hidden_from_leaderboards?: boolean;
serverconfigurator_blacklist?: boolean;
Unbanned?: boolean;
UnbanReduct?: number;
};
};
const { etag, path, value: banList } = await getBanList(context);
await context.env.D1.prepare("DELETE FROM game_appeals WHERE id = ?;")
.bind(context.params.id)
@@ -67,7 +59,7 @@ export async function onRequestPost(context: RequestContext) {
)
.run();
await setBanList(context, banList);
await setBanList(context, banList, etag);
return new Response(null, {
status: 204,

View File

@@ -24,13 +24,7 @@ export default async function (
let banList;
try {
banList = (await getBanList(context)) as {
[k: number]: {
BanType: number;
hidden_from_leaderboards?: boolean;
serverconfigurator_blacklist?: boolean;
};
};
banList = (await getBanList(context)).value;
} catch {
return {
error: "Failed to check your ban status",

View File

@@ -33,13 +33,7 @@ export async function onRequestGet(context: RequestContext) {
let banList;
try {
banList = (await getBanList(context)) as {
[k: number]: {
BanType: number;
hidden_from_leaderboards?: boolean;
serverconfigurator_blacklist?: boolean;
};
};
banList = (await getBanList(context)).value;
} catch (e) {
console.log(e);

View File

@@ -31,12 +31,10 @@ export async function onRequestPost(context: RequestContext) {
)
.run();
const banList = (await getBanList(context)) as {
[k: string]: { BanType: number };
};
const { etag, path, value: banList } = await getBanList(context);
delete banList[user];
await setBanList(context, banList);
await setBanList(context, banList, etag);
return new Response(null, {
status: 204,

View File

@@ -78,15 +78,9 @@ export async function onRequestPost(context: RequestContext) {
await context.env.D1.batch(batchedQueries);
const banList = (await getBanList(context)) as {
[k: string]: {
BanType: number;
hidden_from_leaderboards?: boolean;
serverconfigurator_blacklist?: boolean;
};
};
const { etag, path, value: banList } = await getBanList(context);
await setBanList(context, Object.assign(banList, newActions));
await setBanList(context, Object.assign(banList, newActions), etag);
}
const pushNotificationData: Record<string, string> | null =

View File

@@ -1,8 +1,8 @@
const DATASTORE_URL =
"https://apis.roblox.com/datastores/v1/universes/274816972/standard-datastores/datastore/entries/entry?datastoreName=BanData&entryKey=CloudBanList";
"https://apis.roblox.com/cloud/v2/universes/274816972/data-stores/BanData/entries/CloudBanList";
const SAVE_DATA_URL =
"https://apis.roblox.com/datastores/v1/universes/274816972/standard-datastores/datastore/entries/entry?datastoreName=RealData&entryKey=";
"https://apis.roblox.com/cloud/v2/universes/274816972/data-stores/RealData/entries";
export async function getBanList(context: RequestContext) {
const data = await fetch(DATASTORE_URL, {
@@ -16,14 +16,26 @@ export async function getBanList(context: RequestContext) {
throw new Error("Failed to retrieve ban list");
}
return await data.json();
return (await data.json()) as {
etag: string;
path: string;
value: {
[k: string]: {
BanType: number;
hidden_from_leaderboards?: boolean;
serverconfigurator_blacklist?: boolean;
Unbanned?: boolean;
UnbanReduct?: number;
};
};
};
}
export async function getSaveData(
context: RequestContext,
user: number,
): Promise<string> {
const data = await fetch(`${SAVE_DATA_URL}${user}`, {
const data = await fetch(`${SAVE_DATA_URL}/${user}`, {
headers: {
"x-api-key": context.env.ROBLOX_OPENCLOUD_KEY,
},
@@ -34,20 +46,21 @@ export async function getSaveData(
throw new Error(`Failed to retrieve save data for ${user}`);
}
return await data.json();
return ((await data.json()) as { value: string }).value;
}
export async function setBanList(
context: RequestContext,
data: { [k: string]: { [k: string]: any } },
value: any,
etag?: string,
) {
const setRequest = await fetch(DATASTORE_URL, {
body: JSON.stringify(data),
body: JSON.stringify(etag, value),
headers: {
"content-type": "application/json",
"x-api-key": context.env.ROBLOX_OPENCLOUD_KEY,
},
method: "POST",
method: "PATCH",
});
if (!setRequest.ok) {

View File

@@ -17,11 +17,11 @@
"@remix-run/cloudflare": "^2.17.4",
"@remix-run/cloudflare-pages": "^2.17.4",
"@remix-run/react": "^2.17.4",
"@sentry/cloudflare": "^10.43.0",
"@sentry/remix": "^10.43.0",
"@sentry/cloudflare": "^10.46.0",
"@sentry/remix": "^10.46.0",
"aws4fetch": "^1.0.20",
"dayjs": "^1.11.19",
"framer-motion": "^12.35.2",
"dayjs": "^1.11.20",
"framer-motion": "^12.38.0",
"react": "^18.3.1",
"react-big-calendar": "^1.19.4",
"react-dom": "^18.3.1"
@@ -34,10 +34,10 @@
"@types/react-dom": "^18.3.7",
"dotenv": "^17.3.1",
"prettier": "^3.8.1",
"typescript": "^5.9.3"
"typescript": "^6.0.2"
},
"overrides": {
"@cloudflare/workers-types": "^4.20260310.1"
"@cloudflare/workers-types": "^4.20260329.1"
},
"prettier": {
"endOfLine": "auto"