rhythia-api 117.0.0 → 118.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.
@@ -40,9 +40,7 @@ export async function handler({
40
40
  }: (typeof Schema)["input"]["_type"]): Promise<
41
41
  NextResponse<(typeof Schema)["output"]["_type"]>
42
42
  > {
43
- if (
44
- !url.startsWith(`https://rhthia-avatars.s3.eu-central-003.backblazeb2.com/`)
45
- )
43
+ if (!url.startsWith(`https://static.rhythia.com/`))
46
44
  return NextResponse.json({ error: "Invalid url" });
47
45
 
48
46
  const request = await fetch(url);
@@ -71,7 +69,7 @@ export async function handler({
71
69
  noteCount: parsedData.metadata.noteCount,
72
70
  length: parsedData.pointers.audioLength,
73
71
  beatmapFile: url,
74
- image: `https://rhthia-avatars.s3.eu-central-003.backblazeb2.com/${imgkey}`,
72
+ image: `https://static.rhythia.com/${imgkey}`,
75
73
  starRating: rateMap(parsedData),
76
74
  });
77
75
 
@@ -8,6 +8,9 @@ export const Schema = {
8
8
  session: z.string(),
9
9
  textFilter: z.string().optional(),
10
10
  page: z.number().default(1),
11
+ maxStars: z.number().optional(),
12
+ minStars: z.number().optional(),
13
+ status: z.string().optional(),
11
14
  }),
12
15
  output: z.object({
13
16
  error: z.string().optional(),
@@ -49,58 +52,25 @@ export async function POST(request: Request): Promise<NextResponse> {
49
52
  export async function handler(
50
53
  data: (typeof Schema)["input"]["_type"]
51
54
  ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
52
- const result = await getBeatmaps(
53
- data.page,
54
- data.session,
55
- data.textFilter || ""
56
- );
55
+ const result = await getBeatmaps(data);
57
56
  return NextResponse.json(result);
58
57
  }
59
58
 
60
59
  const VIEW_PER_PAGE = 50;
61
60
 
62
- export async function getBeatmaps(page = 1, session: string, filter: string) {
63
- const startPage = (page - 1) * VIEW_PER_PAGE;
61
+ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
62
+ const startPage = (data.page - 1) * VIEW_PER_PAGE;
64
63
  const endPage = startPage + VIEW_PER_PAGE - 1;
65
64
  const countQuery = await supabase
66
65
  .from("beatmapPages")
67
66
  .select("*", { count: "exact", head: true });
68
67
 
69
- let queryData = await getQuery(startPage, endPage, filter);
70
-
71
- return {
72
- total: countQuery.count || 0,
73
- viewPerPage: VIEW_PER_PAGE,
74
- currentPage: page,
75
- beatmaps: queryData
76
- ?.filter((e) => e.beatmaps)
77
- .map((beatmapPage) => ({
78
- id: beatmapPage.id,
79
- playcount: beatmapPage.beatmaps?.playcount,
80
- created_at: beatmapPage.created_at,
81
- difficulty: beatmapPage.beatmaps?.difficulty,
82
- noteCount: beatmapPage.beatmaps?.noteCount,
83
- length: beatmapPage.beatmaps?.length,
84
- title: beatmapPage.beatmaps?.title,
85
- ranked: beatmapPage.beatmaps?.ranked,
86
- beatmapFile: beatmapPage.beatmaps?.beatmapFile,
87
- image: beatmapPage.beatmaps?.image,
88
- starRating: beatmapPage.beatmaps?.starRating,
89
- owner: beatmapPage.owner,
90
- ownerUsername: beatmapPage.profiles?.username,
91
- ownerAvatar: beatmapPage.profiles?.avatar_url,
92
- })),
93
- };
94
- }
95
-
96
- async function getQuery(startPage: number, endPage: number, filter: string) {
97
- if (filter.length) {
98
- let { data: data, error } = await supabase
99
- .from("beatmapPages")
100
- .select(
101
- `
68
+ let qry = supabase
69
+ .from("beatmapPages")
70
+ .select(
71
+ `
102
72
  *,
103
- beatmaps (
73
+ beatmaps!inner(
104
74
  created_at,
105
75
  playcount,
106
76
  length,
@@ -112,41 +82,49 @@ async function getQuery(startPage: number, endPage: number, filter: string) {
112
82
  noteCount,
113
83
  title
114
84
  ),
115
- profiles (
85
+ profiles!inner(
116
86
  username,
117
87
  avatar_url
118
88
  )`
119
- )
120
- .order("created_at", { ascending: false })
121
- .ilike("beatmaps.title", `%${filter}%`)
122
- .range(startPage, endPage);
89
+ )
90
+ .order("created_at", { ascending: false });
123
91
 
124
- return data;
125
- } else {
126
- let { data: data, error } = await supabase
127
- .from("beatmapPages")
128
- .select(
129
- `
130
- *,
131
- beatmaps (
132
- created_at,
133
- playcount,
134
- length,
135
- ranked,
136
- beatmapFile,
137
- image,
138
- starRating,
139
- difficulty,
140
- noteCount,
141
- title
142
- ),
143
- profiles (
144
- username,
145
- avatar_url
146
- )`
147
- )
148
- .order("created_at", { ascending: false })
149
- .range(startPage, endPage);
150
- return data;
92
+ if (data.textFilter) {
93
+ qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
151
94
  }
95
+
96
+ if (data.minStars) {
97
+ qry = qry.gt("beatmaps.starRating", data.minStars);
98
+ }
99
+
100
+ if (data.maxStars) {
101
+ qry = qry.lt("beatmaps.starRating", data.maxStars);
102
+ }
103
+ if (data.status) {
104
+ qry = qry.eq("status", data.status);
105
+ }
106
+
107
+ let queryData = await qry.range(startPage, endPage);
108
+
109
+ return {
110
+ total: countQuery.count || 0,
111
+ viewPerPage: VIEW_PER_PAGE,
112
+ currentPage: data.page,
113
+ beatmaps: queryData.data?.map((beatmapPage) => ({
114
+ id: beatmapPage.id,
115
+ playcount: beatmapPage.beatmaps?.playcount,
116
+ created_at: beatmapPage.created_at,
117
+ difficulty: beatmapPage.beatmaps?.difficulty,
118
+ noteCount: beatmapPage.beatmaps?.noteCount,
119
+ length: beatmapPage.beatmaps?.length,
120
+ title: beatmapPage.beatmaps?.title,
121
+ ranked: beatmapPage.beatmaps?.ranked,
122
+ beatmapFile: beatmapPage.beatmaps?.beatmapFile,
123
+ image: beatmapPage.beatmaps?.image,
124
+ starRating: beatmapPage.beatmaps?.starRating,
125
+ owner: beatmapPage.owner,
126
+ ownerUsername: beatmapPage.profiles?.username,
127
+ ownerAvatar: beatmapPage.profiles?.avatar_url,
128
+ })),
129
+ };
152
130
  }
@@ -43,7 +43,15 @@ export async function handler({
43
43
  .eq("id", id)
44
44
  .single();
45
45
 
46
+ let { data: beatmapData, error: bmPageError } = await supabase
47
+ .from("beatmaps")
48
+ .select("*")
49
+ .eq("beatmapHash", beatmapHash)
50
+ .single();
51
+
46
52
  if (!userData) return NextResponse.json({ error: "No user." });
53
+ if (!beatmapData) return NextResponse.json({ error: "No beatmap." });
54
+
47
55
  if (userData.id !== pageData?.owner)
48
56
  return NextResponse.json({ error: "Non-authz user." });
49
57
 
@@ -52,6 +60,9 @@ export async function handler({
52
60
  .upsert({
53
61
  id,
54
62
  latestBeatmapHash: beatmapHash,
63
+ genre: "",
64
+ title: beatmapData.title,
65
+ status: "UNRANKED",
55
66
  owner: userData.id,
56
67
  })
57
68
  .select("*")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "117.0.0",
3
+ "version": "118.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",