Untitled

 avatar
unknown
plain_text
3 years ago
1.3 kB
3
Indexable
import SwaggerClient from 'swagger-client';

interface KMId {
  killmail_id: number;
  zkb: {
    locationID: number;
    hash: string;
    fittedValue: number;
    droppedValue: number;
    destroyedValue: number;
    totalValue: number;
    points: number;
    npc: boolean;
    solo: boolean;
    awox: boolean;
  };
}
export default class API {
  static Swagger = new SwaggerClient(
    'https://esi.evetech.net/latest/swagger.json'
  );

  static async fetchKMs(kmsId: KMId[]) {
    const client = await API.Swagger;
    return Promise.all(
      kmsId.map(async (kmId) => {
        const resp =
          await client.apis.Killmails.get_killmails_killmail_id_killmail_hash({
            killmail_id: kmId.killmail_id,
            killmail_hash: kmId.zkb.hash,
          });
        return resp.obj;
      })
    );
  }

  static async fetchKillsIds(character: number): Promise<KMId[]> {
    const respKills = await fetch(
      `https://zkillboard.com/api/kills/characterID/${character}/`
    );
    return respKills.json();
  }

  static async fetchLossesIds(character: number): Promise<KMId[]> {
    const respLosses = await fetch(
      `https://zkillboard.com/api/losses/characterID/${character}/`
    );
    return respLosses.json();
  }
}
Editor is loading...