diff --git a/api/index.ts b/api/index.ts new file mode 100644 index 0000000..9d8e958 --- /dev/null +++ b/api/index.ts @@ -0,0 +1,40 @@ +import { token } from "./infos/token"; +import { github } from "./infos/coding/github"; +import { gitlab } from "./infos/coding/gitlab"; +import { kitsudev } from "./infos/coding/kitsudev"; +import { kitsuclub } from "./infos/fediverse/kitsuclub"; +import { osu } from "./infos/gaming/osu"; +import { speedruncom } from "./infos/gaming/speedruncom"; +import { hackthebox } from "./infos/hacking/hackthebox"; +import { wanikani } from "./infos/japanese/wanikani"; +import { anilist } from "./infos/media/anilist"; +import { lastfm } from "./infos/media/lastfm"; +import { umami } from "./infos/website/umami"; + +const info_routes: Record = { + coding: [github, gitlab, kitsudev], + fediverse: [kitsuclub], + gaming: [osu, speedruncom], + hacking: [hackthebox], + japanese: [wanikani], + media: [anilist, lastfm], + website: [umami], +}; + +export type Handler = (req: URLSearchParams) => Promise; + +export async function api(pathname: string, parameters: URLSearchParams) { + if (pathname === "/api/infos/token") { + return await token(parameters); + } + + for (const route of Object.keys(info_routes)) { + for (const endpoint of info_routes[route]) { + if (pathname === "/api/infos/" + route + "/" + endpoint.name) { + return await endpoint(parameters); + } + } + } + + return new Response("Not Found", {status: 404}); +} diff --git a/api/coding_github.ts b/api/infos/coding/github.ts similarity index 86% rename from api/coding_github.ts rename to api/infos/coding/github.ts index 2341da5..cd1c648 100644 --- a/api/coding_github.ts +++ b/api/infos/coding/github.ts @@ -1,10 +1,12 @@ import {Octokit} from "@octokit/rest"; import {type GithubInfo} from "#Infos/Coding/GitHub.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const coding_github: Handler = async () => { +const username = "TTTaevas"; + +export const github: Handler = async () => { const octokit = new Octokit({auth: process.env["API_GITHUB"]}); - const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username: "TTTaevas"}); + const github = await octokit.rest.activity.listEventsForAuthenticatedUser({username}); const publicPush = github.data.find((e) => (e.type === "PushEvent" || e.type === "PullRequestEvent") && e.public); const privatePush = github.data.find((e) => (e.type === "PushEvent" || e.type === "PullRequestEvent") && !e.public); diff --git a/api/coding_gitlab.ts b/api/infos/coding/gitlab.ts similarity index 85% rename from api/coding_gitlab.ts rename to api/infos/coding/gitlab.ts index ebf00d3..58f9a14 100644 --- a/api/coding_gitlab.ts +++ b/api/infos/coding/gitlab.ts @@ -1,8 +1,8 @@ import { Gitlab } from "@gitbeaker/rest"; import {type GitlabInfo} from "#Infos/Coding/GitLab.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const coding_gitlab: Handler = async () => { +export const gitlab: Handler = async () => { const api = new Gitlab({token: process.env["API_GITLAB"]!}); const gitlab = await api.Events.all({action: "pushed"}); diff --git a/api/coding_kitsudev.ts b/api/infos/coding/kitsudev.ts similarity index 52% rename from api/coding_kitsudev.ts rename to api/infos/coding/kitsudev.ts index e67fe9c..2bcfd38 100644 --- a/api/coding_kitsudev.ts +++ b/api/infos/coding/kitsudev.ts @@ -1,8 +1,11 @@ import { type KitsudevInfo } from "#Infos/Coding/KitsuDev.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const coding_kitsudev: Handler = async () => { - const kitsudev = await (await fetch("https://kitsunes.dev/api/v1/users/Taevas/activities/feeds?limit=1")).json() as [{ +const username = "Taevas"; + +export const kitsudev: Handler = async () => { + /** https://kitsunes.dev/api/swagger#/user/userListActivityFeeds */ + const kitsudev = await (await fetch(`https://kitsunes.dev/api/v1/users/${username}/activities/feeds?limit=1`)).json() as [{ repo: { full_name: string html_url: string diff --git a/api/fediverse_kitsuclub.ts b/api/infos/fediverse/kitsuclub.ts similarity index 92% rename from api/fediverse_kitsuclub.ts rename to api/infos/fediverse/kitsuclub.ts index 8f0b066..a192aed 100644 --- a/api/fediverse_kitsuclub.ts +++ b/api/infos/fediverse/kitsuclub.ts @@ -1,7 +1,10 @@ import { type KitsuclubInfo } from "#Infos/Fediverse/KitsuClub.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const fediverse_kitsuclub: Handler = async () => { +const user_id = "a2hgd7delf"; + +export const kitsuclub: Handler = async () => { + /** https://kitsunes.club/api-doc#tag/users/POST/users/notes */ const kitsuclub = await (await fetch("https://kitsunes.club/api/users/notes", { method: "POST", headers: { @@ -9,7 +12,7 @@ export const fediverse_kitsuclub: Handler = async () => { "Content-Type": "application/json", }, body: JSON.stringify({ - "userId": "a2hgd7delf", + "userId": user_id, "limit": 1, "withReplies": false, "withRepliesToSelf": false, diff --git a/api/gaming_osu.ts b/api/infos/gaming/osu.ts similarity index 58% rename from api/gaming_osu.ts rename to api/infos/gaming/osu.ts index 1eb3b4b..c518a39 100644 --- a/api/gaming_osu.ts +++ b/api/infos/gaming/osu.ts @@ -1,15 +1,17 @@ -import * as osu from "osu-api-v2-js"; +import * as osuv2 from "osu-api-v2-js"; import {type OsuInfo} from "#Infos/Gaming/Osu.tsx"; -import type { Handler } from "../index.ts"; -import { db, getToken } from "../database.ts"; +import type { Handler } from "../../index.ts"; +import { db, getToken } from "../../../database.ts"; -export const gaming_osu: Handler = async (params) => { +const user_id = 7276846; + +export const osu: Handler = async (params) => { const token = await getToken(db, "osu"); let ruleset = params.has("ruleset") ? Number(params.get("ruleset")) : undefined; if (ruleset && isNaN(ruleset)) {ruleset = undefined;} - const api = new osu.API({access_token: token?.access_token}); - const profile = await api.getUser(7276846, ruleset); + const api = new osuv2.API({access_token: token?.access_token}); + const profile = await api.getUser(user_id, ruleset); const info: OsuInfo = { country: profile.country.name, diff --git a/api/gaming_speedruncom.ts b/api/infos/gaming/speedruncom.ts similarity index 80% rename from api/gaming_speedruncom.ts rename to api/infos/gaming/speedruncom.ts index 01be70d..558f53d 100644 --- a/api/gaming_speedruncom.ts +++ b/api/infos/gaming/speedruncom.ts @@ -1,5 +1,7 @@ import {type SpeedruncomInfo} from "#Infos/Gaming/Speedruncom.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; + +const user_id = "j03v45mj"; interface Runs { data: { @@ -41,17 +43,22 @@ interface Level { }; } -export const gaming_speedruncom: Handler = async () => { +export const speedruncom: Handler = async () => { // using the API's embedding would be stupid here, as that'd create lag due to irrelevant runs - const speedruncom = await (await fetch("https://www.speedrun.com/api/v1/users/j03v45mj/personal-bests")).json() as Runs; + + /** https://github.com/speedruncomorg/api/blob/master/version1/users.md#get-usersidpersonal-bests */ + const speedruncom = await (await fetch(`https://www.speedrun.com/api/v1/users/${user_id}/personal-bests`)).json() as Runs; const data = speedruncom.data.at(0); if (!data) { return new Response("Not Found", {status: 404}); } + /** https://github.com/speedruncomorg/api/blob/master/version1/games.md#get-gamesid */ const urlsToRequest = [`https://www.speedrun.com/api/v1/games/${data.run.game}`]; + /** https://github.com/speedruncomorg/api/blob/master/version1/levels.md#get-levelsid */ if (data.run.level) {urlsToRequest.push(`https://www.speedrun.com/api/v1/levels/${data.run.level}`);} + /** https://github.com/speedruncomorg/api/blob/master/version1/categories.md */ if (data.run.category) {urlsToRequest.push(`https://www.speedrun.com/api/v1/categories/${data.run.category}`);} const toRequest = urlsToRequest.map((url) => new Promise(async (resolve) => resolve(await (await fetch(url)).json()))); diff --git a/api/hacking_hackthebox.ts b/api/infos/hacking/hackthebox.ts similarity index 59% rename from api/hacking_hackthebox.ts rename to api/infos/hacking/hackthebox.ts index b995321..c9a8e85 100644 --- a/api/hacking_hackthebox.ts +++ b/api/infos/hacking/hackthebox.ts @@ -1,8 +1,11 @@ import {type HacktheboxInfo} from "#Infos/Hacking/Hackthebox.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const hacking_hackthebox: Handler = async () => { - const hackthebox = await (await fetch("https://www.hackthebox.com/api/v4/profile/activity/1063999")).json() as { +const user_id = 1063999; + +export const hackthebox: Handler = async () => { + /** https://documenter.getpostman.com/view/13129365/TVeqbmeq#1b0b22fc-2e45-456a-9a8f-42888375d1a9 */ + const hackthebox = await (await fetch(`https://www.hackthebox.com/api/v4/profile/activity/${user_id}`)).json() as { profile: { activity: HacktheboxInfo[]; }; diff --git a/api/japanese_wanikani.ts b/api/infos/japanese/wanikani.ts similarity index 97% rename from api/japanese_wanikani.ts rename to api/infos/japanese/wanikani.ts index 1ce1eb5..8897490 100644 --- a/api/japanese_wanikani.ts +++ b/api/infos/japanese/wanikani.ts @@ -1,6 +1,6 @@ import {type WanikaniInfo} from "#Infos/Japanese/Wanikani.tsx"; import type { WKLevelProgression, WKResetCollection, WKSummary } from "@bachmacintosh/wanikani-api-types"; -import type { Handler } from ".."; +import type { Handler } from "../.."; interface Subject { id: number; @@ -48,7 +48,7 @@ function addStuffToLearn(ids: number[], data: {available_at: string; subject_ids return arr; } -export const japanese_wanikani: Handler = async () => { +export const wanikani: Handler = async () => { const urlsToRequest = [ "https://api.wanikani.com/v2/level_progressions", "https://api.wanikani.com/v2/resets", diff --git a/api/media_anilist.ts b/api/infos/media/anilist.ts similarity index 89% rename from api/media_anilist.ts rename to api/infos/media/anilist.ts index 01bce26..9d561f7 100644 --- a/api/media_anilist.ts +++ b/api/infos/media/anilist.ts @@ -1,7 +1,10 @@ import {type AnilistInfo} from "#Infos/Media/Anilist.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const media_anilist: Handler = async () => { +const username = "Taevas"; + +export const anilist: Handler = async () => { + /** https://github.com/AniList/ApiV2-GraphQL-Docs/blob/master/docs/reference/query.md */ const anilist = await fetch("https://graphql.anilist.co", { method: "POST", headers: { @@ -39,7 +42,7 @@ export const media_anilist: Handler = async () => { } `, variables: { - userName: "Taevas", + userName: username, }, }), }); diff --git a/api/media_lastfm.ts b/api/infos/media/lastfm.ts similarity index 78% rename from api/media_lastfm.ts rename to api/infos/media/lastfm.ts index 2c6a826..d12e277 100644 --- a/api/media_lastfm.ts +++ b/api/infos/media/lastfm.ts @@ -1,8 +1,11 @@ import {type LastfmInfo} from "#Infos/Media/Lastfm.tsx"; -import type { Handler } from ".."; +import type { Handler } from "../.."; -export const media_lastfm: Handler = async () => { - const lastfm = await (await fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=TTTaevas&api_key=${process.env["API_LASTFM"]}&format=json&limit=1`)).json() as { +const username = "TTTaevas"; + +export const lastfm: Handler = async () => { + /** https://www.last.fm/api/show/user.getRecentTracks */ + const lastfm = await (await fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${username}&api_key=${process.env["API_LASTFM"]}&format=json&limit=1`)).json() as { recenttracks: { track: { artist: { diff --git a/api/token.ts b/api/infos/token.ts similarity index 97% rename from api/token.ts rename to api/infos/token.ts index 8b61c2f..5709081 100644 --- a/api/token.ts +++ b/api/infos/token.ts @@ -1,4 +1,4 @@ -import { addToken, createTables, db, getToken, removeExpiredTokens } from "../database"; +import { addToken, createTables, db, getToken, removeExpiredTokens } from "../../database"; import {API} from "osu-api-v2-js"; import type { Handler } from ".."; diff --git a/api/website_umami.ts b/api/infos/website/umami.ts similarity index 89% rename from api/website_umami.ts rename to api/infos/website/umami.ts index 38595f4..8a1e26f 100644 --- a/api/website_umami.ts +++ b/api/infos/website/umami.ts @@ -1,8 +1,8 @@ -import type { Handler } from "../index.ts"; +import type { Handler } from "../.."; import type { UmamiInfo } from "#Infos/Website/Umami.tsx"; -import { db, getToken } from "../database.ts"; +import { db, getToken } from "../../../database.ts"; -export const website_umami: Handler = async () => { +export const umami: Handler = async () => { const token = await getToken(db, "umami"); const api_server = "https://visitors.taevas.xyz/api"; diff --git a/bun.lockb b/bun.lockb index 2eeb5ec..eab4dc4 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/database.ts b/database.ts index dc1bf24..ebb1786 100644 --- a/database.ts +++ b/database.ts @@ -1,5 +1,5 @@ import { SQL } from "bun"; -import type { Token } from "./api/token"; +import type { Token } from "./api/infos/token"; export const db = new SQL({url: process.env["URL_POSTGRESQL"]}); diff --git a/index.ts b/index.ts index 26d9396..1f4dbd0 100644 --- a/index.ts +++ b/index.ts @@ -1,17 +1,6 @@ import type { Server } from "bun"; import { parseArgs } from "util"; -import { coding_github } from "./api/coding_github"; -import { coding_gitlab } from "./api/coding_gitlab"; -import { coding_kitsudev } from "./api/coding_kitsudev"; -import { fediverse_kitsuclub } from "./api/fediverse_kitsuclub"; -import { gaming_osu } from "./api/gaming_osu"; -import { gaming_speedruncom } from "./api/gaming_speedruncom"; -import { hacking_hackthebox } from "./api/hacking_hackthebox"; -import { japanese_wanikani } from "./api/japanese_wanikani"; -import { media_anilist } from "./api/media_anilist"; -import { media_lastfm } from "./api/media_lastfm"; -import { token } from "./api/token"; -import { website_umami } from "./api/website_umami"; +import { api } from "./api"; // PORT AND SSL STUFF @@ -32,23 +21,6 @@ console.log("Therefore, we are opening ports on:", ports); // ACTUAL CODE -export type Handler = (req: URLSearchParams) => Promise; - -const api_endpoints: Handler[] = [ - coding_github, - coding_gitlab, - coding_kitsudev, - fediverse_kitsuclub, - gaming_osu, - gaming_speedruncom, - hacking_hackthebox, - japanese_wanikani, - media_anilist, - media_lastfm, - token, - website_umami -]; - const servers: Server[] = ports.map((port) => Bun.serve({ idleTimeout: 30, tls: port !== 80 ? tls : undefined, @@ -92,11 +64,7 @@ const servers: Server[] = ports.map((port) => Bun.serve({ // API if (pathname.startsWith("/api")) { - for (const endpoint of api_endpoints) { - if (pathname === "/api/" + endpoint.name) { - return await endpoint(parameters); - } - } + return await api(pathname, parameters); } return new Response("Not Found", {status: 404}); diff --git a/package.json b/package.json index 1ffb6c0..cf94724 100644 --- a/package.json +++ b/package.json @@ -21,20 +21,20 @@ "@eslint/js": "^9.23.0", "@stylistic/eslint-plugin": "^3.1.0", "@tailwindcss/forms": "^0.5.10", - "@tailwindcss/postcss": "^4.0.17", + "@tailwindcss/postcss": "^4.1.1", "@types/bun": "^1.2.8", - "@types/react": "^19.0.12", - "@types/react-dom": "^19.0.4", + "@types/react": "^19.1.0", + "@types/react-dom": "^19.1.1", "dotenv": "^16.4.7", "eslint": "^9.23.0", "eslint-config-xo-typescript": "^7.0.0", "eslint-plugin-react": "^7.37.4", "postcss": "^8.5.3", "react-animate-height": "^3.2.3", - "tailwindcss": "^4.0.17", + "tailwindcss": "^4.1.1", "typescript": "^5.8.2", - "typescript-eslint": "^8.28.0", - "vite": "^6.2.3" + "typescript-eslint": "^8.29.0", + "vite": "^6.2.5" }, "imports": { "#Main/*": "./src/Main/*", diff --git a/src/Infos/Coding/GitHub.tsx b/src/Infos/Coding/GitHub.tsx index c09dcf1..4e9543b 100644 --- a/src/Infos/Coding/GitHub.tsx +++ b/src/Infos/Coding/GitHub.tsx @@ -1,6 +1,6 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; import Link from "#parts/Link.tsx"; export interface GithubInfo { @@ -14,7 +14,7 @@ export interface GithubInfo { } export default function GitHub() { - const {data, error, setError} = DataHandler("coding_github", 60 * 20); + const {data, error, setError} = DataHandler("infos/coding/github", 60 * 20); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Coding/GitLab.tsx b/src/Infos/Coding/GitLab.tsx index 08b641d..ac1e958 100644 --- a/src/Infos/Coding/GitLab.tsx +++ b/src/Infos/Coding/GitLab.tsx @@ -1,13 +1,13 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; export type GitlabInfo = { date: string; } | undefined; export default function GitLab() { - const {data, error, setError} = DataHandler("coding_gitlab", 60 * 20); + const {data, error, setError} = DataHandler("infos/coding/gitlab", 60 * 20); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Coding/KitsuDev.tsx b/src/Infos/Coding/KitsuDev.tsx index 8a9b68e..17390a9 100644 --- a/src/Infos/Coding/KitsuDev.tsx +++ b/src/Infos/Coding/KitsuDev.tsx @@ -1,6 +1,6 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; import Link from "#parts/Link.tsx"; export type KitsudevInfo = { @@ -10,7 +10,7 @@ export type KitsudevInfo = { } | undefined; export default function KitsuDev() { - const {data, error, setError} = DataHandler("coding_kitsudev", 60 * 20); + const {data, error, setError} = DataHandler("infos/coding/kitsudev", 60 * 20); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Fediverse/KitsuClub.tsx b/src/Infos/Fediverse/KitsuClub.tsx index 3f69c3e..f1ff996 100644 --- a/src/Infos/Fediverse/KitsuClub.tsx +++ b/src/Infos/Fediverse/KitsuClub.tsx @@ -1,6 +1,6 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; import Link from "#parts/Link.tsx"; export type KitsuclubInfo = { @@ -18,7 +18,7 @@ export type KitsuclubInfo = { } | undefined; export default function KitsuClub() { - const {data, error, setError} = DataHandler("fediverse_kitsuclub", 60 * 20); + const {data, error, setError} = DataHandler("infos/fediverse/kitsuclub", 60 * 20); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Gaming/Osu.tsx b/src/Infos/Gaming/Osu.tsx index ce1e897..d711386 100644 --- a/src/Infos/Gaming/Osu.tsx +++ b/src/Infos/Gaming/Osu.tsx @@ -1,7 +1,7 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; import { Ruleset } from "osu-api-v2-js"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; export type OsuInfo = { country: string; @@ -12,7 +12,7 @@ export type OsuInfo = { } | undefined; export default function Osu(args: {ruleset: Ruleset}) { - const {data, error, setError} = DataHandler(`gaming_osu?ruleset=${args.ruleset}`, 60 * 45); + const {data, error, setError} = DataHandler(`infos/gaming/osu?ruleset=${args.ruleset}`, 60 * 45); const [elements, setElements] = useState([] as React.JSX.Element[]); const ruleset = Ruleset[args.ruleset]; diff --git a/src/Infos/Gaming/Speedruncom.tsx b/src/Infos/Gaming/Speedruncom.tsx index 8e4c6c7..d4cf766 100644 --- a/src/Infos/Gaming/Speedruncom.tsx +++ b/src/Infos/Gaming/Speedruncom.tsx @@ -1,6 +1,6 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; import Link from "#parts/Link.tsx"; import ButtonLink from "#parts/ButtonLink.tsx"; @@ -16,7 +16,7 @@ export type SpeedruncomInfo = { } | undefined; export default function Speedruncom() { - const {data, error, setError} = DataHandler("gaming_speedruncom", 60 * 60); + const {data, error, setError} = DataHandler("infos/gaming/speedruncom", 60 * 60); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Gaming/index.tsx b/src/Infos/Gaming/index.tsx index 4b9c18f..348a2aa 100644 --- a/src/Infos/Gaming/index.tsx +++ b/src/Infos/Gaming/index.tsx @@ -4,10 +4,10 @@ import Info from "../Info.tsx"; import Speedruncom from "./Speedruncom.tsx"; // import Osu from "./Osu.tsx"; // import { Ruleset } from "osu-api-v2-js"; -// import DataHandler from "#Infos/DataHandler.tsx"; +// import DataHandler from "#parts/DataHandler.tsx"; export default function RhythmGames() { -// const {data, error} = DataHandler("token?service=osu", 60 * 60 * 8, false); +// const {data, error} = DataHandler("infos/token?service=osu", 60 * 60 * 8, false); const [websites, setWebsites] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Hacking/Hackthebox.tsx b/src/Infos/Hacking/Hackthebox.tsx index 7fac489..3375b2a 100644 --- a/src/Infos/Hacking/Hackthebox.tsx +++ b/src/Infos/Hacking/Hackthebox.tsx @@ -1,7 +1,7 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; import ButtonLink from "#parts/ButtonLink.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; export type HacktheboxInfo = { id: string; @@ -14,7 +14,7 @@ export type HacktheboxInfo = { } | undefined; export default function Hackthebox() { - const {data, error, setError} = DataHandler("hacking_hackthebox", 60 * 60); + const {data, error, setError} = DataHandler("infos/hacking/hackthebox", 60 * 60); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Japanese/Wanikani.tsx b/src/Infos/Japanese/Wanikani.tsx index ea9bf3c..7fc42f1 100644 --- a/src/Infos/Japanese/Wanikani.tsx +++ b/src/Infos/Japanese/Wanikani.tsx @@ -1,7 +1,7 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import { WKLevelProgression, WKReset } from "@bachmacintosh/wanikani-api-types"; -import DataHandler from "#Infos/DataHandler.tsx"; +import type { WKLevelProgression, WKReset } from "@bachmacintosh/wanikani-api-types"; +import DataHandler from "#parts/DataHandler.tsx"; export type WanikaniInfo = { progression: { @@ -37,7 +37,7 @@ function Button(item: Item) { } export default function Wanikani() { - const {data, error, setError} = DataHandler("japanese_wanikani", 60 * 60); + const {data, error, setError} = DataHandler("infos/japanese/wanikani", 60 * 60); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Media/Anilist.tsx b/src/Infos/Media/Anilist.tsx index 97c1dd7..a609100 100644 --- a/src/Infos/Media/Anilist.tsx +++ b/src/Infos/Media/Anilist.tsx @@ -1,6 +1,6 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; import Link from "#parts/Link.tsx"; export type AnilistInfo = { @@ -18,7 +18,7 @@ export type AnilistInfo = { } | undefined; export default function Anilist() { - const {data, error, setError} = DataHandler("media_anilist", 60 * 30); + const {data, error, setError} = DataHandler("infos/media/anilist", 60 * 30); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Media/Lastfm.tsx b/src/Infos/Media/Lastfm.tsx index 890c221..cf94c52 100644 --- a/src/Infos/Media/Lastfm.tsx +++ b/src/Infos/Media/Lastfm.tsx @@ -2,7 +2,7 @@ import React, {useState, useEffect} from "react"; import {format} from "timeago.js"; import Website from "../Website.tsx"; import Link from "#parts/Link.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; export type LastfmInfo = { artist: string; @@ -15,7 +15,7 @@ export type LastfmInfo = { } | undefined; export default function Lastfm() { - const {data, error, setError} = DataHandler("media_lastfm", 60 * 2); + const {data, error, setError} = DataHandler("infos/media/lastfm", 60 * 2); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Website/Umami.tsx b/src/Infos/Website/Umami.tsx index da744a0..66e7a4f 100644 --- a/src/Infos/Website/Umami.tsx +++ b/src/Infos/Website/Umami.tsx @@ -1,6 +1,6 @@ import React, {useState, useEffect} from "react"; import Website from "../Website.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; export type UmamiInfo = { pageviews: number @@ -10,7 +10,7 @@ export type UmamiInfo = { } | undefined; export default function Umami() { - const {data, error, setError} = DataHandler("website_umami", 60 * 5); + const {data, error, setError} = DataHandler("infos/website/umami", 60 * 5); const [elements, setElements] = useState([] as React.JSX.Element[]); useEffect(() => { diff --git a/src/Infos/Website/index.tsx b/src/Infos/Website/index.tsx index bc61704..a937730 100644 --- a/src/Infos/Website/index.tsx +++ b/src/Infos/Website/index.tsx @@ -1,10 +1,10 @@ import React, {useEffect, useState} from "react"; import Info from "../Info.tsx"; import Umami from "./Umami.tsx"; -import DataHandler from "#Infos/DataHandler.tsx"; +import DataHandler from "#parts/DataHandler.tsx"; export default function Website() { - const {data} = DataHandler("token?service=umami", 60 * 60 * 8, false); + const {data} = DataHandler("infos/token?service=umami", 60 * 60 * 8, false); const [websites, setWebsites] = useState([] as React.JSX.Element[]); // useEffect(() => { diff --git a/src/Infos/DataHandler.tsx b/src/parts/DataHandler.tsx similarity index 100% rename from src/Infos/DataHandler.tsx rename to src/parts/DataHandler.tsx