rhythia-api 116.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,31 +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;
70
- if (filter.length) {
71
- let { data: data, error } = await supabase
72
- .from("beatmapPages")
73
- .select(
74
- `
68
+ let qry = supabase
69
+ .from("beatmapPages")
70
+ .select(
71
+ `
75
72
  *,
76
- beatmaps (
73
+ beatmaps!inner(
77
74
  created_at,
78
75
  playcount,
79
76
  length,
@@ -85,48 +82,35 @@ export async function getBeatmaps(page = 1, session: string, filter: string) {
85
82
  noteCount,
86
83
  title
87
84
  ),
88
- profiles (
85
+ profiles!inner(
89
86
  username,
90
87
  avatar_url
91
88
  )`
92
- )
93
- .order("created_at", { ascending: false })
94
- .textSearch("beatmaps.title", filter)
95
- .range(startPage, endPage);
96
- queryData = data;
97
- } else {
98
- let { data: data, error } = await supabase
99
- .from("beatmapPages")
100
- .select(
101
- `
102
- *,
103
- beatmaps (
104
- created_at,
105
- playcount,
106
- length,
107
- ranked,
108
- beatmapFile,
109
- image,
110
- starRating,
111
- difficulty,
112
- noteCount,
113
- title
114
- ),
115
- profiles (
116
- username,
117
- avatar_url
118
- )`
119
- )
120
- .order("created_at", { ascending: false })
121
- .range(startPage, endPage);
122
- queryData = data;
89
+ )
90
+ .order("created_at", { ascending: false });
91
+
92
+ if (data.textFilter) {
93
+ qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
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);
123
102
  }
103
+ if (data.status) {
104
+ qry = qry.eq("status", data.status);
105
+ }
106
+
107
+ let queryData = await qry.range(startPage, endPage);
124
108
 
125
109
  return {
126
110
  total: countQuery.count || 0,
127
111
  viewPerPage: VIEW_PER_PAGE,
128
- currentPage: page,
129
- beatmaps: queryData?.map((beatmapPage) => ({
112
+ currentPage: data.page,
113
+ beatmaps: queryData.data?.map((beatmapPage) => ({
130
114
  id: beatmapPage.id,
131
115
  playcount: beatmapPage.beatmaps?.playcount,
132
116
  created_at: beatmapPage.created_at,
package/api/getProfile.ts CHANGED
@@ -16,6 +16,7 @@ export const Schema = {
16
16
  .object({
17
17
  about_me: z.string().nullable(),
18
18
  avatar_url: z.string().nullable(),
19
+ profile_image: z.string().nullable(),
19
20
  badges: z.any().nullable(),
20
21
  created_at: z.number().nullable(),
21
22
  flag: z.string().nullable(),
@@ -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": "116.0.0",
3
+ "version": "118.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
package/types/database.ts CHANGED
@@ -12,21 +12,30 @@ export type Database = {
12
12
  beatmapPages: {
13
13
  Row: {
14
14
  created_at: string
15
+ genre: string | null
15
16
  id: number
16
17
  latestBeatmapHash: string | null
17
18
  owner: number | null
19
+ status: string | null
20
+ title: string | null
18
21
  }
19
22
  Insert: {
20
23
  created_at?: string
24
+ genre?: string | null
21
25
  id?: number
22
26
  latestBeatmapHash?: string | null
23
27
  owner?: number | null
28
+ status?: string | null
29
+ title?: string | null
24
30
  }
25
31
  Update: {
26
32
  created_at?: string
33
+ genre?: string | null
27
34
  id?: number
28
35
  latestBeatmapHash?: string | null
29
36
  owner?: number | null
37
+ status?: string | null
38
+ title?: string | null
30
39
  }
31
40
  Relationships: [
32
41
  {
@@ -54,7 +63,6 @@ export type Database = {
54
63
  image: string | null
55
64
  length: number | null
56
65
  noteCount: number | null
57
- pageId: number | null
58
66
  playcount: number | null
59
67
  ranked: boolean | null
60
68
  starRating: number | null
@@ -68,7 +76,6 @@ export type Database = {
68
76
  image?: string | null
69
77
  length?: number | null
70
78
  noteCount?: number | null
71
- pageId?: number | null
72
79
  playcount?: number | null
73
80
  ranked?: boolean | null
74
81
  starRating?: number | null
@@ -82,21 +89,12 @@ export type Database = {
82
89
  image?: string | null
83
90
  length?: number | null
84
91
  noteCount?: number | null
85
- pageId?: number | null
86
92
  playcount?: number | null
87
93
  ranked?: boolean | null
88
94
  starRating?: number | null
89
95
  title?: string | null
90
96
  }
91
- Relationships: [
92
- {
93
- foreignKeyName: "beatmaps_pageId_fkey"
94
- columns: ["pageId"]
95
- isOneToOne: false
96
- referencedRelation: "beatmapPages"
97
- referencedColumns: ["id"]
98
- },
99
- ]
97
+ Relationships: []
100
98
  }
101
99
  profiles: {
102
100
  Row: {
@@ -110,6 +108,7 @@ export type Database = {
110
108
  flag: string | null
111
109
  id: number
112
110
  play_count: number | null
111
+ profile_image: string | null
113
112
  skill_points: number | null
114
113
  squares_hit: number | null
115
114
  total_score: number | null
@@ -128,6 +127,7 @@ export type Database = {
128
127
  flag?: string | null
129
128
  id?: number
130
129
  play_count?: number | null
130
+ profile_image?: string | null
131
131
  skill_points?: number | null
132
132
  squares_hit?: number | null
133
133
  total_score?: number | null
@@ -146,6 +146,7 @@ export type Database = {
146
146
  flag?: string | null
147
147
  id?: number
148
148
  play_count?: number | null
149
+ profile_image?: string | null
149
150
  skill_points?: number | null
150
151
  squares_hit?: number | null
151
152
  total_score?: number | null