1 Commits

Author SHA1 Message Date
7c0c32dab3 chore(deps): update nextjs monorepo to v14 2023-10-26 17:01:51 +00:00
9 changed files with 394 additions and 367 deletions

View File

@ -1,10 +1,10 @@
REACT_APP_HTTP_PROXY=<https://proxy.fascinated.cc>
REACT_APP_HTTP_PROXY=https://proxy.fascinated.cc
REACT_APP_SITE_NAME=BeatSaber Overlay
REACT_APP_SITE_TITLE=BeatSaber Overlay - Simple and easy to use BeatSaber overlay
REACT_APP_SITE_DESCRIPTION=ScoreSaber and BeatLeader overlay for Twitch streamers - Elevate your Beat Saber streams with our professional, customizable overlay that displays your real-time scores, rankings, and leaderboard information for your viewers.
REACT_APP_SITE_COLOR=0EBFE9
REACT_APP_SITE_URL=<http://localhost:3000>
REACT_APP_SITE_URL=http://localhost:3000
REDIS_PORT=6379
REDIS_HOST=localhost

View File

@ -20,7 +20,7 @@
"core-js-pure": "^3.33.0",
"critters": "^0.0.20",
"ioredis": "^5.3.2",
"next": "^13.5.4",
"next": "^14.0.0",
"next-seo": "^6.1.0",
"next-themes": "^0.2.1",
"prop-types": "^15.8.1",
@ -37,7 +37,7 @@
"@types/react": "^18.2.28",
"@types/websocket": "^1.0.7",
"eslint": "^8.51.0",
"eslint-config-next": "^13.5.4",
"eslint-config-next": "^14.0.0",
"npm-check": "^6.0.1",
"typescript": "^5.2.2"
}

96
pnpm-lock.yaml generated
View File

@ -39,14 +39,14 @@ dependencies:
specifier: ^5.3.2
version: 5.3.2
next:
specifier: ^13.5.4
version: 13.5.4(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)
specifier: ^14.0.0
version: 14.0.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)
next-seo:
specifier: ^6.1.0
version: 6.1.0(next@13.5.4)(react-dom@18.2.0)(react@18.2.0)
version: 6.1.0(next@14.0.0)(react-dom@18.2.0)(react@18.2.0)
next-themes:
specifier: ^0.2.1
version: 0.2.1(next@13.5.4)(react-dom@18.2.0)(react@18.2.0)
version: 0.2.1(next@14.0.0)(react-dom@18.2.0)(react@18.2.0)
prop-types:
specifier: ^15.8.1
version: 15.8.1
@ -86,8 +86,8 @@ devDependencies:
specifier: ^8.51.0
version: 8.51.0
eslint-config-next:
specifier: ^13.5.4
version: 13.5.4(eslint@8.51.0)(typescript@5.2.2)
specifier: ^14.0.0
version: 14.0.0(eslint@8.51.0)(typescript@5.2.2)
npm-check:
specifier: ^6.0.1
version: 6.0.1
@ -528,18 +528,18 @@ packages:
'@jridgewell/resolve-uri': 3.1.1
'@jridgewell/sourcemap-codec': 1.4.15
/@next/env@13.5.4:
resolution: {integrity: sha512-LGegJkMvRNw90WWphGJ3RMHMVplYcOfRWf2Be3td3sUa+1AaxmsYyANsA+znrGCBjXJNi4XAQlSoEfUxs/4kIQ==}
/@next/env@14.0.0:
resolution: {integrity: sha512-cIKhxkfVELB6hFjYsbtEeTus2mwrTC+JissfZYM0n+8Fv+g8ucUfOlm3VEDtwtwydZ0Nuauv3bl0qF82nnCAqA==}
dev: false
/@next/eslint-plugin-next@13.5.4:
resolution: {integrity: sha512-vI94U+D7RNgX6XypSyjeFrOzxGlZyxOplU0dVE5norIfZGn/LDjJYPHdvdsR5vN1eRtl6PDAsOHmycFEOljK5A==}
/@next/eslint-plugin-next@14.0.0:
resolution: {integrity: sha512-Ye37nNI09V3yt7pzuzSQtwlvuJ2CGzFszHXkcTHHZgNr7EhTMFLipn3VSJChy+e5+ahTdNApPphc3qCPUsn10A==}
dependencies:
glob: 7.1.7
dev: true
/@next/swc-darwin-arm64@13.5.4:
resolution: {integrity: sha512-Df8SHuXgF1p+aonBMcDPEsaahNo2TCwuie7VXED4FVyECvdXfRT9unapm54NssV9tF3OQFKBFOdlje4T43VO0w==}
/@next/swc-darwin-arm64@14.0.0:
resolution: {integrity: sha512-HQKi159jCz4SRsPesVCiNN6tPSAFUkOuSkpJsqYTIlbHLKr1mD6be/J0TvWV6fwJekj81bZV9V/Tgx3C2HO9lA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [darwin]
@ -547,8 +547,8 @@ packages:
dev: false
optional: true
/@next/swc-darwin-x64@13.5.4:
resolution: {integrity: sha512-siPuUwO45PnNRMeZnSa8n/Lye5ZX93IJom9wQRB5DEOdFrw0JjOMu1GINB8jAEdwa7Vdyn1oJ2xGNaQpdQQ9Pw==}
/@next/swc-darwin-x64@14.0.0:
resolution: {integrity: sha512-4YyQLMSaCgX/kgC1jjF3s3xSoBnwHuDhnF6WA1DWNEYRsbOOPWjcYhv8TKhRe2ApdOam+VfQSffC4ZD+X4u1Cg==}
engines: {node: '>= 10'}
cpu: [x64]
os: [darwin]
@ -556,8 +556,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-arm64-gnu@13.5.4:
resolution: {integrity: sha512-l/k/fvRP/zmB2jkFMfefmFkyZbDkYW0mRM/LB+tH5u9pB98WsHXC0WvDHlGCYp3CH/jlkJPL7gN8nkTQVrQ/2w==}
/@next/swc-linux-arm64-gnu@14.0.0:
resolution: {integrity: sha512-io7fMkJ28Glj7SH8yvnlD6naIhRDnDxeE55CmpQkj3+uaA2Hko6WGY2pT5SzpQLTnGGnviK85cy8EJ2qsETj/g==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@ -565,8 +565,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-arm64-musl@13.5.4:
resolution: {integrity: sha512-YYGb7SlLkI+XqfQa8VPErljb7k9nUnhhRrVaOdfJNCaQnHBcvbT7cx/UjDQLdleJcfyg1Hkn5YSSIeVfjgmkTg==}
/@next/swc-linux-arm64-musl@14.0.0:
resolution: {integrity: sha512-nC2h0l1Jt8LEzyQeSs/BKpXAMe0mnHIMykYALWaeddTqCv5UEN8nGO3BG8JAqW/Y8iutqJsaMe2A9itS0d/r8w==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@ -574,8 +574,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-x64-gnu@13.5.4:
resolution: {integrity: sha512-uE61vyUSClnCH18YHjA8tE1prr/PBFlBFhxBZis4XBRJoR+txAky5d7gGNUIbQ8sZZ7LVkSVgm/5Fc7mwXmRAg==}
/@next/swc-linux-x64-gnu@14.0.0:
resolution: {integrity: sha512-Wf+WjXibJQ7hHXOdNOmSMW5bxeJHVf46Pwb3eLSD2L76NrytQlif9NH7JpHuFlYKCQGfKfgSYYre5rIfmnSwQw==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@ -583,8 +583,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-x64-musl@13.5.4:
resolution: {integrity: sha512-qVEKFYML/GvJSy9CfYqAdUexA6M5AklYcQCW+8JECmkQHGoPxCf04iMh7CPR7wkHyWWK+XLt4Ja7hhsPJtSnhg==}
/@next/swc-linux-x64-musl@14.0.0:
resolution: {integrity: sha512-WTZb2G7B+CTsdigcJVkRxfcAIQj7Lf0ipPNRJ3vlSadU8f0CFGv/ST+sJwF5eSwIe6dxKoX0DG6OljDBaad+rg==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@ -592,8 +592,8 @@ packages:
dev: false
optional: true
/@next/swc-win32-arm64-msvc@13.5.4:
resolution: {integrity: sha512-mDSQfqxAlfpeZOLPxLymZkX0hYF3juN57W6vFHTvwKlnHfmh12Pt7hPIRLYIShk8uYRsKPtMTth/EzpwRI+u8w==}
/@next/swc-win32-arm64-msvc@14.0.0:
resolution: {integrity: sha512-7R8/x6oQODmNpnWVW00rlWX90sIlwluJwcvMT6GXNIBOvEf01t3fBg0AGURNKdTJg2xNuP7TyLchCL7Lh2DTiw==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [win32]
@ -601,8 +601,8 @@ packages:
dev: false
optional: true
/@next/swc-win32-ia32-msvc@13.5.4:
resolution: {integrity: sha512-aoqAT2XIekIWoriwzOmGFAvTtVY5O7JjV21giozBTP5c6uZhpvTWRbmHXbmsjZqY4HnEZQRXWkSAppsIBweKqw==}
/@next/swc-win32-ia32-msvc@14.0.0:
resolution: {integrity: sha512-RLK1nELvhCnxaWPF07jGU4x3tjbyx2319q43loZELqF0+iJtKutZ+Lk8SVmf/KiJkYBc7Cragadz7hb3uQvz4g==}
engines: {node: '>= 10'}
cpu: [ia32]
os: [win32]
@ -610,8 +610,8 @@ packages:
dev: false
optional: true
/@next/swc-win32-x64-msvc@13.5.4:
resolution: {integrity: sha512-cyRvlAxwlddlqeB9xtPSfNSCRy8BOa4wtMo0IuI9P7Y0XT2qpDrpFKRyZ7kUngZis59mPVla5k8X1oOJ8RxDYg==}
/@next/swc-win32-x64-msvc@14.0.0:
resolution: {integrity: sha512-g6hLf1SUko+hnnaywQQZzzb3BRecQsoKkF3o/C+F+dOA4w/noVAJngUVkfwF0+2/8FzNznM7ofM6TGZO9svn7w==}
engines: {node: '>= 10'}
cpu: [x64]
os: [win32]
@ -2740,8 +2740,8 @@ packages:
resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
engines: {node: '>=10'}
/eslint-config-next@13.5.4(eslint@8.51.0)(typescript@5.2.2):
resolution: {integrity: sha512-FzQGIj4UEszRX7fcRSJK6L1LrDiVZvDFW320VVntVKh3BSU8Fb9kpaoxQx0cdFgf3MQXdeSbrCXJ/5Z/NndDkQ==}
/eslint-config-next@14.0.0(eslint@8.51.0)(typescript@5.2.2):
resolution: {integrity: sha512-jtXeE+/pGQ3h9n11QyyuPN50kO13GO5XvjU5ZRq6W+XTpOMjyobWmK2s7aowy0FtzA49krJzYzEU9s1RMwoJ6g==}
peerDependencies:
eslint: ^7.23.0 || ^8.0.0
typescript: '>=3.3.1'
@ -2749,7 +2749,7 @@ packages:
typescript:
optional: true
dependencies:
'@next/eslint-plugin-next': 13.5.4
'@next/eslint-plugin-next': 14.0.0
'@rushstack/eslint-patch': 1.5.1
'@typescript-eslint/parser': 6.7.5(eslint@8.51.0)(typescript@5.2.2)
eslint: 8.51.0
@ -4214,26 +4214,26 @@ packages:
/natural-compare@1.4.0:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
/next-seo@6.1.0(next@13.5.4)(react-dom@18.2.0)(react@18.2.0):
/next-seo@6.1.0(next@14.0.0)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-iMBpFoJsR5zWhguHJvsoBDxDSmdYTHtnVPB1ij+CD0NReQCP78ZxxbdL9qkKIf4oEuZEqZkrjAQLB0bkII7RYA==}
peerDependencies:
next: ^8.1.1-canary.54 || >=9.0.0
react: '>=16.0.0'
react-dom: '>=16.0.0'
dependencies:
next: 13.5.4(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)
next: 14.0.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)
react: 18.2.0
react-dom: 18.2.0(react@18.2.0)
dev: false
/next-themes@0.2.1(next@13.5.4)(react-dom@18.2.0)(react@18.2.0):
/next-themes@0.2.1(next@14.0.0)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
peerDependencies:
next: '*'
react: '*'
react-dom: '*'
dependencies:
next: 13.5.4(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)
next: 14.0.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)
react: 18.2.0
react-dom: 18.2.0(react@18.2.0)
dev: false
@ -4242,9 +4242,9 @@ packages:
resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==}
dev: false
/next@13.5.4(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-+93un5S779gho8y9ASQhb/bTkQF17FNQOtXLKAj3lsNgltEcF0C5PMLLncDmH+8X1EnJH1kbqAERa29nRXqhjA==}
engines: {node: '>=16.14.0'}
/next@14.0.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-J0jHKBJpB9zd4+c153sair0sz44mbaCHxggs8ryVXSFBuBqJ8XdE9/ozoV85xGh2VnSjahwntBZZgsihL9QznA==}
engines: {node: '>=18.17.0'}
hasBin: true
peerDependencies:
'@opentelemetry/api': ^1.1.0
@ -4257,7 +4257,7 @@ packages:
sass:
optional: true
dependencies:
'@next/env': 13.5.4
'@next/env': 14.0.0
'@swc/helpers': 0.5.2
busboy: 1.6.0
caniuse-lite: 1.0.30001549
@ -4267,15 +4267,15 @@ packages:
styled-jsx: 5.1.1(@babel/core@7.23.2)(react@18.2.0)
watchpack: 2.4.0
optionalDependencies:
'@next/swc-darwin-arm64': 13.5.4
'@next/swc-darwin-x64': 13.5.4
'@next/swc-linux-arm64-gnu': 13.5.4
'@next/swc-linux-arm64-musl': 13.5.4
'@next/swc-linux-x64-gnu': 13.5.4
'@next/swc-linux-x64-musl': 13.5.4
'@next/swc-win32-arm64-msvc': 13.5.4
'@next/swc-win32-ia32-msvc': 13.5.4
'@next/swc-win32-x64-msvc': 13.5.4
'@next/swc-darwin-arm64': 14.0.0
'@next/swc-darwin-x64': 14.0.0
'@next/swc-linux-arm64-gnu': 14.0.0
'@next/swc-linux-arm64-musl': 14.0.0
'@next/swc-linux-x64-gnu': 14.0.0
'@next/swc-linux-x64-musl': 14.0.0
'@next/swc-win32-arm64-msvc': 14.0.0
'@next/swc-win32-ia32-msvc': 14.0.0
'@next/swc-win32-x64-msvc': 14.0.0
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros

View File

@ -5,17 +5,17 @@ import { BeatSaverMapData } from "../types/BeatSaverMapData";
import { getValue, setValue, valueExists } from "../utils/redisUtils";
const BEATSAVER_MAP_API =
env(VARS.HTTP_PROXY) + "/https://api.beatsaver.com/maps/hash/%s";
env(VARS.HTTP_PROXY) + "/https://api.beatsaver.com/maps/hash/%s";
const KEY = "BS_MAP_DATA_";
function getLatestMapArt(data: BeatSaverMapData) {
return data.versions[data.versions.length - 1].coverURL;
return data.versions[data.versions.length - 1].coverURL;
}
type MapData = {
bsr: string;
mapArt: string | undefined;
bsr: string;
mapArt: string | undefined;
};
/**
@ -25,30 +25,34 @@ type MapData = {
* @returns The map data
*/
export async function getMapData(hash: string): Promise<MapData | undefined> {
const mapHash = hash.replace("custom_level_", "").toLowerCase();
const mapHash = hash.replace("custom_level_", "").toLowerCase();
const key = `${KEY}${mapHash}`;
const exists = await valueExists(key);
if (exists) {
const data = await getValue(key);
return JSON.parse(data);
}
const key = `${KEY}${mapHash}`;
const exists = await valueExists(key);
if (exists) {
const data = await getValue(key);
return JSON.parse(data);
}
const before = Date.now();
const response = await axios.get(BEATSAVER_MAP_API.replace("%s", mapHash));
if (response.status === 404) {
return undefined;
}
const jsonResponse = response.data;
const json = {
bsr: jsonResponse.id,
mapArt: getLatestMapArt(jsonResponse),
};
await setValue(key, JSON.stringify(json), 86400 * 7); // Expire in a week
console.log(
`[Cache]: Cached BS Map Data for hash ${mapHash} in ${
Date.now() - before
}ms`
);
return json;
const before = Date.now();
const response = await axios.get(BEATSAVER_MAP_API.replace("%s", mapHash), {
headers: {
"X-Requested-With": "BeatSaber Overlay",
},
});
if (response.status === 404) {
return undefined;
}
const jsonResponse = response.data;
const json = {
bsr: jsonResponse.id,
mapArt: getLatestMapArt(jsonResponse),
};
await setValue(key, JSON.stringify(json), 86400 * 7); // Expire in a week
console.log(
`[Cache]: Cached BS Map Data for hash ${mapHash} in ${
Date.now() - before
}ms`
);
return json;
}

View File

@ -2,8 +2,13 @@ import axios from "axios";
import LeaderboardType from "../../consts/LeaderboardType";
export async function getPlayerData(leaderboardType, playerId) {
const data = await axios.get(
LeaderboardType[leaderboardType].ApiUrl.PlayerData.replace("%s", playerId)
);
return data;
const data = await axios.get(
LeaderboardType[leaderboardType].ApiUrl.PlayerData.replace("%s", playerId),
{
headers: {
"x-requested-with": "BeatSaber Overlay",
},
}
);
return data;
}

View File

@ -11,92 +11,97 @@ const KEY = "BL_MAP_DATA_";
* @returns
*/
export default async function handler(req, res) {
if (!req.query.hash || !req.query.difficulty || !req.query.characteristic) {
return res.status(404).json({
status: 404,
message: "Invalid request",
});
}
const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase();
const difficulty = req.query.difficulty.replace(" ", "");
const characteristic = req.query.characteristic;
if (!req.query.hash || !req.query.difficulty || !req.query.characteristic) {
return res.status(404).json({
status: 404,
message: "Invalid request",
});
}
const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase();
const difficulty = req.query.difficulty.replace(" ", "");
const characteristic = req.query.characteristic;
const key = `${KEY}${difficulty}-${characteristic}-${mapHash}`;
const exists = await valueExists(key);
if (exists) {
const data = await getValue(key);
const json = JSON.parse(data);
res.setHeader("Cache-Status", "hit");
const key = `${KEY}${difficulty}-${characteristic}-${mapHash}`;
const exists = await valueExists(key);
if (exists) {
const data = await getValue(key);
const json = JSON.parse(data);
res.setHeader("Cache-Status", "hit");
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: json.stars,
modifiers: json.modifiers,
passRating: json.passRating,
accRating: json.accRating,
techRating: json.techRating,
});
}
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: json.stars,
modifiers: json.modifiers,
passRating: json.passRating,
accRating: json.accRating,
techRating: json.techRating,
});
}
const before = Date.now();
const reesponse = await axios.get(
WebsiteTypes.BeatLeader.ApiUrl.MapData.replace("%h", mapHash)
);
if (reesponse.status === 404) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
const json = reesponse.data;
let starCount = undefined;
let modifiers = undefined;
let passRating = undefined;
let accRating = undefined;
let techRating = undefined;
const before = Date.now();
const reesponse = await axios.get(
WebsiteTypes.BeatLeader.ApiUrl.MapData.replace("%h", mapHash),
{
headers: {
"X-Requested-With": "BeatSaber Overlay",
},
}
);
if (reesponse.status === 404) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
const json = reesponse.data;
let starCount = undefined;
let modifiers = undefined;
let passRating = undefined;
let accRating = undefined;
let techRating = undefined;
for (const diff of json.difficulties) {
if (
diff.difficultyName === difficulty &&
diff.modeName === characteristic
) {
starCount = diff.stars;
modifiers = diff.modifierValues;
passRating = diff.passRating;
accRating = diff.accRating;
techRating = diff.techRating;
}
}
if (starCount === undefined) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
await setValue(
key,
JSON.stringify({
stars: starCount,
modifiers: modifiers,
passRating: passRating,
accRating: accRating,
techRating: techRating,
})
);
console.log(
`[Cache]: Cached BL Star Count for hash ${mapHash} in ${
Date.now() - before
}ms`
);
res.setHeader("Cache-Status", "miss");
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: starCount,
modifiers: modifiers,
passRating: passRating,
accRating: accRating,
techRating: techRating,
});
for (const diff of json.difficulties) {
if (
diff.difficultyName === difficulty &&
diff.modeName === characteristic
) {
starCount = diff.stars;
modifiers = diff.modifierValues;
passRating = diff.passRating;
accRating = diff.accRating;
techRating = diff.techRating;
}
}
if (starCount === undefined) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
await setValue(
key,
JSON.stringify({
stars: starCount,
modifiers: modifiers,
passRating: passRating,
accRating: accRating,
techRating: techRating,
})
);
console.log(
`[Cache]: Cached BL Star Count for hash ${mapHash} in ${
Date.now() - before
}ms`
);
res.setHeader("Cache-Status", "miss");
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: starCount,
modifiers: modifiers,
passRating: passRating,
accRating: accRating,
techRating: techRating,
});
}

View File

@ -12,60 +12,65 @@ const KEY = "SS_MAP_STAR_";
* @returns
*/
export default async function handler(req, res) {
if (!req.query.hash) {
return res.status(404).json({
status: 404,
message: "Invalid request",
});
}
const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase();
const difficulty = req.query.difficulty.replace(" ", "");
const characteristic = req.query.characteristic;
if (!req.query.hash) {
return res.status(404).json({
status: 404,
message: "Invalid request",
});
}
const mapHash = req.query.hash.replace("custom_level_", "").toLowerCase();
const difficulty = req.query.difficulty.replace(" ", "");
const characteristic = req.query.characteristic;
const key = `${KEY}${difficulty}-${characteristic}-${mapHash}`;
const exists = await valueExists(key);
if (exists) {
const data = await getValue(key);
res.setHeader("Cache-Status", "hit");
const key = `${KEY}${difficulty}-${characteristic}-${mapHash}`;
const exists = await valueExists(key);
if (exists) {
const data = await getValue(key);
res.setHeader("Cache-Status", "hit");
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: Number.parseFloat(data),
});
}
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: Number.parseFloat(data),
});
}
const before = Date.now();
const response = await axios.get(
WebsiteTypes.ScoreSaber.ApiUrl.MapData.replace("%h", mapHash).replace(
"%d",
diffToScoreSaberDiff(difficulty)
)
);
if (response.status === 404) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
const json = response.data;
let starCount = json.stars;
if (starCount === undefined) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
await setValue(key, starCount);
console.log(
`[Cache]: Cached SS Star Count for hash ${mapHash} in ${
Date.now() - before
}ms`
);
res.setHeader("Cache-Status", "miss");
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: starCount,
});
const before = Date.now();
const response = await axios.get(
WebsiteTypes.ScoreSaber.ApiUrl.MapData.replace("%h", mapHash).replace(
"%d",
diffToScoreSaberDiff(difficulty)
),
{
headers: {
"X-Requested-With": "BeatSaber Overlay",
},
}
);
if (response.status === 404) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
const json = response.data;
let starCount = json.stars;
if (starCount === undefined) {
return res.status(404).json({
status: 404,
message: "Unknown Map Hash",
});
}
await setValue(key, starCount);
console.log(
`[Cache]: Cached SS Star Count for hash ${mapHash} in ${
Date.now() - before
}ms`
);
res.setHeader("Cache-Status", "miss");
return res.status(200).json({
status: "OK",
difficulty: difficulty,
stars: starCount,
});
}

View File

@ -4,48 +4,52 @@ import Utils from "../utils/utils";
import { useSettingsStore } from "./overlaySettingsStore";
interface PlayerDataState {
isLoading: boolean;
id: string;
pp: number;
avatar: string;
globalPos: number;
countryRank: number;
country: string;
updatePlayerData: () => void;
isLoading: boolean;
id: string;
pp: number;
avatar: string;
globalPos: number;
countryRank: number;
country: string;
updatePlayerData: () => void;
}
export const usePlayerDataStore = create<PlayerDataState>()((set) => ({
isLoading: true,
id: "",
pp: 0,
avatar: "",
globalPos: 0,
countryRank: 0,
country: "",
isLoading: true,
id: "",
pp: 0,
avatar: "",
globalPos: 0,
countryRank: 0,
country: "",
updatePlayerData: async () => {
const leaderboardType = useSettingsStore.getState().leaderboardType;
const playerId = useSettingsStore.getState().id;
updatePlayerData: async () => {
const leaderboardType = useSettingsStore.getState().leaderboardType;
const playerId = useSettingsStore.getState().id;
const apiUrl = Utils.getWebsiteApi(
leaderboardType
).ApiUrl.PlayerData.replace("%s", playerId);
const response = await axios.get(apiUrl);
if (response.status !== 200) {
return;
}
const data = response.data;
const apiUrl = Utils.getWebsiteApi(
leaderboardType
).ApiUrl.PlayerData.replace("%s", playerId);
const response = await axios.get(apiUrl, {
headers: {
"x-requested-with": "BeatSaber Overlay",
},
});
if (response.status !== 200) {
return;
}
const data = response.data;
console.log("Updated player data");
console.log("Updated player data");
set(() => ({
id: playerId,
isLoading: false,
pp: data.pp,
avatar: data.avatar || data.profilePicture,
globalPos: data.rank,
countryRank: data.countryRank,
country: data.country,
}));
},
set(() => ({
id: playerId,
isLoading: false,
pp: data.pp,
avatar: data.avatar || data.profilePicture,
globalPos: data.rank,
countryRank: data.countryRank,
country: data.country,
}));
},
}));

View File

@ -5,130 +5,134 @@ import { getScoreSaberPP } from "../curve/ScoreSaberCurve";
import { useSongDataStore } from "../store/songDataStore";
export default class Utils {
/**
* Returns the information for the given website type.
*
* @param {string} website
* @returns The website type's information.
*/
static getWebsiteApi(website) {
return LeaderboardType[website];
}
/**
* Returns the information for the given website type.
*
* @param {string} website
* @returns The website type's information.
*/
static getWebsiteApi(website) {
return LeaderboardType[website];
}
static openInNewTab(url) {
window.open(url, "_blank");
}
static openInNewTab(url) {
window.open(url, "_blank");
}
static async isLeaderboardValid(url, steamId) {
const response = await axios.get(url.replace("%s", steamId));
if (response.status === 429) {
return true; // Just assume it's true is we are rate limited
}
const json = response.data;
return !!json.pp;
}
static async isLeaderboardValid(url, steamId) {
const response = await axios.get(url.replace("%s", steamId), {
headers: {
"X-Requested-With": "BeatSaber Overlay",
},
});
if (response.status === 429) {
return true; // Just assume it's true is we are rate limited
}
const json = response.data;
return !!json.pp;
}
static calculatePP(stars, acc, type) {
if (stars <= 0) {
return undefined;
}
if (type === "BeatLeader") {
const leaderboardData =
useSongDataStore.getState().mapLeaderboardData.beatLeader;
static calculatePP(stars, acc, type) {
if (stars <= 0) {
return undefined;
}
if (type === "BeatLeader") {
const leaderboardData =
useSongDataStore.getState().mapLeaderboardData.beatLeader;
return getBeatLeaderPP(
acc,
leaderboardData.accRating,
leaderboardData.passRating,
leaderboardData.techRating
);
}
if (type === "ScoreSaber") {
return getScoreSaberPP(acc, stars);
}
return undefined;
}
return getBeatLeaderPP(
acc,
leaderboardData.accRating,
leaderboardData.passRating,
leaderboardData.techRating
);
}
if (type === "ScoreSaber") {
return getScoreSaberPP(acc, stars);
}
return undefined;
}
static calculateModifierBonus() {
const songMods = useSongDataStore.getState().songModifiers;
const modifierMulipliers =
useSongDataStore.getState().mapLeaderboardData.beatLeader.modifiers;
let bonus = 1;
static calculateModifierBonus() {
const songMods = useSongDataStore.getState().songModifiers;
const modifierMulipliers =
useSongDataStore.getState().mapLeaderboardData.beatLeader.modifiers;
let bonus = 1;
// No Fail
if (
songMods.noFail == true &&
modifierMulipliers.nf < 0 &&
useSongDataStore.getState().failed
) {
bonus -= modifierMulipliers.nf;
}
// No Fail
if (
songMods.noFail == true &&
modifierMulipliers.nf < 0 &&
useSongDataStore.getState().failed
) {
bonus -= modifierMulipliers.nf;
}
// Speed Modifiers
if (songMods.songSpeed != "Normal") {
if (songMods.songSpeed == "SuperSlow" && modifierMulipliers.ss > 0) {
bonus -= modifierMulipliers.ss;
}
if (songMods.songSpeed == "Faster" && modifierMulipliers.fs > 0) {
bonus += modifierMulipliers.fs;
}
if (songMods.songSpeed == "SuperFast" && modifierMulipliers.sf > 0) {
bonus += modifierMulipliers.sf;
}
}
// Speed Modifiers
if (songMods.songSpeed != "Normal") {
if (songMods.songSpeed == "SuperSlow" && modifierMulipliers.ss > 0) {
bonus -= modifierMulipliers.ss;
}
if (songMods.songSpeed == "Faster" && modifierMulipliers.fs > 0) {
bonus += modifierMulipliers.fs;
}
if (songMods.songSpeed == "SuperFast" && modifierMulipliers.sf > 0) {
bonus += modifierMulipliers.sf;
}
}
// Disappearing Arrows
if (songMods.disappearingArrows == true && modifierMulipliers.da > 0) {
bonus += modifierMulipliers.da;
}
// Disappearing Arrows
if (songMods.disappearingArrows == true && modifierMulipliers.da > 0) {
bonus += modifierMulipliers.da;
}
// Ghost Notes
if (songMods.ghostNotes == true && modifierMulipliers.gn > 0) {
toAdd += modifierMulipliers.gn;
}
// Ghost Notes
if (songMods.ghostNotes == true && modifierMulipliers.gn > 0) {
toAdd += modifierMulipliers.gn;
}
// No Arrows
if (songMods.noArrows == true && modifierMulipliers.na < 0) {
bonus -= modifierMulipliers.na;
}
// No Arrows
if (songMods.noArrows == true && modifierMulipliers.na < 0) {
bonus -= modifierMulipliers.na;
}
// No Bombs
if (songMods.noBombs == true && modifierMulipliers.nb < 0) {
bonus -= modifierMulipliers.nb;
}
// No Bombs
if (songMods.noBombs == true && modifierMulipliers.nb < 0) {
bonus -= modifierMulipliers.nb;
}
// No Obstacles
if (songMods.obstacles == false && modifierMulipliers.no < 0) {
bonus -= modifierMulipliers.no;
}
// No Obstacles
if (songMods.obstacles == false && modifierMulipliers.no < 0) {
bonus -= modifierMulipliers.no;
}
return bonus;
}
return bonus;
}
static base64ToArrayBuffer(base64) {
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
}
static base64ToArrayBuffer(base64) {
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
}
static stringToBoolean = (stringValue) => {
switch (stringValue?.toLowerCase()?.trim()) {
case "true":
case "yes":
case "1":
return true;
static stringToBoolean = (stringValue) => {
switch (stringValue?.toLowerCase()?.trim()) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
case null:
case undefined:
return false;
case "false":
case "no":
case "0":
case null:
case undefined:
return false;
default:
return JSON.parse(stringValue);
}
};
default:
return JSON.parse(stringValue);
}
};
static capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
static capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
}