rhythia-api 115.0.0 → 117.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.
@@ -6,6 +6,7 @@ import { supabase } from "../utils/supabase";
6
6
  export const Schema = {
7
7
  input: z.strictObject({
8
8
  session: z.string(),
9
+ textFilter: z.string().optional(),
9
10
  page: z.number().default(1),
10
11
  }),
11
12
  output: z.object({
@@ -48,23 +49,84 @@ export async function POST(request: Request): Promise<NextResponse> {
48
49
  export async function handler(
49
50
  data: (typeof Schema)["input"]["_type"]
50
51
  ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
51
- const result = await getBeatmaps(data.page, data.session);
52
+ const result = await getBeatmaps(
53
+ data.page,
54
+ data.session,
55
+ data.textFilter || ""
56
+ );
52
57
  return NextResponse.json(result);
53
58
  }
54
59
 
55
60
  const VIEW_PER_PAGE = 50;
56
61
 
57
- export async function getBeatmaps(page = 1, session: string) {
62
+ export async function getBeatmaps(page = 1, session: string, filter: string) {
58
63
  const startPage = (page - 1) * VIEW_PER_PAGE;
59
64
  const endPage = startPage + VIEW_PER_PAGE - 1;
60
65
  const countQuery = await supabase
61
66
  .from("beatmapPages")
62
67
  .select("*", { count: "exact", head: true });
63
68
 
64
- let { data: queryData, error } = await supabase
65
- .from("beatmapPages")
66
- .select(
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
+ `
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
+ .ilike("beatmaps.title", `%${filter}%`)
122
+ .range(startPage, endPage);
123
+
124
+ return data;
125
+ } else {
126
+ let { data: data, error } = await supabase
127
+ .from("beatmapPages")
128
+ .select(
129
+ `
68
130
  *,
69
131
  beatmaps (
70
132
  created_at,
@@ -82,28 +144,9 @@ export async function getBeatmaps(page = 1, session: string) {
82
144
  username,
83
145
  avatar_url
84
146
  )`
85
- )
86
- .range(startPage, endPage);
87
-
88
- return {
89
- total: countQuery.count || 0,
90
- viewPerPage: VIEW_PER_PAGE,
91
- currentPage: page,
92
- beatmaps: queryData?.map((beatmapPage) => ({
93
- id: beatmapPage.id,
94
- playcount: beatmapPage.beatmaps?.playcount,
95
- created_at: beatmapPage.created_at,
96
- difficulty: beatmapPage.beatmaps?.difficulty,
97
- noteCount: beatmapPage.beatmaps?.noteCount,
98
- length: beatmapPage.beatmaps?.length,
99
- title: beatmapPage.beatmaps?.title,
100
- ranked: beatmapPage.beatmaps?.ranked,
101
- beatmapFile: beatmapPage.beatmaps?.beatmapFile,
102
- image: beatmapPage.beatmaps?.image,
103
- starRating: beatmapPage.beatmaps?.starRating,
104
- owner: beatmapPage.owner,
105
- ownerUsername: beatmapPage.profiles?.username,
106
- ownerAvatar: beatmapPage.profiles?.avatar_url,
107
- })),
108
- };
147
+ )
148
+ .order("created_at", { ascending: false })
149
+ .range(startPage, endPage);
150
+ return data;
151
+ }
109
152
  }
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(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "115.0.0",
3
+ "version": "117.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