Skip to content

Commit

Permalink
feat(utils): generate static map list in seed script
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Jan 16, 2024
1 parent 7c795b0 commit 744a1ae
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion libs/db/src/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
ReportType,
Role,
TrackType,
MapZones
MapZones,
FlatMapList,
CombinedMapStatuses,
mapListPath
} from '@momentum/constants';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { Bitflags } from '@momentum/bitflags';
Expand All @@ -36,6 +39,8 @@ import { JsonValue } from 'type-fest';
import { COS_XP_PARAMS, XpSystems } from '@momentum/xp-systems';
import { nuke } from '../prisma/utils';
import { prismaWrapper } from './prisma-wrapper';
import { promisify } from 'node:util';
import zlib from 'node:zlib';

//#region Configuration
// Can be overridden with --key=N or --key=N-M
Expand Down Expand Up @@ -725,6 +730,40 @@ prismaWrapper(async (prisma: PrismaClient) => {
//#endregion
}

// Now that we FINALLY have every map added, generate the static map lists
// Code here is derived from map-list.service.ts
if (doFileUploads)
for (const type of [FlatMapList.APPROVED, FlatMapList.SUBMISSION]) {
const maps = await prisma.mMap.findMany({
where: {
status:
type === FlatMapList.APPROVED
? MapStatusNew.APPROVED
: { in: CombinedMapStatuses.IN_SUBMISSION }
},
select: {
id: true,
name: true,
fileName: true,
hash: true,
createdAt: true,
thumbnail: true,
leaderboards: true,
info: true
}
});

const mapListJson = JSON.stringify(maps);
const compressed = await promisify(zlib.deflate)(mapListJson);
await s3.send(
new PutObjectCommand({
Bucket: process.env['STORAGE_BUCKET_NAME'],
Key: mapListPath(type, 1),
Body: compressed
})
);
}

//#region Make me admin

const personalSteamIDs = process.env['ADMIN_STEAM_ID64S'];
Expand Down

0 comments on commit 744a1ae

Please sign in to comment.