rhythia-api 117.0.0 → 119.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,10 @@ 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
+ creator: z.string().optional(),
14
+ status: z.string().optional(),
11
15
  }),
12
16
  output: z.object({
13
17
  error: z.string().optional(),
@@ -49,58 +53,25 @@ export async function POST(request: Request): Promise<NextResponse> {
49
53
  export async function handler(
50
54
  data: (typeof Schema)["input"]["_type"]
51
55
  ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
52
- const result = await getBeatmaps(
53
- data.page,
54
- data.session,
55
- data.textFilter || ""
56
- );
56
+ const result = await getBeatmaps(data);
57
57
  return NextResponse.json(result);
58
58
  }
59
59
 
60
60
  const VIEW_PER_PAGE = 50;
61
61
 
62
- export async function getBeatmaps(page = 1, session: string, filter: string) {
63
- const startPage = (page - 1) * VIEW_PER_PAGE;
62
+ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
63
+ const startPage = (data.page - 1) * VIEW_PER_PAGE;
64
64
  const endPage = startPage + VIEW_PER_PAGE - 1;
65
65
  const countQuery = await supabase
66
66
  .from("beatmapPages")
67
67
  .select("*", { count: "exact", head: true });
68
68
 
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
- `
69
+ let qry = supabase
70
+ .from("beatmapPages")
71
+ .select(
72
+ `
102
73
  *,
103
- beatmaps (
74
+ beatmaps!inner(
104
75
  created_at,
105
76
  playcount,
106
77
  length,
@@ -112,41 +83,53 @@ async function getQuery(startPage: number, endPage: number, filter: string) {
112
83
  noteCount,
113
84
  title
114
85
  ),
115
- profiles (
86
+ profiles!inner(
116
87
  username,
117
88
  avatar_url
118
89
  )`
119
- )
120
- .order("created_at", { ascending: false })
121
- .ilike("beatmaps.title", `%${filter}%`)
122
- .range(startPage, endPage);
90
+ )
91
+ .order("created_at", { ascending: false });
123
92
 
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;
93
+ if (data.textFilter) {
94
+ qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
95
+ }
96
+
97
+ if (data.minStars) {
98
+ qry = qry.gt("beatmaps.starRating", data.minStars);
151
99
  }
100
+
101
+ if (data.maxStars) {
102
+ qry = qry.lt("beatmaps.starRating", data.maxStars);
103
+ }
104
+ if (data.status) {
105
+ qry = qry.eq("status", data.status);
106
+ }
107
+
108
+ if (data.creator) {
109
+ qry = qry.eq("creator", data.creator);
110
+ }
111
+
112
+ let queryData = await qry.range(startPage, endPage);
113
+
114
+ return {
115
+ total: countQuery.count || 0,
116
+ viewPerPage: VIEW_PER_PAGE,
117
+ currentPage: data.page,
118
+ beatmaps: queryData.data?.map((beatmapPage) => ({
119
+ id: beatmapPage.id,
120
+ playcount: beatmapPage.beatmaps?.playcount,
121
+ created_at: beatmapPage.created_at,
122
+ difficulty: beatmapPage.beatmaps?.difficulty,
123
+ noteCount: beatmapPage.beatmaps?.noteCount,
124
+ length: beatmapPage.beatmaps?.length,
125
+ title: beatmapPage.beatmaps?.title,
126
+ ranked: beatmapPage.beatmaps?.ranked,
127
+ beatmapFile: beatmapPage.beatmaps?.beatmapFile,
128
+ image: beatmapPage.beatmaps?.image,
129
+ starRating: beatmapPage.beatmaps?.starRating,
130
+ owner: beatmapPage.owner,
131
+ ownerUsername: beatmapPage.profiles?.username,
132
+ ownerAvatar: beatmapPage.profiles?.avatar_url,
133
+ })),
134
+ };
152
135
  }
@@ -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": "119.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",