From 9818adb12de6c185f6f558de4651596eda0f65f0 Mon Sep 17 00:00:00 2001 From: Taevas Date: Thu, 17 Apr 2025 13:38:00 +0200 Subject: [PATCH] Use custom headers to possibly bypass Anubis & co As recommended by the kind Kio! (so now most requests use a custom user-agent) --- api/index.ts | 6 ++++++ api/infos/coding/kitsudev.ts | 4 ++-- api/infos/fediverse/kitsuclub.ts | 4 ++-- api/infos/gamedev/alakajam.ts | 4 ++-- api/infos/gamedev/itchio.ts | 4 ++-- api/infos/gaming/speedruncom.ts | 4 ++-- api/infos/hacking/hackthebox.ts | 4 ++-- api/infos/japanese/wanikani.ts | 6 +++--- api/infos/media/anilist.ts | 7 ++----- api/infos/media/lastfm.ts | 5 +++-- api/infos/website/kitsudev.ts | 4 ++-- api/infos/website/umami.ts | 4 ++-- 12 files changed, 30 insertions(+), 26 deletions(-) diff --git a/api/index.ts b/api/index.ts index 9a2faea..09652d0 100644 --- a/api/index.ts +++ b/api/index.ts @@ -27,6 +27,12 @@ const info_routes: Record = { export type Handler = (req: URLSearchParams) => Promise; +export const headers = { + "Accept": "application/json", + "Content-Type": "application/json", + "User-Agent": "taevas.xyz (code@taevas.xyz)", +}; + export async function parseJson(response: Response) { try { return await response.json(); diff --git a/api/infos/coding/kitsudev.ts b/api/infos/coding/kitsudev.ts index b5b2ea5..ce2e11e 100644 --- a/api/infos/coding/kitsudev.ts +++ b/api/infos/coding/kitsudev.ts @@ -1,11 +1,11 @@ import { type KitsudevInfo } from "#Infos/Coding/KitsuDev.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const username = "Taevas"; export const kitsudev: Handler = async () => { /** https://kitsunes.dev/api/swagger#/user/userListActivityFeeds */ - const kitsudev = await parseJson(await fetch(`https://kitsunes.dev/api/v1/users/${username}/activities/feeds?limit=1`)) as [{ + const kitsudev = await parseJson(await fetch(`https://kitsunes.dev/api/v1/users/${username}/activities/feeds?limit=1`, {headers})) as [{ repo: { full_name: string html_url: string diff --git a/api/infos/fediverse/kitsuclub.ts b/api/infos/fediverse/kitsuclub.ts index 6c55ef3..1f77486 100644 --- a/api/infos/fediverse/kitsuclub.ts +++ b/api/infos/fediverse/kitsuclub.ts @@ -1,5 +1,5 @@ import { type KitsuclubInfo } from "#Infos/Fediverse/KitsuClub.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const user_id = "a2hgd7delf"; @@ -8,8 +8,8 @@ export const kitsuclub: Handler = async () => { const kitsuclub = await parseJson(await fetch("https://kitsunes.club/api/users/notes", { method: "POST", headers: { + ...headers, "Authorization": `Bearer ${process.env["API_KITSUCLUB"]}`, - "Content-Type": "application/json", }, body: JSON.stringify({ "userId": user_id, diff --git a/api/infos/gamedev/alakajam.ts b/api/infos/gamedev/alakajam.ts index 50bf55d..5b84240 100644 --- a/api/infos/gamedev/alakajam.ts +++ b/api/infos/gamedev/alakajam.ts @@ -1,11 +1,11 @@ import type { AlakajamInfo } from "#Infos/GameDev/Alakajam.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const username = "Taevas"; export const alakajam: Handler = async () => { /** https://alakajam.com/api */ - const response = await parseJson(await fetch(`https://alakajam.com/api/user/${username}/latestEntry`)) as { + const response = await parseJson(await fetch(`https://alakajam.com/api/user/${username}/latestEntry`, {headers})) as { name: string latest_entry: { event_name: string diff --git a/api/infos/gamedev/itchio.ts b/api/infos/gamedev/itchio.ts index b54b77d..50c7f02 100644 --- a/api/infos/gamedev/itchio.ts +++ b/api/infos/gamedev/itchio.ts @@ -1,9 +1,9 @@ import type { ItchioInfo } from "#Infos/GameDev/Itchio.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; export const itchio: Handler = async () => { /** https://itch.io/docs/api/serverside#reference/profilegames-httpsitchioapi1keymy-games */ - const response = await parseJson(await fetch(`https://itch.io/api/1/${process.env["API_ITCHIO"]}/my-games`)) as { + const response = await parseJson(await fetch(`https://itch.io/api/1/${process.env["API_ITCHIO"]}/my-games`, {headers})) as { games: { published_at?: string title: string diff --git a/api/infos/gaming/speedruncom.ts b/api/infos/gaming/speedruncom.ts index 90a2a36..7f65f58 100644 --- a/api/infos/gaming/speedruncom.ts +++ b/api/infos/gaming/speedruncom.ts @@ -1,5 +1,5 @@ import {type SpeedruncomInfo} from "#Infos/Gaming/Speedruncom.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const user_id = "j03v45mj"; @@ -47,7 +47,7 @@ export const speedruncom: Handler = async () => { // using the API's embedding would be stupid here, as that'd create lag due to irrelevant runs /** https://github.com/speedruncomorg/api/blob/master/version1/users.md#get-usersidpersonal-bests */ - const speedruncom = await parseJson(await fetch(`https://www.speedrun.com/api/v1/users/${user_id}/personal-bests`)) as Runs; + const speedruncom = await parseJson(await fetch(`https://www.speedrun.com/api/v1/users/${user_id}/personal-bests`, {headers})) as Runs; const data = speedruncom.data.at(0); if (!data) { diff --git a/api/infos/hacking/hackthebox.ts b/api/infos/hacking/hackthebox.ts index 200350e..d30e923 100644 --- a/api/infos/hacking/hackthebox.ts +++ b/api/infos/hacking/hackthebox.ts @@ -1,11 +1,11 @@ import {type HacktheboxInfo} from "#Infos/Hacking/Hackthebox.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const user_id = 1063999; export const hackthebox: Handler = async () => { /** https://documenter.getpostman.com/view/13129365/TVeqbmeq#1b0b22fc-2e45-456a-9a8f-42888375d1a9 */ - const hackthebox = await parseJson(await fetch(`https://www.hackthebox.com/api/v4/profile/activity/${user_id}`)) as { + const hackthebox = await parseJson(await fetch(`https://www.hackthebox.com/api/v4/profile/activity/${user_id}`, {headers})) as { profile: { activity: HacktheboxInfo[]; }; diff --git a/api/infos/japanese/wanikani.ts b/api/infos/japanese/wanikani.ts index 7cc50b0..88b689b 100644 --- a/api/infos/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 { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; interface Subject { id: number; @@ -56,8 +56,8 @@ export const wanikani: Handler = async () => { ]; const toRequest = urlsToRequest.map((url) => new Promise(async (resolve) => { const response = await fetch(url, {headers: { + ...headers, "Authorization": `Bearer ${process.env["API_WANIKANI"]}`, - "Content-Type": "application/json", }}); resolve(await parseJson(response)); })); @@ -92,8 +92,8 @@ export const wanikani: Handler = async () => { const subjectIdsAll = subjectIdsLessons.concat(subjectIdsReviews); const subjects = await parseJson(await fetch(`https://api.wanikani.com/v2/subjects?ids=${subjectIdsAll.toString()}`, {headers: { + ...headers, "Authorization": `Bearer ${process.env["API_WANIKANI"]}`, - "Content-Type": "application/json", }})) as {data: Subject[]}; const lessons = addStuffToLearn(subjectIdsLessons, summary.data.lessons, subjects.data); diff --git a/api/infos/media/anilist.ts b/api/infos/media/anilist.ts index 40492b6..4463f20 100644 --- a/api/infos/media/anilist.ts +++ b/api/infos/media/anilist.ts @@ -1,5 +1,5 @@ import {type AnilistInfo} from "#Infos/Media/Anilist.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const username = "Taevas"; @@ -7,10 +7,7 @@ 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: { - "Content-Type": "application/json", - "Accept": "application/json", - }, + headers, body: JSON.stringify({ query: ` query ($userName: String) { diff --git a/api/infos/media/lastfm.ts b/api/infos/media/lastfm.ts index afa074c..9155f04 100644 --- a/api/infos/media/lastfm.ts +++ b/api/infos/media/lastfm.ts @@ -1,11 +1,12 @@ import {type LastfmInfo} from "#Infos/Media/Lastfm.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const username = "TTTaevas"; export const lastfm: Handler = async () => { /** https://www.last.fm/api/show/user.getRecentTracks */ - const lastfm = await parseJson(await fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${username}&api_key=${process.env["API_LASTFM"]}&format=json&limit=1`)) as { + const url = `https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${username}&api_key=${process.env["API_LASTFM"]}&format=json&limit=1`; + const lastfm = await parseJson(await fetch(url, {headers})) as { recenttracks: { track: { artist: { diff --git a/api/infos/website/kitsudev.ts b/api/infos/website/kitsudev.ts index b7e0c53..00e1c13 100644 --- a/api/infos/website/kitsudev.ts +++ b/api/infos/website/kitsudev.ts @@ -1,12 +1,12 @@ import { type KitsudevInfo } from "#Infos/Website/KitsuDev.tsx"; -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; const username = "Taevas"; const repository = "taevas.xyz"; export const kitsudev: Handler = async () => { /** https://kitsunes.dev/api/swagger#/repository/repoGetAllCommits */ - const kitsudev = await parseJson(await fetch(`https://kitsunes.dev/api/v1/repos/${username}/${repository}/commits?limit=1`)) as [{ + const kitsudev = await parseJson(await fetch(`https://kitsunes.dev/api/v1/repos/${username}/${repository}/commits?limit=1`, {headers})) as [{ html_url: string commit: { author: { diff --git a/api/infos/website/umami.ts b/api/infos/website/umami.ts index b4d25a9..6ca7f88 100644 --- a/api/infos/website/umami.ts +++ b/api/infos/website/umami.ts @@ -1,4 +1,4 @@ -import { parseJson, type Handler } from "../.."; +import { headers, parseJson, type Handler } from "../.."; import type { UmamiInfo } from "#Infos/Website/Umami.tsx"; import { db, getToken } from "../../../database.ts"; @@ -13,7 +13,7 @@ export const umami: Handler = async () => { // Not using the package directly because of serious issues I consider it to have const umami = await parseJson(await fetch(`${api_server}/websites/${website_id}/stats?startAt=${Number(sevendaysago)}&endAt=${Number(now)}`, { headers: { - "Accept": "application/json", + ...headers, "Authorization": `Bearer ${token?.access_token}` }, })) as UmamiInfo;