Add WaniKani

This commit is contained in:
Taevas 2023-11-01 21:15:29 +01:00
parent d2dfb621f4
commit ea09afc2d9
8 changed files with 248 additions and 9 deletions

View file

@ -1,7 +1,7 @@
import fetch from "node-fetch"
export async function api<T>(url: string): Promise<T> {
return fetch(url)
export async function api<T>(url: string, restful_token?: string): Promise<T> {
return (restful_token ? fetch(url, {headers: {"Authorization": `Bearer ${restful_token}`}}) : fetch(url))
.then(response => {
if (!response.ok) {
console.error(response.status, response.statusText)