Convert stats to bigints (#909)

Fixes #880

## Description:

Convert numeric stat types to bigint, and serialize those values as
strings.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [ ] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
Scott Anderson
2025-05-27 22:13:05 -04:00
committed by GitHub
parent 0b79d0be16
commit 8cf2d86a70
6 changed files with 313 additions and 50 deletions
+10 -3
View File
@@ -60,7 +60,7 @@ async function archiveAnalyticsToR2(gameRecord: GameRecord) {
await r2.putObject({
Bucket: bucket,
Key: `${analyticsFolder}/${analyticsKey}`,
Body: JSON.stringify(analyticsData),
Body: JSON.stringify(analyticsData, replacer),
ContentType: "application/json",
});
@@ -78,7 +78,7 @@ async function archiveAnalyticsToR2(gameRecord: GameRecord) {
async function archiveFullGameToR2(gameRecord: GameRecord) {
// Create a deep copy to avoid modifying the original
const recordCopy: GameRecord = JSON.parse(JSON.stringify(gameRecord));
const recordCopy = structuredClone(gameRecord);
// Players may see this so make sure to clear PII
recordCopy.info.players.forEach((p) => {
@@ -89,7 +89,7 @@ async function archiveFullGameToR2(gameRecord: GameRecord) {
await r2.putObject({
Bucket: bucket,
Key: `${gameFolder}/${recordCopy.info.gameID}`,
Body: JSON.stringify(recordCopy),
Body: JSON.stringify(recordCopy, replacer),
ContentType: "application/json",
});
} catch (error) {
@@ -147,3 +147,10 @@ export async function gameRecordExists(gameId: GameID): Promise<boolean> {
return false;
}
}
/**
* JSON.stringify replacer function that converts bigint values to strings.
*/
export function replacer(_key: string, value: any): any {
return typeof value === "bigint" ? value.toString() : value;
}