settings now working

This commit is contained in:
2024-01-12 14:19:00 +01:00
parent 756ae1be58
commit 2c6b51cbb2
8 changed files with 159 additions and 41 deletions

View File

@@ -1,33 +0,0 @@
import axios from "axios";
import type { Error } from "../types/error";
import type { User } from "../types/user";
const loginCheckEndpoint = "https://ez-pp.farm/login/check";
let retries = 0;
export const performLogin = async (
username: string,
password: string,
): Promise<Error | User> => {
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
method: "POST",
mode: "cors",
body: JSON.stringify({ username, password }),
headers: {
"Content-Type": "application/json",
},
});
if (fetchResult.ok) {
const result = await fetchResult.json();
retries = 0;
return result.user;
} else {
if (retries++ >= 5) {
console.log("Login failed after 5 retries.");
retries = 0;
return { code: 403, message: "Login failed." } as Error;
}
return await performLogin(username, password);
}
};

View File

@@ -1,3 +1,3 @@
export const clamp = (val: number, min: number, max: number) => {
return val <= min ? min : val >= max ? max : val;
return Math.max(min, Math.min(val, max));
};

40
src/util/osuUtil.js Normal file
View File

@@ -0,0 +1,40 @@
const fs = require("fs");
const path = require("path");
const ignoredOsuEntities = [
"osu!auth.dll",
];
const osuEntities = [
"avcodec-51.dll",
"avformat-52.dll",
"avutil-49.dll",
"bass.dll",
"bass_fx.dll",
"collection.db",
"d3dcompiler_47.dll",
"libEGL.dll",
"libGLESv2.dll",
"Microsoft.Ink.dll",
"OpenTK.dll",
"osu!.cfg",
"osu!.db",
"osu!.exe",
"osu!auth.dll",
"osu!gameplay.dll",
"osu!seasonal.dll",
"osu!ui.dll",
"presence.db",
"pthreadGC2.dll",
"scores.db",
];
async function isValidOsuFolder(path) {
const allFiles = await fs.promises.readdir(path);
let matches = 0;
for (const file of allFiles) {
if (osuEntities.includes(file)) matches = matches + 1;
}
return (Math.round((matches / osuEntities.length) * 100) >= 60);
}
module.exports = { isValidOsuFolder };