noot
This commit is contained in:
parent
2eb167b33d
commit
4368ec9104
5
package.json
Normal file
5
package.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"axios-cache-interceptor": "^1.6.2"
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
|
import { c } from "#/di";
|
||||||
import { WApiV3ItemDatabase } from "#/lib/wynn/types";
|
import { WApiV3ItemDatabase } from "#/lib/wynn/types";
|
||||||
import { WApi } from "#/lib/wynn/wapi";
|
import { WApi } from "#/lib/wynn/wapi";
|
||||||
import { ArkError, ArkErrors } from "arktype";
|
import { ArkErrors } from "arktype";
|
||||||
|
|
||||||
export async function update_wynn_items() {
|
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: ''})
|
const ans = await api.get('/v3/item/database', {fullResult: ''})
|
||||||
if(ans.status !== 200){
|
if(ans.status !== 200){
|
||||||
throw new Error('Failed to get wynn items')
|
throw new Error('Failed to get wynn items')
|
||||||
|
@ -6,7 +6,7 @@ import { type } from "arktype";
|
|||||||
import {parseDate} from "chrono-node";
|
import {parseDate} from "chrono-node";
|
||||||
|
|
||||||
export async function update_all_guilds() {
|
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')
|
const ans = await api.get('/v3/guild/list/guild')
|
||||||
if(ans.status !== 200){
|
if(ans.status !== 200){
|
||||||
throw new Error('Failed to get guild list from wapi')
|
throw new Error('Failed to get guild list from wapi')
|
||||||
@ -38,8 +38,7 @@ export async function update_guild({
|
|||||||
}:{
|
}:{
|
||||||
guild_name: string
|
guild_name: string
|
||||||
}) {
|
}) {
|
||||||
const api = new WApi()
|
const api = await c.getAsync(WApi)
|
||||||
|
|
||||||
const ans = await api.get(`/v3/guild/${guild_name}`)
|
const ans = await api.get(`/v3/guild/${guild_name}`)
|
||||||
if(ans.status !== 200){
|
if(ans.status !== 200){
|
||||||
throw new Error('Failed to get guild into from wapi')
|
throw new Error('Failed to get guild into from wapi')
|
||||||
|
@ -57,7 +57,7 @@ const playerSchema = playerSchemaFail.or(playerSchemaSuccess)
|
|||||||
|
|
||||||
export const scrape_online_players = async()=>{
|
export const scrape_online_players = async()=>{
|
||||||
|
|
||||||
const api = new WApi()
|
const api = await c.getAsync(WApi)
|
||||||
const raw = await api.get('/v3/player')
|
const raw = await api.get('/v3/player')
|
||||||
const onlineList = type({
|
const onlineList = type({
|
||||||
total: "number",
|
total: "number",
|
||||||
|
@ -16,6 +16,8 @@ const schemaConfig = {
|
|||||||
PG_DATABASE: z.string().optional(),
|
PG_DATABASE: z.string().optional(),
|
||||||
PG_PORT: z.number().int().optional(),
|
PG_PORT: z.number().int().optional(),
|
||||||
PG_SSLMODE: z.string().optional(),
|
PG_SSLMODE: z.string().optional(),
|
||||||
|
|
||||||
|
WAPI_URL: z.string().default("https://api.wynncraft.com/"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 {
|
export class WApi {
|
||||||
|
|
||||||
c: AxiosInstance
|
c: AxiosInstance
|
||||||
|
|
||||||
constructor(endpoint: string = `https://api.wynncraft.com/`) {
|
constructor() {
|
||||||
this.c = axios.create({
|
const c = axios.create({
|
||||||
baseURL: endpoint,
|
baseURL: config.WAPI_URL,
|
||||||
})
|
})
|
||||||
|
setupCache(c);
|
||||||
|
this.c = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(path:string, params?: any) {
|
async get(path:string, params?: any) {
|
||||||
|
27
yarn.lock
Normal file
27
yarn.lock
Normal 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==
|
Loading…
Reference in New Issue
Block a user