rhythia-api 139.0.0 → 141.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.
@@ -18,6 +18,7 @@ export const Schema = {
18
18
  input: z.strictObject({
19
19
  url: z.string(),
20
20
  session: z.string(),
21
+ updateFlag: z.boolean().optional(),
21
22
  }),
22
23
  output: z.strictObject({
23
24
  hash: z.string().optional(),
@@ -36,6 +37,8 @@ export async function POST(request: Request): Promise<NextResponse> {
36
37
 
37
38
  export async function handler({
38
39
  url,
40
+ session,
41
+ updateFlag,
39
42
  }: (typeof Schema)["input"]["_type"]): Promise<
40
43
  NextResponse<(typeof Schema)["output"]["_type"]>
41
44
  > {
@@ -49,6 +52,17 @@ export async function handler({
49
52
  const parsedData = parser.parse();
50
53
  const digested = parsedData.strings.mapID;
51
54
 
55
+ const user = (await supabase.auth.getUser(session)).data.user!;
56
+ let { data: userData, error: userError } = await supabase
57
+ .from("profiles")
58
+ .select("*")
59
+ .eq("uid", user.id)
60
+ .single();
61
+
62
+ if (!userData) {
63
+ return NextResponse.json({ error: "Bad user" });
64
+ }
65
+
52
66
  let { data: beatmapPage, error: errorlast } = await supabase
53
67
  .from("beatmapPages")
54
68
  .select(`*`)
@@ -56,7 +70,11 @@ export async function handler({
56
70
  .single();
57
71
 
58
72
  if (beatmapPage) {
59
- return NextResponse.json({ error: "Already Exists" });
73
+ if (!updateFlag) {
74
+ return NextResponse.json({ error: "Already Exists" });
75
+ } else if (beatmapPage.owner !== userData.id) {
76
+ return NextResponse.json({ error: "Already Exists" });
77
+ }
60
78
  }
61
79
 
62
80
  const imgkey = `beatmap-img-${Date.now()}-${digested}`;
@@ -46,7 +46,7 @@ export async function handler({
46
46
  let { data: beatmapData, error: bmPageError } = await supabase
47
47
  .from("beatmaps")
48
48
  .select("*")
49
- .eq("beatmapHash", pageData.id)
49
+ .eq("beatmapHash", pageData.latestBeatmapHash || "-1-1-1-1")
50
50
  .single();
51
51
 
52
52
  if (!userData) return NextResponse.json({ error: "No user." });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "139.0.0",
3
+ "version": "141.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
@@ -1,76 +0,0 @@
1
- import fs from "fs";
2
- import * as git from "isomorphic-git";
3
- import http from "isomorphic-git/http/node";
4
- import path from "path";
5
-
6
- // Set up the repository URL
7
- const repoUrl = `https://${process.env.GIT_KEY}@github.com/cunev/rhythia-api.git`;
8
-
9
- const sourceBranch = process.env.SOURCE_BRANCH!;
10
- const targetBranch = process.env.TARGET_BRANCH!;
11
-
12
- async function cloneBranch() {
13
- const dir = path.join("/tmp", "repo");
14
-
15
- try {
16
- // Ensure the directory is clean before cloning
17
- if (fs.existsSync(dir)) {
18
- fs.rmdirSync(dir, { recursive: true });
19
- console.log(`Deleted existing directory: ${dir}`);
20
- }
21
-
22
- // Clone the repository into a temporary directory
23
- await git.clone({
24
- fs,
25
- http,
26
- dir,
27
- url: repoUrl,
28
- ref: sourceBranch,
29
- singleBranch: true,
30
- depth: 1,
31
- });
32
- console.log(`Cloned ${sourceBranch} branch from remote repository.`);
33
-
34
- // Check out the source branch
35
- await git.checkout({ fs, dir, ref: sourceBranch });
36
- console.log(`Checked out to branch: ${sourceBranch}`);
37
-
38
- // Pull the latest changes from the source branch
39
- await git.pull({
40
- fs,
41
- http,
42
- dir,
43
- ref: sourceBranch,
44
- singleBranch: true,
45
- author: {
46
- name: process.env.GIT_USER,
47
- email: "you@example.com", // Replace with the actual email
48
- },
49
- });
50
- console.log(`Pulled latest changes from branch: ${sourceBranch}`);
51
-
52
- // Create and checkout the target branch from the source branch
53
- await git.branch({ fs, dir, ref: targetBranch });
54
- await git.checkout({ fs, dir, ref: targetBranch });
55
- console.log(`Created and checked out to branch: ${targetBranch}`);
56
-
57
- // Push the new branch to the remote repository
58
- await git.push({
59
- fs,
60
- http,
61
- dir,
62
- remote: "origin",
63
- ref: targetBranch,
64
- force: true,
65
- onAuth: () => ({
66
- username: process.env.GIT_KEY, // GitHub token or password
67
- password: "",
68
- }),
69
- });
70
- console.log(`Pushed new branch to remote: ${targetBranch}`);
71
- } catch (error) {
72
- console.error("Error performing Git operations:", error.message);
73
- }
74
- }
75
-
76
- cloneBranch();
package/scripts/test.ts DELETED
@@ -1,96 +0,0 @@
1
- import { createClient } from "@supabase/supabase-js";
2
- import { Database } from "../types/database";
3
- import { SSPMParser } from "../utils/star-calc/sspmParser";
4
- import { rateMap, rateMapOld } from "../utils/star-calc";
5
- import { V1SSPMParser } from "../utils/star-calc/sspmv1Parser";
6
-
7
- export const supabase = createClient<Database>(
8
- `https://pfkajngbllcbdzoylrvp.supabase.co`,
9
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InBma2FqbmdibGxjYmR6b3lscnZwIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcxODU3NjA3MCwiZXhwIjoyMDM0MTUyMDcwfQ.XKUlQWvzmcYyirM-Zi4nwhiEKcpx1xLS97QUyuR3MoY",
10
- {
11
- auth: {
12
- autoRefreshToken: false,
13
- persistSession: false,
14
- },
15
- }
16
- );
17
-
18
- async function main() {
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 });
41
-
42
- qry = qry.ilike("beatmaps.title", "%Ca%");
43
- qry = qry.ilike("profiles.username", "%Ca%");
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
- // }
74
- // for (const map of json) {
75
- // const reqMap = await fetch(map.link);
76
- // const buff = await reqMap.arrayBuffer();
77
- // writeFileSync("./toSubmit/" + map.id + ".sspm", Buffer.from(buff));
78
- // }
79
-
80
- // const { data: mapData, error } = await supabase
81
- // .from("beatmapPages")
82
- // .select("id,nominations,owner,status")
83
- // .eq("owner", 10)
84
- // .eq("status", "RANKED");
85
-
86
- // if (!mapData) {
87
- // throw "lolz";
88
- // }
89
-
90
- // for (const element of mapData) {
91
-
92
- // console.log(data.error);
93
- // }
94
- }
95
-
96
- main();
package/scripts/update.ts DELETED
@@ -1,49 +0,0 @@
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`;