From 744a1ae29c8e98ae5153114489e69e45a8239e21 Mon Sep 17 00:00:00 2001 From: tsa96 Date: Tue, 16 Jan 2024 18:48:54 +0000 Subject: [PATCH] feat(utils): generate static map list in seed script --- libs/db/src/scripts/seed.ts | 41 ++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/libs/db/src/scripts/seed.ts b/libs/db/src/scripts/seed.ts index b83dad0091..c7024523c7 100644 --- a/libs/db/src/scripts/seed.ts +++ b/libs/db/src/scripts/seed.ts @@ -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'; @@ -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 @@ -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'];