Add osu!
This commit is contained in:
parent
74ccb4d01d
commit
606d55f79f
7 changed files with 217 additions and 3 deletions
47
netlify/functions/osu.ts
Normal file
47
netlify/functions/osu.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { Handler } from '@netlify/functions'
|
||||
import { API, APIError, User } from 'osu-api-v2-js'
|
||||
|
||||
const handler: Handler = async (event, context) => {
|
||||
let api = await API.createAsync({id: 11451, secret: process.env.API_OSU!})
|
||||
if (!api) {
|
||||
return {
|
||||
statusCode: 404,
|
||||
body: ""
|
||||
}
|
||||
}
|
||||
|
||||
let profile = await Promise.all([
|
||||
new Promise((resolve, reject) => resolve((api!.getUser({id: 7276846}, 0)))),
|
||||
new Promise((resolve, reject) => resolve((api!.getUser({id: 7276846}, 1)))),
|
||||
new Promise((resolve, reject) => resolve((api!.getUser({id: 7276846}, 2)))),
|
||||
new Promise((resolve, reject) => resolve((api!.getUser({id: 7276846}, 3))))
|
||||
])
|
||||
|
||||
if (profile.find((mode) => mode instanceof APIError)) {
|
||||
return {
|
||||
statusCode: 404,
|
||||
body: ""
|
||||
}
|
||||
}
|
||||
|
||||
let ranks = {
|
||||
osu: [0,0],
|
||||
taiko: [0,0],
|
||||
fruits: [0,0],
|
||||
mania: [0,0]
|
||||
}
|
||||
|
||||
for (let i = 0; i < profile.length; i++) {
|
||||
let mode = profile[i] as User
|
||||
if (mode.rank_history) {
|
||||
ranks[mode.rank_history.mode] = mode.rank_history.data
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(ranks)
|
||||
}
|
||||
}
|
||||
|
||||
export { handler }
|
|
@ -7,8 +7,11 @@
|
|||
"dependencies": {
|
||||
"@netlify/functions": "^1.4.0",
|
||||
"@octokit/core": "^4.2.0",
|
||||
"chart.js": "^4.3.0",
|
||||
"node-fetch": "^3.3.1",
|
||||
"osu-api-v2-js": "^0.2.0",
|
||||
"react": "^18.2.0",
|
||||
"react-chartjs-2": "^5.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -5,6 +5,7 @@ import Lastfm from "./components/Lastfm";
|
|||
import Speedruncom from "./components/Speedruncom";
|
||||
import Hackthebox from "./components/hackthebox";
|
||||
import Github from "./components/github";
|
||||
import Osu from "./components/osu";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
|
@ -14,6 +15,7 @@ function App() {
|
|||
<Speedruncom/>
|
||||
<Hackthebox/>
|
||||
<Github/>
|
||||
<Osu/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
81
src/components/osu.jsx
Normal file
81
src/components/osu.jsx
Normal file
|
@ -0,0 +1,81 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import {
|
||||
Chart as ChartJS,
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
LineElement,
|
||||
Title,
|
||||
Tooltip,
|
||||
Legend,
|
||||
scales,
|
||||
} from 'chart.js';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
|
||||
ChartJS.register(
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
LineElement,
|
||||
Title,
|
||||
Tooltip,
|
||||
Legend
|
||||
);
|
||||
|
||||
export default function Osu() {
|
||||
const [osu, setOsu] = useState({})
|
||||
const getOsu = async () => {
|
||||
const response = await fetch("/.netlify/functions/osu").then(r => r.json())
|
||||
setOsu(response)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getOsu()
|
||||
}, [])
|
||||
|
||||
if (osu.osu === undefined) {
|
||||
return <></>
|
||||
}
|
||||
|
||||
function shapeData(ranks) {
|
||||
let labels = ranks.map((r, i) => `${i + 1} days ago`).reverse()
|
||||
return {
|
||||
labels,
|
||||
datasets: [{
|
||||
id: 1,
|
||||
label: "",
|
||||
data: ranks,
|
||||
borderColor: `rgb(
|
||||
${String(ranks[0]).slice(-2)},
|
||||
${String(ranks[ranks.length/2]).slice(-2)},
|
||||
${String(ranks[ranks.length-1]).slice(-2)}
|
||||
)`,
|
||||
tension: 0.5,
|
||||
fill: false,
|
||||
pointStyle: false
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
let options = {
|
||||
scales: {
|
||||
y: {
|
||||
reverse: true,
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div id="osu">
|
||||
<Line datasetIdKey="1" data={shapeData(osu.osu)} options={options}/>
|
||||
<Line datasetIdKey="1" data={shapeData(osu.taiko)} options={options}/>
|
||||
<Line datasetIdKey="1" data={shapeData(osu.fruits)} options={options}/>
|
||||
<Line datasetIdKey="1" data={shapeData(osu.mania)} options={options}/>
|
||||
</div>
|
||||
)
|
||||
}
|
0
src/style/github.css
Normal file
0
src/style/github.css
Normal file
0
src/style/osu.css
Normal file
0
src/style/osu.css
Normal file
87
yarn.lock
87
yarn.lock
|
@ -357,6 +357,11 @@
|
|||
"@jridgewell/resolve-uri" "3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "1.4.14"
|
||||
|
||||
"@kurkle/color@^0.3.0":
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@kurkle/color/-/color-0.3.2.tgz#5acd38242e8bde4f9986e7913c8fdf49d3aa199f"
|
||||
integrity sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw==
|
||||
|
||||
"@netlify/functions@^1.4.0":
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@netlify/functions/-/functions-1.4.0.tgz#027a2e5d54df5519ccbd14cf450231e97bbbf93a"
|
||||
|
@ -478,6 +483,20 @@ ansi-styles@^3.2.1:
|
|||
dependencies:
|
||||
color-convert "^1.9.0"
|
||||
|
||||
asynckit@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
||||
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
|
||||
|
||||
axios@^1.3.4:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f"
|
||||
integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==
|
||||
dependencies:
|
||||
follow-redirects "^1.15.0"
|
||||
form-data "^4.0.0"
|
||||
proxy-from-env "^1.1.0"
|
||||
|
||||
before-after-hook@^2.2.0:
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.3.tgz#c51e809c81a4e354084422b9b26bad88249c517c"
|
||||
|
@ -507,6 +526,13 @@ chalk@^2.0.0:
|
|||
escape-string-regexp "^1.0.5"
|
||||
supports-color "^5.3.0"
|
||||
|
||||
chart.js@^4.3.0:
|
||||
version "4.3.0"
|
||||
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-4.3.0.tgz#ac363030ab3fec572850d2d872956f32a46326a1"
|
||||
integrity sha512-ynG0E79xGfMaV2xAHdbhwiPLczxnNNnasrmPEXriXsPJGjmhOBYzFVEsB65w2qMDz+CaBJJuJD0inE/ab/h36g==
|
||||
dependencies:
|
||||
"@kurkle/color" "^0.3.0"
|
||||
|
||||
color-convert@^1.9.0:
|
||||
version "1.9.3"
|
||||
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
|
||||
|
@ -519,6 +545,13 @@ color-name@1.1.3:
|
|||
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
|
||||
integrity sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==
|
||||
|
||||
combined-stream@^1.0.8:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
|
||||
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
|
||||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
convert-source-map@^1.7.0:
|
||||
version "1.9.0"
|
||||
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.9.0.tgz#7faae62353fb4213366d0ca98358d22e8368b05f"
|
||||
|
@ -541,6 +574,11 @@ debug@^4.1.0:
|
|||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
|
||||
|
||||
deprecation@^2.0.0:
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919"
|
||||
|
@ -597,6 +635,20 @@ fetch-blob@^3.1.2, fetch-blob@^3.1.4:
|
|||
node-domexception "^1.0.0"
|
||||
web-streams-polyfill "^3.0.3"
|
||||
|
||||
follow-redirects@^1.15.0:
|
||||
version "1.15.2"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
|
||||
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
|
||||
|
||||
form-data@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
|
||||
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
formdata-polyfill@^4.0.10:
|
||||
version "4.0.10"
|
||||
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
|
||||
|
@ -663,6 +715,18 @@ lru-cache@^5.1.1:
|
|||
dependencies:
|
||||
yallist "^3.0.2"
|
||||
|
||||
mime-db@1.52.0:
|
||||
version "1.52.0"
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
|
||||
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
|
||||
|
||||
mime-types@^2.1.12:
|
||||
version "2.1.35"
|
||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
|
||||
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
|
||||
dependencies:
|
||||
mime-db "1.52.0"
|
||||
|
||||
ms@2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
|
@ -679,9 +743,9 @@ node-domexception@^1.0.0:
|
|||
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
|
||||
|
||||
node-fetch@^2.6.7:
|
||||
version "2.6.9"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.9.tgz#7c7f744b5cc6eb5fd404e0c7a9fec630a55657e6"
|
||||
integrity sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==
|
||||
version "2.6.10"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.10.tgz#4a52b637a6802092aa11a3bf73d19aac789fdce1"
|
||||
integrity sha512-5YytjUVbwzjE/BX4N62vnPPkGNxlJPwdA9/ArUc4pcM6cYS4Hinuv4VazzwjMGgnWuiQqcemOanib/5PpcsGug==
|
||||
dependencies:
|
||||
whatwg-url "^5.0.0"
|
||||
|
||||
|
@ -706,6 +770,13 @@ once@^1.4.0:
|
|||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
osu-api-v2-js@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/osu-api-v2-js/-/osu-api-v2-js-0.2.0.tgz#b27fb26b54af36a52b50c267904af3c6cd6a49be"
|
||||
integrity sha512-wKio6S38RkI05AoTJ/CSUE0BqMq0Pw5AdYHrBz2MM7/nThekPAqXVm9IKHYj+pWXi/+ltKaHjFv3lQn5TAArBw==
|
||||
dependencies:
|
||||
axios "^1.3.4"
|
||||
|
||||
picocolors@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
|
||||
|
@ -720,6 +791,16 @@ postcss@^8.4.23:
|
|||
picocolors "^1.0.0"
|
||||
source-map-js "^1.0.2"
|
||||
|
||||
proxy-from-env@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
|
||||
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
|
||||
|
||||
react-chartjs-2@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/react-chartjs-2/-/react-chartjs-2-5.2.0.tgz#43c1e3549071c00a1a083ecbd26c1ad34d385f5d"
|
||||
integrity sha512-98iN5aguJyVSxp5U3CblRLH67J8gkfyGNbiK3c+l1QI/G4irHMPQw44aEPmjVag+YKTyQ260NcF82GTQ3bdscA==
|
||||
|
||||
react-dom@^18.2.0:
|
||||
version "18.2.0"
|
||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue