rhythia-api 91.0.0 → 93.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/.prettierrc.json +6 -6
- package/api/editProfile.ts +74 -74
- package/api/getLeaderboard.ts +76 -76
- package/api/getProfile.ts +115 -115
- package/api/getPublicStats.ts +42 -42
- package/api/getUserScores.ts +84 -0
- package/api/searchUsers.ts +41 -41
- package/api/submitScore.ts +108 -106
- package/handleApi.ts +19 -19
- package/index.html +2 -2
- package/index.ts +14 -9
- package/package.json +1 -1
- package/scripts/ci-deploy.ts +76 -76
- package/scripts/update.ts +49 -49
- package/types/database.ts +6 -3
- package/utils/requestUtils.ts +55 -55
- package/utils/supabase.ts +13 -13
- package/vercel.json +12 -12
package/scripts/update.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { $ } from "bun";
|
|
2
|
-
import { readdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
-
import { lowerFirst, upperFirst } from "lodash";
|
|
4
|
-
import path from "path";
|
|
5
|
-
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
|
|
6
|
-
|
|
7
|
-
const versions = packageJson.version.split(".");
|
|
8
|
-
versions[0] = Number(versions[0]) + 1;
|
|
9
|
-
|
|
10
|
-
packageJson.version = versions.join(".");
|
|
11
|
-
|
|
12
|
-
writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
|
|
13
|
-
|
|
14
|
-
const apis = readdirSync("./api");
|
|
15
|
-
|
|
16
|
-
const exports: string[] = [];
|
|
17
|
-
exports.push(`import { handleApi } from "./handleApi"`);
|
|
18
|
-
|
|
19
|
-
for (const api of apis) {
|
|
20
|
-
if (
|
|
21
|
-
!readFileSync(path.join("./api", api), "utf-8").includes(
|
|
22
|
-
"export const Schema"
|
|
23
|
-
)
|
|
24
|
-
) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
exports.push(`\n// ./api/${api} API`);
|
|
28
|
-
|
|
29
|
-
const apiName = path.parse(api).name;
|
|
30
|
-
exports.push(
|
|
31
|
-
`import { Schema as ${upperFirst(apiName)} } from "./api/${apiName}"`
|
|
32
|
-
);
|
|
33
|
-
exports.push(
|
|
34
|
-
`export { Schema as Schema${upperFirst(apiName)} } from "./api/${apiName}"`
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
exports.push(
|
|
38
|
-
`export const ${lowerFirst(
|
|
39
|
-
apiName
|
|
40
|
-
)} = handleApi({url:"/api/${apiName}",...${upperFirst(apiName)}})`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
exports.push(`export { handleApi } from "./handleApi"`);
|
|
44
|
-
|
|
45
|
-
writeFileSync("./index.ts", exports.join("\n"));
|
|
46
|
-
|
|
47
|
-
// const conf = readFileSync("./.cred", "utf-8");
|
|
48
|
-
// await $`npm logout`.nothrow();
|
|
49
|
-
await $`yarn publish`;
|
|
1
|
+
import { $ } from "bun";
|
|
2
|
+
import { readdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { lowerFirst, upperFirst } from "lodash";
|
|
4
|
+
import path from "path";
|
|
5
|
+
const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
|
|
6
|
+
|
|
7
|
+
const versions = packageJson.version.split(".");
|
|
8
|
+
versions[0] = Number(versions[0]) + 1;
|
|
9
|
+
|
|
10
|
+
packageJson.version = versions.join(".");
|
|
11
|
+
|
|
12
|
+
writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
|
|
13
|
+
|
|
14
|
+
const apis = readdirSync("./api");
|
|
15
|
+
|
|
16
|
+
const exports: string[] = [];
|
|
17
|
+
exports.push(`import { handleApi } from "./handleApi"`);
|
|
18
|
+
|
|
19
|
+
for (const api of apis) {
|
|
20
|
+
if (
|
|
21
|
+
!readFileSync(path.join("./api", api), "utf-8").includes(
|
|
22
|
+
"export const Schema"
|
|
23
|
+
)
|
|
24
|
+
) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
exports.push(`\n// ./api/${api} API`);
|
|
28
|
+
|
|
29
|
+
const apiName = path.parse(api).name;
|
|
30
|
+
exports.push(
|
|
31
|
+
`import { Schema as ${upperFirst(apiName)} } from "./api/${apiName}"`
|
|
32
|
+
);
|
|
33
|
+
exports.push(
|
|
34
|
+
`export { Schema as Schema${upperFirst(apiName)} } from "./api/${apiName}"`
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
exports.push(
|
|
38
|
+
`export const ${lowerFirst(
|
|
39
|
+
apiName
|
|
40
|
+
)} = handleApi({url:"/api/${apiName}",...${upperFirst(apiName)}})`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
exports.push(`export { handleApi } from "./handleApi"`);
|
|
44
|
+
|
|
45
|
+
writeFileSync("./index.ts", exports.join("\n"));
|
|
46
|
+
|
|
47
|
+
// const conf = readFileSync("./.cred", "utf-8");
|
|
48
|
+
// await $`npm logout`.nothrow();
|
|
49
|
+
await $`yarn publish`;
|
package/types/database.ts
CHANGED
|
@@ -97,39 +97,42 @@ export type Database = {
|
|
|
97
97
|
}
|
|
98
98
|
scores: {
|
|
99
99
|
Row: {
|
|
100
|
+
awarded_sp: number | null
|
|
100
101
|
beatmapHash: string | null
|
|
101
102
|
created_at: string
|
|
102
103
|
id: number
|
|
103
104
|
misses: number | null
|
|
104
105
|
noteResults: Json | null
|
|
105
106
|
passed: boolean | null
|
|
106
|
-
|
|
107
|
+
rank: string | null
|
|
107
108
|
replayHwid: string | null
|
|
108
109
|
songId: string | null
|
|
109
110
|
triggers: Json | null
|
|
110
111
|
userId: number | null
|
|
111
112
|
}
|
|
112
113
|
Insert: {
|
|
114
|
+
awarded_sp?: number | null
|
|
113
115
|
beatmapHash?: string | null
|
|
114
116
|
created_at?: string
|
|
115
117
|
id?: number
|
|
116
118
|
misses?: number | null
|
|
117
119
|
noteResults?: Json | null
|
|
118
120
|
passed?: boolean | null
|
|
119
|
-
|
|
121
|
+
rank?: string | null
|
|
120
122
|
replayHwid?: string | null
|
|
121
123
|
songId?: string | null
|
|
122
124
|
triggers?: Json | null
|
|
123
125
|
userId?: number | null
|
|
124
126
|
}
|
|
125
127
|
Update: {
|
|
128
|
+
awarded_sp?: number | null
|
|
126
129
|
beatmapHash?: string | null
|
|
127
130
|
created_at?: string
|
|
128
131
|
id?: number
|
|
129
132
|
misses?: number | null
|
|
130
133
|
noteResults?: Json | null
|
|
131
134
|
passed?: boolean | null
|
|
132
|
-
|
|
135
|
+
rank?: string | null
|
|
133
136
|
replayHwid?: string | null
|
|
134
137
|
songId?: string | null
|
|
135
138
|
triggers?: Json | null
|
package/utils/requestUtils.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import { supabase } from "./supabase";
|
|
3
|
-
import { ZodObject } from "zod";
|
|
4
|
-
|
|
5
|
-
interface Props<
|
|
6
|
-
K = (...args: any[]) => Promise<NextResponse<any>>,
|
|
7
|
-
T = ZodObject<any>
|
|
8
|
-
> {
|
|
9
|
-
request: Request;
|
|
10
|
-
schema: { input: T; output: T };
|
|
11
|
-
authorization?: Function;
|
|
12
|
-
activity: K;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function protectedApi({
|
|
16
|
-
request,
|
|
17
|
-
schema,
|
|
18
|
-
authorization,
|
|
19
|
-
activity,
|
|
20
|
-
}: Props) {
|
|
21
|
-
try {
|
|
22
|
-
const toParse = await request.json();
|
|
23
|
-
const data = schema.input.parse(toParse);
|
|
24
|
-
if (authorization) {
|
|
25
|
-
const authorizationResponse = await authorization(data);
|
|
26
|
-
if (authorizationResponse) {
|
|
27
|
-
return authorizationResponse;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return await activity(data, request);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
return NextResponse.json({ error: error.toString() }, { status: 400 });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function validUser(data) {
|
|
37
|
-
if (!data.session) {
|
|
38
|
-
return NextResponse.json(
|
|
39
|
-
{
|
|
40
|
-
error: "Session is missing",
|
|
41
|
-
},
|
|
42
|
-
{ status: 501 }
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const user = await supabase.auth.getUser(data.session);
|
|
47
|
-
if (user.error || !user.data.user) {
|
|
48
|
-
return NextResponse.json(
|
|
49
|
-
{
|
|
50
|
-
error: "Invalid user session",
|
|
51
|
-
},
|
|
52
|
-
{ status: 400 }
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import { supabase } from "./supabase";
|
|
3
|
+
import { ZodObject } from "zod";
|
|
4
|
+
|
|
5
|
+
interface Props<
|
|
6
|
+
K = (...args: any[]) => Promise<NextResponse<any>>,
|
|
7
|
+
T = ZodObject<any>
|
|
8
|
+
> {
|
|
9
|
+
request: Request;
|
|
10
|
+
schema: { input: T; output: T };
|
|
11
|
+
authorization?: Function;
|
|
12
|
+
activity: K;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function protectedApi({
|
|
16
|
+
request,
|
|
17
|
+
schema,
|
|
18
|
+
authorization,
|
|
19
|
+
activity,
|
|
20
|
+
}: Props) {
|
|
21
|
+
try {
|
|
22
|
+
const toParse = await request.json();
|
|
23
|
+
const data = schema.input.parse(toParse);
|
|
24
|
+
if (authorization) {
|
|
25
|
+
const authorizationResponse = await authorization(data);
|
|
26
|
+
if (authorizationResponse) {
|
|
27
|
+
return authorizationResponse;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return await activity(data, request);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return NextResponse.json({ error: error.toString() }, { status: 400 });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function validUser(data) {
|
|
37
|
+
if (!data.session) {
|
|
38
|
+
return NextResponse.json(
|
|
39
|
+
{
|
|
40
|
+
error: "Session is missing",
|
|
41
|
+
},
|
|
42
|
+
{ status: 501 }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const user = await supabase.auth.getUser(data.session);
|
|
47
|
+
if (user.error || !user.data.user) {
|
|
48
|
+
return NextResponse.json(
|
|
49
|
+
{
|
|
50
|
+
error: "Invalid user session",
|
|
51
|
+
},
|
|
52
|
+
{ status: 400 }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/utils/supabase.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createClient } from "@supabase/supabase-js";
|
|
2
|
-
import { Database } from "../types/database";
|
|
3
|
-
|
|
4
|
-
export const supabase = createClient<Database>(
|
|
5
|
-
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
6
|
-
process.env.ADMIN_KEY || "key",
|
|
7
|
-
{
|
|
8
|
-
auth: {
|
|
9
|
-
autoRefreshToken: false,
|
|
10
|
-
persistSession: false,
|
|
11
|
-
},
|
|
12
|
-
}
|
|
13
|
-
);
|
|
1
|
+
import { createClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/database";
|
|
3
|
+
|
|
4
|
+
export const supabase = createClient<Database>(
|
|
5
|
+
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
6
|
+
process.env.ADMIN_KEY || "key",
|
|
7
|
+
{
|
|
8
|
+
auth: {
|
|
9
|
+
autoRefreshToken: false,
|
|
10
|
+
persistSession: false,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
);
|
package/vercel.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"headers": [
|
|
3
|
-
{
|
|
4
|
-
"source": "/api/(.*)",
|
|
5
|
-
"headers": [
|
|
6
|
-
{ "key": "Access-Control-Allow-Credentials", "value": "true" },
|
|
7
|
-
{ "key": "Access-Control-Allow-Origin", "value": "*" },
|
|
8
|
-
{ "key": "Access-Control-Allow-Methods", "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
|
|
9
|
-
{ "key": "Access-Control-Allow-Headers", "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" }
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"headers": [
|
|
3
|
+
{
|
|
4
|
+
"source": "/api/(.*)",
|
|
5
|
+
"headers": [
|
|
6
|
+
{ "key": "Access-Control-Allow-Credentials", "value": "true" },
|
|
7
|
+
{ "key": "Access-Control-Allow-Origin", "value": "*" },
|
|
8
|
+
{ "key": "Access-Control-Allow-Methods", "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
|
|
9
|
+
{ "key": "Access-Control-Allow-Headers", "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
13
|
}
|