rhythia-api 136.0.0 → 138.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.
@@ -7,8 +7,12 @@ export const Schema = {
7
7
  input: z.strictObject({
8
8
  session: z.string(),
9
9
  textFilter: z.string().optional(),
10
+ authorFilter: z.string().optional(),
11
+ tagsFilter: z.string().optional(),
10
12
  page: z.number().default(1),
11
13
  maxStars: z.number().optional(),
14
+ minLength: z.number().optional(),
15
+ maxLength: z.number().optional(),
12
16
  minStars: z.number().optional(),
13
17
  creator: z.number().optional(),
14
18
  status: z.string().optional(),
@@ -36,6 +40,7 @@ export const Schema = {
36
40
  ownerUsername: z.string().nullable().optional(),
37
41
  ownerAvatar: z.string().nullable().optional(),
38
42
  status: z.string().nullable().optional(),
43
+ tags: z.string().nullable().optional(),
39
44
  })
40
45
  )
41
46
  .optional(),
@@ -75,6 +80,7 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
75
80
  created_at,
76
81
  id,
77
82
  status,
83
+ tags,
78
84
  beatmaps!inner(
79
85
  playcount,
80
86
  ranked,
@@ -82,6 +88,7 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
82
88
  image,
83
89
  starRating,
84
90
  difficulty,
91
+ length,
85
92
  title
86
93
  ),
87
94
  profiles!inner(
@@ -94,6 +101,14 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
94
101
  qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
95
102
  }
96
103
 
104
+ if (data.authorFilter) {
105
+ qry = qry.ilike("profiles.username", `%${data.authorFilter}%`);
106
+ }
107
+
108
+ if (data.tagsFilter) {
109
+ qry = qry.ilike("tags", `%${data.tagsFilter}%`);
110
+ }
111
+
97
112
  if (data.minStars) {
98
113
  qry = qry.gt("beatmaps.starRating", data.minStars);
99
114
  }
@@ -101,6 +116,15 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
101
116
  if (data.maxStars) {
102
117
  qry = qry.lt("beatmaps.starRating", data.maxStars);
103
118
  }
119
+
120
+ if (data.minLength) {
121
+ qry = qry.gt("beatmaps.length", data.minLength);
122
+ }
123
+
124
+ if (data.maxLength) {
125
+ qry = qry.lt("beatmaps.length", data.maxLength);
126
+ }
127
+
104
128
  if (data.status) {
105
129
  qry = qry.eq("status", data.status);
106
130
  }
@@ -117,11 +141,13 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
117
141
  currentPage: data.page,
118
142
  beatmaps: queryData.data?.map((beatmapPage) => ({
119
143
  id: beatmapPage.id,
144
+ tags: beatmapPage.tags,
120
145
  playcount: beatmapPage.beatmaps?.playcount,
121
146
  created_at: beatmapPage.created_at,
122
147
  difficulty: beatmapPage.beatmaps?.difficulty,
123
148
  title: beatmapPage.beatmaps?.title,
124
149
  ranked: beatmapPage.beatmaps?.ranked,
150
+ length: beatmapPage.beatmaps?.length,
125
151
  beatmapFile: beatmapPage.beatmaps?.beatmapFile,
126
152
  image: beatmapPage.beatmaps?.image,
127
153
  starRating: beatmapPage.beatmaps?.starRating,
@@ -8,6 +8,8 @@ export const Schema = {
8
8
  session: z.string(),
9
9
  id: z.number(),
10
10
  beatmapHash: z.string(),
11
+ tags: z.string(),
12
+ description: z.string(),
11
13
  }),
12
14
  output: z.strictObject({
13
15
  error: z.string().optional(),
@@ -27,6 +29,8 @@ export async function handler({
27
29
  session,
28
30
  beatmapHash,
29
31
  id,
32
+ description,
33
+ tags,
30
34
  }: (typeof Schema)["input"]["_type"]): Promise<
31
35
  NextResponse<(typeof Schema)["output"]["_type"]>
32
36
  > {
@@ -64,6 +68,8 @@ export async function handler({
64
68
  title: beatmapData.title,
65
69
  status: "UNRANKED",
66
70
  owner: userData.id,
71
+ description,
72
+ tags,
67
73
  })
68
74
  .select("*")
69
75
  .single();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "136.0.0",
3
+ "version": "138.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
package/scripts/test.ts CHANGED
@@ -16,32 +16,61 @@ export const supabase = createClient<Database>(
16
16
  );
17
17
 
18
18
  async function main() {
19
- const req = await fetch(`https://cdn.rhythia.net/index.json`);
20
- const json = Object.values(await req.json()) as any[];
21
- console.log(json[0]);
19
+ let qry = supabase
20
+ .from("beatmapPages")
21
+ .select(
22
+ `
23
+ owner,
24
+ created_at,
25
+ id,
26
+ status,
27
+ beatmaps!inner(
28
+ playcount,
29
+ ranked,
30
+ beatmapFile,
31
+ image,
32
+ starRating,
33
+ difficulty,
34
+ title
35
+ ),
36
+ profiles!inner(
37
+ username
38
+ )`
39
+ )
40
+ .order("created_at", { ascending: false });
22
41
 
23
- let count = 0;
24
- for (const map of json) {
25
- const request = await fetch(map.download);
26
- const bytes = await request.arrayBuffer();
27
- const parser = new SSPMParser(Buffer.from(bytes));
28
- let rate = 0;
29
- try {
30
- const data = parser.parse();
31
- rate = rateMap(data);
32
- } catch (error) {
33
- const parserOld = new V1SSPMParser(Buffer.from(bytes));
34
- const data = parserOld.parse();
42
+ qry = qry.ilike("beatmaps.title", "%Ca%");
43
+ qry = qry.ilike("profiles.username", "%Ca%");
35
44
 
36
- rate = rateMapOld(data);
37
- }
38
- await supabase.from("beatmaps").upsert({
39
- beatmapHash: map.id,
40
- starRating: rate,
41
- });
42
- count++;
43
- console.log(count, json.length, map.id, rate);
44
- }
45
+ const data = await qry;
46
+ console.log(data);
47
+ // console.log(data.data[]);
48
+ // const req = await fetch(`https://cdn.rhythia.net/index.json`);
49
+ // const json = Object.values(await req.json()) as any[];
50
+ // console.log(json[0]);
51
+
52
+ // let count = 0;
53
+ // for (const map of json) {
54
+ // const request = await fetch(map.download);
55
+ // const bytes = await request.arrayBuffer();
56
+ // const parser = new SSPMParser(Buffer.from(bytes));
57
+ // let rate = 0;
58
+ // try {
59
+ // const data = parser.parse();
60
+ // rate = rateMap(data);
61
+ // } catch (error) {
62
+ // const parserOld = new V1SSPMParser(Buffer.from(bytes));
63
+ // const data = parserOld.parse();
64
+
65
+ // rate = rateMapOld(data);
66
+ // }
67
+ // await supabase.from("beatmaps").upsert({
68
+ // beatmapHash: map.id,
69
+ // starRating: rate,
70
+ // });
71
+ // count++;
72
+ // console.log(count, json.length, map.id, rate);
73
+ // }
45
74
  // for (const map of json) {
46
75
  // const reqMap = await fetch(map.link);
47
76
  // const buff = await reqMap.arrayBuffer();
package/types/database.ts CHANGED
@@ -51,32 +51,38 @@ export type Database = {
51
51
  beatmapPages: {
52
52
  Row: {
53
53
  created_at: string
54
+ description: string
54
55
  genre: string | null
55
56
  id: number
56
57
  latestBeatmapHash: string | null
57
58
  nominations: Json | null
58
59
  owner: number | null
59
60
  status: string | null
61
+ tags: string
60
62
  title: string | null
61
63
  }
62
64
  Insert: {
63
65
  created_at?: string
66
+ description?: string
64
67
  genre?: string | null
65
68
  id?: number
66
69
  latestBeatmapHash?: string | null
67
70
  nominations?: Json | null
68
71
  owner?: number | null
69
72
  status?: string | null
73
+ tags?: string
70
74
  title?: string | null
71
75
  }
72
76
  Update: {
73
77
  created_at?: string
78
+ description?: string
74
79
  genre?: string | null
75
80
  id?: number
76
81
  latestBeatmapHash?: string | null
77
82
  nominations?: Json | null
78
83
  owner?: number | null
79
84
  status?: string | null
85
+ tags?: string
80
86
  title?: string | null
81
87
  }
82
88
  Relationships: [