rhythia-api 243.0.0 → 244.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,12 @@
1
1
  import { NextResponse } from "../utils/response";
2
2
  import z from "zod";
3
3
  import { protectedApi, validUser } from "../utils/requestUtils";
4
- import { SSPMParser } from "../utils/star-calc/sspmParser";
4
+ import { SSPMParser, type SSPMParsedMap } from "../utils/star-calc/sspmParser";
5
+ import {
6
+ isRHM,
7
+ parseRHM,
8
+ rhmToSSPMParsedMap,
9
+ } from "../utils/star-calc/rhmParser";
5
10
  import { supabase } from "../utils/supabase";
6
11
  import { rateMap } from "../utils/star-calc";
7
12
  import { getUserBySession } from "../utils/getUserBySession";
@@ -79,13 +84,14 @@ export async function handler({
79
84
  if (!url.startsWith(`https://static.rhythia.com/`))
80
85
  return NextResponse.json({ error: "Invalid url" });
81
86
 
82
- let parsedData: ReturnType<SSPMParser["parse"]> | undefined;
87
+ let parsedData: SSPMParsedMap | undefined;
83
88
  let parseError: unknown;
84
89
 
85
90
  for (let attempt = 0; attempt < 4; attempt++) {
86
91
  try {
87
92
  const { object, objectKey, bytes } = await readStaticObject(url);
88
93
  const isSSPM = bytes.subarray(0, 4).toString("hex") === "53532b6d";
94
+ const isBeatmapFile = isSSPM || isRHM(bytes);
89
95
  console.log("createBeatmap object fetch result", {
90
96
  attempt: attempt + 1,
91
97
  url,
@@ -99,17 +105,17 @@ export async function handler({
99
105
  .toString("utf8")
100
106
  .replace(/[^\x20-\x7e]/g, "."),
101
107
  bodyPreview:
102
- !isSSPM && bytes.length <= 512
108
+ !isBeatmapFile && bytes.length <= 512
103
109
  ? bytes.toString("utf8").replace(/[^\x09\x0a\x0d\x20-\x7e]/g, ".")
104
110
  : undefined,
105
111
  eTag: object.ETag,
106
112
  versionId: object.VersionId,
107
113
  });
108
114
 
109
- const parser = new SSPMParser(bytes);
110
-
111
- parsedData = parser.parse();
112
- console.log("createBeatmap parsed SSPM", {
115
+ parsedData = isRHM(bytes)
116
+ ? rhmToSSPMParsedMap(parseRHM(bytes))
117
+ : new SSPMParser(bytes).parse();
118
+ console.log("createBeatmap parsed beatmap", {
113
119
  attempt: attempt + 1,
114
120
  mapID: parsedData.strings.mapID,
115
121
  noteCount: parsedData.metadata.noteCount,