noot
Some checks failed
commit-tag / commit-tag-image (push) Has been cancelled
commit-tag / commit-tag-image (./cmd/caddy) (push) Has been cancelled

This commit is contained in:
a 2025-03-02 03:23:41 -06:00
parent 2eb167b33d
commit 4368ec9104
No known key found for this signature in database
GPG Key ID: 2F22877AA4DFDADB
7 changed files with 50 additions and 12 deletions

5
package.json Normal file
View File

@ -0,0 +1,5 @@
{
"dependencies": {
"axios-cache-interceptor": "^1.6.2"
}
}

View File

@ -1,10 +1,11 @@
import { c } from "#/di";
import { WApiV3ItemDatabase } from "#/lib/wynn/types";
import { WApi } from "#/lib/wynn/wapi";
import { ArkError, ArkErrors } from "arktype";
import { ArkErrors } from "arktype";
export async function update_wynn_items() {
const api = new WApi()
const api = await c.getAsync(WApi)
const ans = await api.get('/v3/item/database', {fullResult: ''})
if(ans.status !== 200){
throw new Error('Failed to get wynn items')

View File

@ -6,7 +6,7 @@ import { type } from "arktype";
import {parseDate} from "chrono-node";
export async function update_all_guilds() {
const api = new WApi()
const api = await c.getAsync(WApi)
const ans = await api.get('/v3/guild/list/guild')
if(ans.status !== 200){
throw new Error('Failed to get guild list from wapi')
@ -38,8 +38,7 @@ export async function update_guild({
}:{
guild_name: string
}) {
const api = new WApi()
const api = await c.getAsync(WApi)
const ans = await api.get(`/v3/guild/${guild_name}`)
if(ans.status !== 200){
throw new Error('Failed to get guild into from wapi')

View File

@ -57,7 +57,7 @@ const playerSchema = playerSchemaFail.or(playerSchemaSuccess)
export const scrape_online_players = async()=>{
const api = new WApi()
const api = await c.getAsync(WApi)
const raw = await api.get('/v3/player')
const onlineList = type({
total: "number",

View File

@ -16,6 +16,8 @@ const schemaConfig = {
PG_DATABASE: z.string().optional(),
PG_PORT: z.number().int().optional(),
PG_SSLMODE: z.string().optional(),
WAPI_URL: z.string().default("https://api.wynncraft.com/"),
};

View File

@ -1,15 +1,19 @@
import axios, { Axios, AxiosInstance } from "axios";
import { config } from "#/config";
import { injectable } from "@needle-di/core";
import axios, { AxiosInstance } from "axios";
import { setupCache } from 'axios-cache-interceptor';
@injectable()
export class WApi {
c: AxiosInstance
constructor(endpoint: string = `https://api.wynncraft.com/`) {
this.c = axios.create({
baseURL: endpoint,
constructor() {
const c = axios.create({
baseURL: config.WAPI_URL,
})
setupCache(c);
this.c = c;
}
async get(path:string, params?: any) {

27
yarn.lock Normal file
View File

@ -0,0 +1,27 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
axios-cache-interceptor@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/axios-cache-interceptor/-/axios-cache-interceptor-1.6.2.tgz#0aca85d14ee8fae8d48491f16f6e1bdc87a4056b"
integrity sha512-YLbAODIHZZIcD4b3WYFVQOa5W2TY/WnJ6sBHqAg6Z+hx+RVj8/OcjQyRopO6awn7/kOkGL5X9TP16AucnlJ/lw==
dependencies:
cache-parser "1.2.5"
fast-defer "1.1.8"
object-code "1.3.3"
cache-parser@1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/cache-parser/-/cache-parser-1.2.5.tgz#f19102a788b03055389730eb0493e463e1b379ac"
integrity sha512-Md/4VhAHByQ9frQ15WD6LrMNiVw9AEl/J7vWIXw+sxT6fSOpbtt6LHTp76vy8+bOESPBO94117Hm2bIjlI7XjA==
fast-defer@1.1.8:
version "1.1.8"
resolved "https://registry.yarnpkg.com/fast-defer/-/fast-defer-1.1.8.tgz#940ef9597b2ea51c4cd08e99d0f2a8978fa49ba2"
integrity sha512-lEJeOH5VL5R09j6AA0D4Uvq7AgsHw0dAImQQ+F3iSyHZuAxyQfWobsagGpTcOPvJr3urmKRHrs+Gs9hV+/Qm/Q==
object-code@1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/object-code/-/object-code-1.3.3.tgz#cf21843ddfecce3ec73fd141f66a7f16ba0cb93e"
integrity sha512-/Ds4Xd5xzrtUOJ+xJQ57iAy0BZsZltOHssnDgcZ8DOhgh41q1YJCnTPnWdWSLkNGNnxYzhYChjc5dgC9mEERCA==