rhythia-api 177.0.0 → 179.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.
@@ -37,6 +37,11 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
37
37
  return NextResponse.json({ error: "Can't find user" });
38
38
  }
39
39
 
40
+ if (data.title.length < 3) {
41
+ return NextResponse.json({
42
+ error: "Collection title should be longer than 3",
43
+ });
44
+ }
40
45
  const inserted = await supabase
41
46
  .from("beatmapCollections")
42
47
  .insert({
@@ -61,6 +61,7 @@ export async function handler({
61
61
  return NextResponse.json({ error: "Only unranked maps can be updated" });
62
62
 
63
63
  await supabase.from("beatmapPageComments").delete().eq("beatmapPage", id);
64
+ await supabase.from("collectionRelations").delete().eq("beatmapPage", id);
64
65
  await supabase.from("beatmapPages").delete().eq("id", id);
65
66
  await supabase
66
67
  .from("beatmaps")
@@ -0,0 +1,59 @@
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
+ await supabase
55
+ .from("collectionRelations")
56
+ .delete()
57
+ .eq("collection", data.collection);
58
+ return NextResponse.json({});
59
+ }
@@ -0,0 +1,71 @@
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
+ beatmapPage: z.number(),
13
+ }),
14
+ output: z.object({
15
+ error: z.string().optional(),
16
+ }),
17
+ };
18
+
19
+ export async function POST(request: Request) {
20
+ return protectedApi({
21
+ request,
22
+ schema: Schema,
23
+ authorization: validUser,
24
+ activity: handler,
25
+ });
26
+ }
27
+
28
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
29
+ const user = (await getUserBySession(data.session)) as User;
30
+ let { data: queryUserData, error: userError } = await supabase
31
+ .from("profiles")
32
+ .select("*")
33
+ .eq("uid", user.id)
34
+ .single();
35
+
36
+ if (!queryUserData) {
37
+ return NextResponse.json({ error: "Can't find user" });
38
+ }
39
+
40
+ let { data: queryCollectionData, error: collectionError } = await supabase
41
+ .from("beatmapCollections")
42
+ .select("*")
43
+ .eq("id", data.collection)
44
+ .single();
45
+
46
+ let { data: queryBeatmapData, error: beatmapData } = await supabase
47
+ .from("beatmapPages")
48
+ .select("*")
49
+ .eq("id", data.beatmapPage)
50
+ .single();
51
+
52
+ if (!queryCollectionData) {
53
+ return NextResponse.json({ error: "Can't find collection" });
54
+ }
55
+
56
+ if (!queryBeatmapData) {
57
+ return NextResponse.json({ error: "Can't find beatmap page" });
58
+ }
59
+
60
+ if (queryCollectionData.owner !== queryUserData.id) {
61
+ return NextResponse.json({ error: "You can't update foreign collections" });
62
+ }
63
+
64
+ await supabase
65
+ .from("collectionRelations")
66
+ .delete()
67
+ .eq("beatmapPage", data.beatmapPage)
68
+ .eq("collection", data.collection);
69
+
70
+ return NextResponse.json({});
71
+ }
@@ -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
@@ -128,6 +128,39 @@ import { Schema as DeleteBeatmapPage } from "./api/deleteBeatmapPage"
128
128
  export { Schema as SchemaDeleteBeatmapPage } from "./api/deleteBeatmapPage"
129
129
  export const deleteBeatmapPage = handleApi({url:"/api/deleteBeatmapPage",...DeleteBeatmapPage})
130
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
+
147
+ // ./api/deleteCollectionMap.ts API
148
+
149
+ /*
150
+ export const Schema = {
151
+ input: z.strictObject({
152
+ session: z.string(),
153
+ collection: z.number(),
154
+ beatmapPage: z.number(),
155
+ }),
156
+ output: z.object({
157
+ error: z.string().optional(),
158
+ }),
159
+ };*/
160
+ import { Schema as DeleteCollectionMap } from "./api/deleteCollectionMap"
161
+ export { Schema as SchemaDeleteCollectionMap } from "./api/deleteCollectionMap"
162
+ export const deleteCollectionMap = handleApi({url:"/api/deleteCollectionMap",...DeleteCollectionMap})
163
+
131
164
  // ./api/editAboutMe.ts API
132
165
 
133
166
  /*
@@ -166,6 +199,24 @@ import { Schema as EditClan } from "./api/editClan"
166
199
  export { Schema as SchemaEditClan } from "./api/editClan"
167
200
  export const editClan = handleApi({url:"/api/editClan",...EditClan})
168
201
 
202
+ // ./api/editCollection.ts API
203
+
204
+ /*
205
+ export const Schema = {
206
+ input: z.strictObject({
207
+ session: z.string(),
208
+ collection: z.number(),
209
+ title: z.string(),
210
+ description: z.string(),
211
+ }),
212
+ output: z.object({
213
+ error: z.string().optional(),
214
+ }),
215
+ };*/
216
+ import { Schema as EditCollection } from "./api/editCollection"
217
+ export { Schema as SchemaEditCollection } from "./api/editCollection"
218
+ export const editCollection = handleApi({url:"/api/editCollection",...EditCollection})
219
+
169
220
  // ./api/editProfile.ts API
170
221
 
171
222
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "177.0.0",
3
+ "version": "179.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors",
6
6
  "scripts": {