rhythia-api 173.0.0 → 174.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.
- package/api/chartPublicStats.ts +32 -0
- package/api/createBeatmap.ts +3 -0
- package/api/getPublicStats.ts +13 -0
- package/api/getRawStarRating.ts +11 -1
- package/index.ts +17 -0
- package/package.json +1 -1
- package/types/database.ts +21 -0
- package/utils/star-calc/index.ts +3 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({}),
|
|
8
|
+
output: z.object({}),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function POST(request: Request) {
|
|
12
|
+
return protectedApi({
|
|
13
|
+
request,
|
|
14
|
+
schema: Schema,
|
|
15
|
+
authorization: () => {},
|
|
16
|
+
activity: handler,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
21
|
+
// 30 minutes activity
|
|
22
|
+
const countOnline = await supabase
|
|
23
|
+
.from("profileActivities")
|
|
24
|
+
.select("*", { count: "exact", head: true })
|
|
25
|
+
.gt("last_activity", Date.now() - 1800000);
|
|
26
|
+
|
|
27
|
+
await supabase.from("chartedValues").insert({
|
|
28
|
+
type: "online_players",
|
|
29
|
+
value: countOnline.count,
|
|
30
|
+
});
|
|
31
|
+
return NextResponse.json({});
|
|
32
|
+
}
|
package/api/createBeatmap.ts
CHANGED
|
@@ -86,6 +86,9 @@ export async function handler({
|
|
|
86
86
|
.single();
|
|
87
87
|
|
|
88
88
|
if (beatmapPage) {
|
|
89
|
+
if (beatmapPage?.status !== "UNRANKED")
|
|
90
|
+
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
91
|
+
|
|
89
92
|
if (!updateFlag) {
|
|
90
93
|
return NextResponse.json({ error: "Already Exists" });
|
|
91
94
|
} else if (beatmapPage.owner !== userData.id) {
|
package/api/getPublicStats.ts
CHANGED
|
@@ -10,6 +10,12 @@ export const Schema = {
|
|
|
10
10
|
beatmaps: z.number(),
|
|
11
11
|
scores: z.number(),
|
|
12
12
|
onlineUsers: z.number(),
|
|
13
|
+
countChart: z.array(
|
|
14
|
+
z.object({
|
|
15
|
+
type: z.string(),
|
|
16
|
+
value: z.number(),
|
|
17
|
+
})
|
|
18
|
+
),
|
|
13
19
|
lastBeatmaps: z.array(
|
|
14
20
|
z.object({
|
|
15
21
|
id: z.number().nullable().optional(),
|
|
@@ -127,11 +133,18 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
|
127
133
|
.select("*", { count: "exact", head: true })
|
|
128
134
|
.gt("last_activity", Date.now() - 1800000);
|
|
129
135
|
|
|
136
|
+
const countChart = await supabase
|
|
137
|
+
.from("chartedValues")
|
|
138
|
+
.select("*")
|
|
139
|
+
.eq("type", "online_players")
|
|
140
|
+
.gt("created_at", new Date(Date.now() - 86400000).toISOString());
|
|
141
|
+
|
|
130
142
|
return NextResponse.json({
|
|
131
143
|
beatmaps: countBeatmapsQuery.count,
|
|
132
144
|
profiles: countProfilesQuery.count,
|
|
133
145
|
scores: countScoresQuery.count,
|
|
134
146
|
onlineUsers: countOnline.count,
|
|
147
|
+
countChart: countChart.data,
|
|
135
148
|
lastBeatmaps: beatmapPage?.map((e) => ({
|
|
136
149
|
playcount: e.beatmaps?.playcount,
|
|
137
150
|
created_at: e.created_at,
|
package/api/getRawStarRating.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
-
import { rateMapNotes } from "../utils/star-calc";
|
|
4
|
+
import { calculatePerformancePoints, rateMapNotes } from "../utils/star-calc";
|
|
5
5
|
|
|
6
6
|
export const Schema = {
|
|
7
7
|
input: z.strictObject({
|
|
@@ -41,6 +41,16 @@ export async function handler(
|
|
|
41
41
|
return NextResponse.json({
|
|
42
42
|
beatmap: {
|
|
43
43
|
starRating,
|
|
44
|
+
rp: {
|
|
45
|
+
"S---": calculatePerformancePoints((starRating * 1) / 1.35, 1),
|
|
46
|
+
"S--": calculatePerformancePoints((starRating * 1) / 1.25, 1),
|
|
47
|
+
"S-": calculatePerformancePoints((starRating * 1) / 1.15, 1),
|
|
48
|
+
S: calculatePerformancePoints(starRating * 1, 1),
|
|
49
|
+
"S+": calculatePerformancePoints(starRating * 1.15, 1),
|
|
50
|
+
"S++": calculatePerformancePoints(starRating * 1.25, 1),
|
|
51
|
+
"S+++": calculatePerformancePoints(starRating * 1.35, 1),
|
|
52
|
+
"S++++": calculatePerformancePoints(starRating * 1.45, 1),
|
|
53
|
+
},
|
|
44
54
|
},
|
|
45
55
|
});
|
|
46
56
|
}
|
package/index.ts
CHANGED
|
@@ -16,6 +16,17 @@ import { Schema as ApproveMap } from "./api/approveMap"
|
|
|
16
16
|
export { Schema as SchemaApproveMap } from "./api/approveMap"
|
|
17
17
|
export const approveMap = handleApi({url:"/api/approveMap",...ApproveMap})
|
|
18
18
|
|
|
19
|
+
// ./api/chartPublicStats.ts API
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
export const Schema = {
|
|
23
|
+
input: z.strictObject({}),
|
|
24
|
+
output: z.object({}),
|
|
25
|
+
};*/
|
|
26
|
+
import { Schema as ChartPublicStats } from "./api/chartPublicStats"
|
|
27
|
+
export { Schema as SchemaChartPublicStats } from "./api/chartPublicStats"
|
|
28
|
+
export const chartPublicStats = handleApi({url:"/api/chartPublicStats",...ChartPublicStats})
|
|
29
|
+
|
|
19
30
|
// ./api/createBeatmap.ts API
|
|
20
31
|
|
|
21
32
|
/*
|
|
@@ -540,6 +551,12 @@ export const Schema = {
|
|
|
540
551
|
beatmaps: z.number(),
|
|
541
552
|
scores: z.number(),
|
|
542
553
|
onlineUsers: z.number(),
|
|
554
|
+
countChart: z.array(
|
|
555
|
+
z.object({
|
|
556
|
+
type: z.string(),
|
|
557
|
+
value: z.number(),
|
|
558
|
+
})
|
|
559
|
+
),
|
|
543
560
|
lastBeatmaps: z.array(
|
|
544
561
|
z.object({
|
|
545
562
|
id: z.number().nullable().optional(),
|
package/package.json
CHANGED
package/types/database.ts
CHANGED
|
@@ -153,6 +153,27 @@ export type Database = {
|
|
|
153
153
|
}
|
|
154
154
|
Relationships: []
|
|
155
155
|
}
|
|
156
|
+
chartedValues: {
|
|
157
|
+
Row: {
|
|
158
|
+
created_at: string
|
|
159
|
+
id: number
|
|
160
|
+
type: string | null
|
|
161
|
+
value: number | null
|
|
162
|
+
}
|
|
163
|
+
Insert: {
|
|
164
|
+
created_at?: string
|
|
165
|
+
id?: number
|
|
166
|
+
type?: string | null
|
|
167
|
+
value?: number | null
|
|
168
|
+
}
|
|
169
|
+
Update: {
|
|
170
|
+
created_at?: string
|
|
171
|
+
id?: number
|
|
172
|
+
type?: string | null
|
|
173
|
+
value?: number | null
|
|
174
|
+
}
|
|
175
|
+
Relationships: []
|
|
176
|
+
}
|
|
156
177
|
clans: {
|
|
157
178
|
Row: {
|
|
158
179
|
acronym: string | null
|
package/utils/star-calc/index.ts
CHANGED
|
@@ -31,9 +31,9 @@ export function rateMap(map: SSPMParsedMap) {
|
|
|
31
31
|
|
|
32
32
|
export function rateMapNotes(map: [number, number, number][]) {
|
|
33
33
|
let notes = map.map((marker) => ({
|
|
34
|
-
time: marker[
|
|
35
|
-
x: marker[
|
|
36
|
-
y: marker[
|
|
34
|
+
time: marker[2],
|
|
35
|
+
x: marker[0],
|
|
36
|
+
y: marker[1],
|
|
37
37
|
}));
|
|
38
38
|
|
|
39
39
|
return rate(notes);
|