rhythia-api 176.0.0 → 178.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/addCollectionMap.ts +12 -0
- package/api/createCollection.ts +18 -6
- package/api/deleteCollection.ts +55 -0
- package/api/editCollection.ts +69 -0
- package/index.ts +35 -0
- package/package.json +1 -1
package/api/addCollectionMap.ts
CHANGED
|
@@ -37,6 +37,18 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
|
37
37
|
return NextResponse.json({ error: "Can't find user" });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
let { data: queryCollectionRelation, error: collectionRelationError } =
|
|
41
|
+
await supabase
|
|
42
|
+
.from("collectionRelations")
|
|
43
|
+
.select("*")
|
|
44
|
+
.eq("collection", data.collection)
|
|
45
|
+
.eq("beatmapPage", data.beatmapPage)
|
|
46
|
+
.single();
|
|
47
|
+
|
|
48
|
+
if (queryCollectionRelation) {
|
|
49
|
+
return NextResponse.json({ error: "Map already in collection" });
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
41
53
|
.from("beatmapCollections")
|
|
42
54
|
.select("*")
|
package/api/createCollection.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const Schema = {
|
|
|
11
11
|
title: z.string(),
|
|
12
12
|
}),
|
|
13
13
|
output: z.object({
|
|
14
|
+
id: z.number(),
|
|
14
15
|
error: z.string().optional(),
|
|
15
16
|
}),
|
|
16
17
|
};
|
|
@@ -36,11 +37,22 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
|
36
37
|
return NextResponse.json({ error: "Can't find user" });
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
40
|
+
if (data.title.length < 3) {
|
|
41
|
+
return NextResponse.json({
|
|
42
|
+
error: "Collection title should be longer than 3",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const inserted = await supabase
|
|
46
|
+
.from("beatmapCollections")
|
|
47
|
+
.insert({
|
|
48
|
+
title: data.title,
|
|
49
|
+
description: "",
|
|
50
|
+
owner: queryUserData.id,
|
|
51
|
+
})
|
|
52
|
+
.select("*")
|
|
53
|
+
.single();
|
|
44
54
|
|
|
45
|
-
return NextResponse.json({
|
|
55
|
+
return NextResponse.json({
|
|
56
|
+
id: inserted.data!.id,
|
|
57
|
+
});
|
|
46
58
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
import { getUserBySession } from "../utils/getUserBySession";
|
|
6
|
+
import { User } from "@supabase/supabase-js";
|
|
7
|
+
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
collection: z.number(),
|
|
12
|
+
}),
|
|
13
|
+
output: z.object({
|
|
14
|
+
error: z.string().optional(),
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function POST(request: Request) {
|
|
19
|
+
return protectedApi({
|
|
20
|
+
request,
|
|
21
|
+
schema: Schema,
|
|
22
|
+
authorization: validUser,
|
|
23
|
+
activity: handler,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
28
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
29
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
30
|
+
.from("profiles")
|
|
31
|
+
.select("*")
|
|
32
|
+
.eq("uid", user.id)
|
|
33
|
+
.single();
|
|
34
|
+
|
|
35
|
+
if (!queryUserData) {
|
|
36
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
40
|
+
.from("beatmapCollections")
|
|
41
|
+
.select("*")
|
|
42
|
+
.eq("id", data.collection)
|
|
43
|
+
.single();
|
|
44
|
+
|
|
45
|
+
if (!queryCollectionData) {
|
|
46
|
+
return NextResponse.json({ error: "Can't find collection" });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (queryCollectionData.owner !== queryUserData.id) {
|
|
50
|
+
return NextResponse.json({ error: "You can't update foreign collections" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await supabase.from("beatmapCollections").delete().eq("id", data.collection);
|
|
54
|
+
return NextResponse.json({});
|
|
55
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
import { getUserBySession } from "../utils/getUserBySession";
|
|
6
|
+
import { User } from "@supabase/supabase-js";
|
|
7
|
+
import { describe } from "node:test";
|
|
8
|
+
|
|
9
|
+
export const Schema = {
|
|
10
|
+
input: z.strictObject({
|
|
11
|
+
session: z.string(),
|
|
12
|
+
collection: z.number(),
|
|
13
|
+
title: z.string(),
|
|
14
|
+
description: z.string(),
|
|
15
|
+
}),
|
|
16
|
+
output: z.object({
|
|
17
|
+
error: z.string().optional(),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function POST(request: Request) {
|
|
22
|
+
return protectedApi({
|
|
23
|
+
request,
|
|
24
|
+
schema: Schema,
|
|
25
|
+
authorization: validUser,
|
|
26
|
+
activity: handler,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
31
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
32
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
33
|
+
.from("profiles")
|
|
34
|
+
.select("*")
|
|
35
|
+
.eq("uid", user.id)
|
|
36
|
+
.single();
|
|
37
|
+
|
|
38
|
+
if (!queryUserData) {
|
|
39
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
43
|
+
.from("beatmapCollections")
|
|
44
|
+
.select("*")
|
|
45
|
+
.eq("id", data.collection)
|
|
46
|
+
.single();
|
|
47
|
+
|
|
48
|
+
if (!queryCollectionData) {
|
|
49
|
+
return NextResponse.json({ error: "Can't find collection" });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (queryCollectionData.owner !== queryUserData.id) {
|
|
53
|
+
return NextResponse.json({ error: "You can't update foreign collections" });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (data.title.length < 3) {
|
|
57
|
+
return NextResponse.json({
|
|
58
|
+
error: "Collection title should be longer than 3",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await supabase.from("beatmapCollections").upsert({
|
|
63
|
+
id: data.collection,
|
|
64
|
+
title: data.title,
|
|
65
|
+
description: data.description,
|
|
66
|
+
owner: queryUserData.id,
|
|
67
|
+
});
|
|
68
|
+
return NextResponse.json({});
|
|
69
|
+
}
|
package/index.ts
CHANGED
|
@@ -104,6 +104,7 @@ export const Schema = {
|
|
|
104
104
|
title: z.string(),
|
|
105
105
|
}),
|
|
106
106
|
output: z.object({
|
|
107
|
+
id: z.number(),
|
|
107
108
|
error: z.string().optional(),
|
|
108
109
|
}),
|
|
109
110
|
};*/
|
|
@@ -127,6 +128,22 @@ import { Schema as DeleteBeatmapPage } from "./api/deleteBeatmapPage"
|
|
|
127
128
|
export { Schema as SchemaDeleteBeatmapPage } from "./api/deleteBeatmapPage"
|
|
128
129
|
export const deleteBeatmapPage = handleApi({url:"/api/deleteBeatmapPage",...DeleteBeatmapPage})
|
|
129
130
|
|
|
131
|
+
// ./api/deleteCollection.ts API
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
export const Schema = {
|
|
135
|
+
input: z.strictObject({
|
|
136
|
+
session: z.string(),
|
|
137
|
+
collection: z.number(),
|
|
138
|
+
}),
|
|
139
|
+
output: z.object({
|
|
140
|
+
error: z.string().optional(),
|
|
141
|
+
}),
|
|
142
|
+
};*/
|
|
143
|
+
import { Schema as DeleteCollection } from "./api/deleteCollection"
|
|
144
|
+
export { Schema as SchemaDeleteCollection } from "./api/deleteCollection"
|
|
145
|
+
export const deleteCollection = handleApi({url:"/api/deleteCollection",...DeleteCollection})
|
|
146
|
+
|
|
130
147
|
// ./api/editAboutMe.ts API
|
|
131
148
|
|
|
132
149
|
/*
|
|
@@ -165,6 +182,24 @@ import { Schema as EditClan } from "./api/editClan"
|
|
|
165
182
|
export { Schema as SchemaEditClan } from "./api/editClan"
|
|
166
183
|
export const editClan = handleApi({url:"/api/editClan",...EditClan})
|
|
167
184
|
|
|
185
|
+
// ./api/editCollection.ts API
|
|
186
|
+
|
|
187
|
+
/*
|
|
188
|
+
export const Schema = {
|
|
189
|
+
input: z.strictObject({
|
|
190
|
+
session: z.string(),
|
|
191
|
+
collection: z.number(),
|
|
192
|
+
title: z.string(),
|
|
193
|
+
description: z.string(),
|
|
194
|
+
}),
|
|
195
|
+
output: z.object({
|
|
196
|
+
error: z.string().optional(),
|
|
197
|
+
}),
|
|
198
|
+
};*/
|
|
199
|
+
import { Schema as EditCollection } from "./api/editCollection"
|
|
200
|
+
export { Schema as SchemaEditCollection } from "./api/editCollection"
|
|
201
|
+
export const editCollection = handleApi({url:"/api/editCollection",...EditCollection})
|
|
202
|
+
|
|
168
203
|
// ./api/editProfile.ts API
|
|
169
204
|
|
|
170
205
|
/*
|