Use custom headers to possibly bypass Anubis & co
As recommended by the kind Kio! (so now most requests use a custom user-agent)
This commit is contained in:
parent
f8987cdcdb
commit
9818adb12d
12 changed files with 30 additions and 26 deletions
|
@ -27,6 +27,12 @@ const info_routes: Record<string, Handler[]> = {
|
|||
|
||||
export type Handler = (req: URLSearchParams) => Promise<Response>;
|
||||
|
||||
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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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[];
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue