rhythia-api 149.0.0 → 150.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/updateBeatmapPage.ts +25 -17
- package/index.ts +3 -3
- package/package.json +1 -1
package/api/updateBeatmapPage.ts
CHANGED
|
@@ -7,9 +7,9 @@ export const Schema = {
|
|
|
7
7
|
input: z.strictObject({
|
|
8
8
|
session: z.string(),
|
|
9
9
|
id: z.number(),
|
|
10
|
-
beatmapHash: z.string(),
|
|
11
|
-
tags: z.string(),
|
|
12
|
-
description: z.string(),
|
|
10
|
+
beatmapHash: z.string().optional(),
|
|
11
|
+
tags: z.string().optional(),
|
|
12
|
+
description: z.string().optional(),
|
|
13
13
|
}),
|
|
14
14
|
output: z.strictObject({
|
|
15
15
|
error: z.string().optional(),
|
|
@@ -47,14 +47,17 @@ export async function handler({
|
|
|
47
47
|
.eq("id", id)
|
|
48
48
|
.single();
|
|
49
49
|
|
|
50
|
+
if (!userData) return NextResponse.json({ error: "No user." });
|
|
51
|
+
|
|
50
52
|
let { data: beatmapData, error: bmPageError } = await supabase
|
|
51
53
|
.from("beatmaps")
|
|
52
54
|
.select("*")
|
|
53
|
-
.eq("beatmapHash", beatmapHash)
|
|
55
|
+
.eq("beatmapHash", beatmapHash || "")
|
|
54
56
|
.single();
|
|
55
57
|
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
+
if (!beatmapData && beatmapHash) {
|
|
59
|
+
return NextResponse.json({ error: "No beatmap." });
|
|
60
|
+
}
|
|
58
61
|
|
|
59
62
|
if (userData.id !== pageData?.owner)
|
|
60
63
|
return NextResponse.json({ error: "Non-authz user." });
|
|
@@ -62,19 +65,24 @@ export async function handler({
|
|
|
62
65
|
if (pageData?.status !== "UNRANKED")
|
|
63
66
|
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
64
67
|
|
|
68
|
+
const upsertPayload = {
|
|
69
|
+
id,
|
|
70
|
+
latestBeatmapHash: beatmapHash ? beatmapHash : pageData.latestBeatmapHash,
|
|
71
|
+
genre: "",
|
|
72
|
+
status: "UNRANKED",
|
|
73
|
+
owner: userData.id,
|
|
74
|
+
description: description ? description : pageData.description,
|
|
75
|
+
tags: tags ? tags : pageData.tags,
|
|
76
|
+
nominations: [],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (beatmapHash && beatmapData) {
|
|
80
|
+
upsertPayload["title"] = beatmapData.title;
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
const upserted = await supabase
|
|
66
84
|
.from("beatmapPages")
|
|
67
|
-
.upsert(
|
|
68
|
-
id,
|
|
69
|
-
latestBeatmapHash: beatmapHash,
|
|
70
|
-
genre: "",
|
|
71
|
-
title: beatmapData.title,
|
|
72
|
-
status: "UNRANKED",
|
|
73
|
-
owner: userData.id,
|
|
74
|
-
description,
|
|
75
|
-
tags,
|
|
76
|
-
nominations: [],
|
|
77
|
-
})
|
|
85
|
+
.upsert(upsertPayload)
|
|
78
86
|
.select("*")
|
|
79
87
|
.single();
|
|
80
88
|
|
package/index.ts
CHANGED
|
@@ -593,9 +593,9 @@ export const Schema = {
|
|
|
593
593
|
input: z.strictObject({
|
|
594
594
|
session: z.string(),
|
|
595
595
|
id: z.number(),
|
|
596
|
-
beatmapHash: z.string(),
|
|
597
|
-
tags: z.string(),
|
|
598
|
-
description: z.string(),
|
|
596
|
+
beatmapHash: z.string().optional(),
|
|
597
|
+
tags: z.string().optional(),
|
|
598
|
+
description: z.string().optional(),
|
|
599
599
|
}),
|
|
600
600
|
output: z.strictObject({
|
|
601
601
|
error: z.string().optional(),
|