Added documentation to methods
Fixed avatars not initially loading
Just generally cleaned up the codebase
This commit is contained in:
RealFascinated 2022-04-02 07:01:58 +01:00
parent cfa2d5757f
commit aac2c7027e
13 changed files with 27 additions and 15 deletions

2
.gitignore vendored

@ -34,4 +34,4 @@ yarn-error.log*
.vercel .vercel
# IntelliJ # IntelliJ
.idea .idea

@ -1,7 +1,8 @@
# Simple ScoreSaber Overlay # ScoreSaber Overlay with real-time data
The public url to view/use this is: `https://bs-overlay.fascinated.cc`</br> The public url to view/use this is: `https://bs-overlay.fascinated.cc`</br>
To use your scoresaber: `https://bs-overlay.fascinated.cc/?id=765611` To use your scoresaber: `https://bs-overlay.fascinated.cc/?id=76561198449412074`</br>
Support Server: https://discord.gg/4FYVVhZPm7
## Getting Started with developent ## Getting Started with developent

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

@ -2,7 +2,7 @@ import Image from "next/image";
const Avatar = (props) => { const Avatar = (props) => {
return <> return <>
<Image className={'player-avatar'} src={props.url} width={180} height={180} alt={'Avatar image'} /> <Image className={'player-avatar'} src={props.url} width={180} height={180} alt={'Avatar image'} loading='lazy'/>
</> </>
} }

@ -1,7 +1,6 @@
import ReactCountryFlag from "react-country-flag"; import ReactCountryFlag from "react-country-flag";
const PlayerStats = (props) => { const PlayerStats = (props) => {
return <div className={'player-stats'}> return <div className={'player-stats'}>
<p>{props.pp}pp</p> <p>{props.pp}pp</p>
<p>#{props.globalPos}</p> <p>#{props.globalPos}</p>

@ -6,8 +6,14 @@ export default class ScoreStats extends Component {
super(params); super(params);
} }
getAverage(values) { /**
return values.reduce((p, c) => p + c, 0) / values.length; * Returns the average of the provided numbers list
*
* @param {List<Number>} hitValues
* @returns The average value
*/
getAverage(hitValues) {
return hitValues.reduce((p, c) => p + c, 0) / hitValues.length;
} }
render() { render() {

@ -4,8 +4,7 @@ module.exports = {
domains: [ domains: [
'cdn.scoresaber.com', 'cdn.scoresaber.com',
'bs-overlay.fascinated.cc', 'bs-overlay.fascinated.cc',
'localhost:3000', 'localhost:3000'
''
], ],
} }
} }

@ -4,12 +4,13 @@ export default async function handler(req, res) {
const mapHash = req.query.hash; const mapHash = req.query.hash;
const mapData = await Utils.getMapData(mapHash.replace("custom_level_", "")); const mapData = await Utils.getMapData(mapHash.replace("custom_level_", ""));
if (mapData === undefined) { if (mapData === undefined) { // Check if a map hash was provided
return res.json({ error: true, message: "Unknown map" }) return res.json({ error: true, message: "Unknown map" })
} }
const data = { const data = { // The maps data from the provided map hash
bsr: mapData.id, bsr: mapData.id,
songArt: "http://" + req.headers.host + "/api/beatsaver/art/" + mapHash + "?ext=" + mapData.versions[0].coverURL.split("/")[3].split(".")[1] songArt: "http://" + req.headers.host + "/api/beatsaver/art/" + mapHash + "?ext=" + mapData.versions[0].coverURL
.split("/")[3].split(".")[1]
}; };
res.json({ error: false, data: data }) res.json({ error: false, data: data });
} }

@ -175,5 +175,4 @@
.song-time-text { .song-time-text {
margin-top: 8px; margin-top: 8px;
font-size: large; font-size: large;
} }

@ -3,6 +3,13 @@ import Config from '../config.json';
module.exports = { module.exports = {
BEATSAVER_MAP_API: Config.proxy_url + "/https://api.beatsaver.com/maps/hash/%s", BEATSAVER_MAP_API: Config.proxy_url + "/https://api.beatsaver.com/maps/hash/%s",
// todo: cache map data for 12 hrs // todo: cache map data for 12 hrs
/**
* Gets a specified maps data from BeatSaver
*
* @param {string} hash
* @returns The map data
*/
async getMapData(hash) { async getMapData(hash) {
const data = await fetch(this.BEATSAVER_MAP_API.replace("%s", hash), { const data = await fetch(this.BEATSAVER_MAP_API.replace("%s", hash), {
headers: { headers: {