rhythia-api 178.0.0 → 180.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.
@@ -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")
@@ -51,5 +51,9 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
51
51
  }
52
52
 
53
53
  await supabase.from("beatmapCollections").delete().eq("id", data.collection);
54
+ await supabase
55
+ .from("collectionRelations")
56
+ .delete()
57
+ .eq("collection", data.collection);
54
58
  return NextResponse.json({});
55
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
+ }
@@ -59,6 +59,12 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
59
59
  });
60
60
  }
61
61
 
62
+ if (data.description.length > 128) {
63
+ return NextResponse.json({
64
+ error: "Description too long",
65
+ });
66
+ }
67
+
62
68
  await supabase.from("beatmapCollections").upsert({
63
69
  id: data.collection,
64
70
  title: data.title,
@@ -12,6 +12,10 @@ export const Schema = {
12
12
  collection: z.object({
13
13
  title: z.string(),
14
14
  description: z.string(),
15
+ owner: z.object({
16
+ id: z.number(),
17
+ username: z.string(),
18
+ }),
15
19
  beatmaps: z.array(
16
20
  z.object({
17
21
  id: z.number(),
@@ -47,7 +51,15 @@ export async function POST(request: Request) {
47
51
  export async function handler(data: (typeof Schema)["input"]["_type"]) {
48
52
  let { data: queryCollectionData, error: collectionError } = await supabase
49
53
  .from("beatmapCollections")
50
- .select("*")
54
+ .select(
55
+ `
56
+ *,
57
+ profiles!inner(
58
+ id,
59
+ username
60
+ )
61
+ `
62
+ )
51
63
  .eq("id", data.collection)
52
64
  .single();
53
65
 
@@ -104,6 +116,10 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
104
116
 
105
117
  return NextResponse.json({
106
118
  collection: {
119
+ owner: {
120
+ username: queryCollectionData.profiles.username,
121
+ id: queryCollectionData.profiles.id,
122
+ },
107
123
  title: queryCollectionData.title,
108
124
  description: queryCollectionData.description,
109
125
  beatmaps: formattedBeatmaps,
package/index.ts CHANGED
@@ -144,6 +144,23 @@ import { Schema as DeleteCollection } from "./api/deleteCollection"
144
144
  export { Schema as SchemaDeleteCollection } from "./api/deleteCollection"
145
145
  export const deleteCollection = handleApi({url:"/api/deleteCollection",...DeleteCollection})
146
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
+
147
164
  // ./api/editAboutMe.ts API
148
165
 
149
166
  /*
@@ -494,6 +511,10 @@ export const Schema = {
494
511
  collection: z.object({
495
512
  title: z.string(),
496
513
  description: z.string(),
514
+ owner: z.object({
515
+ id: z.number(),
516
+ username: z.string(),
517
+ }),
497
518
  beatmaps: z.array(
498
519
  z.object({
499
520
  id: z.number(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "178.0.0",
3
+ "version": "180.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors",
6
6
  "scripts": {