rhythia-api 136.0.0 → 137.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.
- package/api/getBeatmaps.ts +13 -0
- package/package.json +1 -1
- package/scripts/test.ts +53 -24
- package/types/database.ts +6 -0
package/api/getBeatmaps.ts
CHANGED
|
@@ -7,6 +7,8 @@ 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(),
|
|
12
14
|
minStars: z.number().optional(),
|
|
@@ -36,6 +38,7 @@ export const Schema = {
|
|
|
36
38
|
ownerUsername: z.string().nullable().optional(),
|
|
37
39
|
ownerAvatar: z.string().nullable().optional(),
|
|
38
40
|
status: z.string().nullable().optional(),
|
|
41
|
+
tags: z.string().nullable().optional(),
|
|
39
42
|
})
|
|
40
43
|
)
|
|
41
44
|
.optional(),
|
|
@@ -75,6 +78,7 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
|
75
78
|
created_at,
|
|
76
79
|
id,
|
|
77
80
|
status,
|
|
81
|
+
tags,
|
|
78
82
|
beatmaps!inner(
|
|
79
83
|
playcount,
|
|
80
84
|
ranked,
|
|
@@ -94,6 +98,14 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
|
94
98
|
qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
|
|
95
99
|
}
|
|
96
100
|
|
|
101
|
+
if (data.authorFilter) {
|
|
102
|
+
qry = qry.ilike("profiles.username", `%${data.authorFilter}%`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (data.tagsFilter) {
|
|
106
|
+
qry = qry.ilike("tags", `%${data.tagsFilter}%`);
|
|
107
|
+
}
|
|
108
|
+
|
|
97
109
|
if (data.minStars) {
|
|
98
110
|
qry = qry.gt("beatmaps.starRating", data.minStars);
|
|
99
111
|
}
|
|
@@ -117,6 +129,7 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
|
117
129
|
currentPage: data.page,
|
|
118
130
|
beatmaps: queryData.data?.map((beatmapPage) => ({
|
|
119
131
|
id: beatmapPage.id,
|
|
132
|
+
tags: beatmapPage.tags,
|
|
120
133
|
playcount: beatmapPage.beatmaps?.playcount,
|
|
121
134
|
created_at: beatmapPage.created_at,
|
|
122
135
|
difficulty: beatmapPage.beatmaps?.difficulty,
|
package/package.json
CHANGED
package/scripts/test.ts
CHANGED
|
@@ -16,32 +16,61 @@ export const supabase = createClient<Database>(
|
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
async function main() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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: [
|