Skip to content

Commit

Permalink
Add very not optimised untested hiei stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
0t4u committed May 13, 2021
1 parent 700c9cd commit 8d6811f
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 198 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azurapi/azurapi",
"version": "1.0.3",
"version": "1.0.4",
"description": "Open Source Azur Lane Local Database",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@augu/eslint-config": "^1.8.2",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"@types/node": "^14.14.45",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"eslint": "^7.17.0",
Expand Down
113 changes: 67 additions & 46 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import Updater from './core/CacheUpdater';
import { Ships } from './core/api/api_ship';
import { Equipments } from './core/api/api_equipment';
import { Barrages } from './core/api/api_barrage';
import API from './core/api/api';
import { Equipment } from './types/equipment';
import { Chapter } from './types/chapter';
import { Voiceline } from './types/voiceline';
import { Barrage } from './types/barrage';
import { Chapters } from './core/api/api_chapter';
import { Voicelines } from './core/api/api_voiceline';
import * as Hiei from './core/api/hiei';
import { datatype } from './core/Data';

export type Source = 'uncached' | 'local' | 'hiei'

export interface CacheOptions {
source?: Source;
autoupdate?: boolean;
rate?: number;
source?: Source;
autoupdate?: boolean;
rate?: number;
hieiUrl?: string;
hieiAuth?: string;
}

export let instance: AzurAPI;
Expand All @@ -24,49 +24,70 @@ export let instance: AzurAPI;
* The main AzurAPI class
*/
export class AzurAPI extends EventEmitter {
public options: CacheOptions;
public source: string;
public autoupdate: boolean;
public rate: number;
public updater: Updater;
public ships = new Ships(this);
public equipments = new Equipments(this);
public chapters = new API<Chapter>(this);
public voicelines = new API<Voiceline>(this);
public barrages = new Barrages(this);
public apis = {
public options: CacheOptions;
public source: string;
public autoupdate: boolean;
public rate: number;
public updater: Updater;
public ships: Ships | Hiei.Ships/* = new Ships(this)*/;
public equipments: Equipments | Hiei.Equipments/* = new Equipments(this)*/;
public chapters: Chapters | Hiei.Chapters/* = new Chapters(this)*/;
public voicelines: Voicelines | Hiei.Voicelines/* = new Voicelines(this)*/;
public barrages: Barrages | Hiei.Barrages/* = new Barrages(this)*/;
public apis: object/* = {
ships: this.ships,
equipments: this.equipments,
chapters: this.chapters,
voicelines: this.voicelines,
barrages: this.barrages
}*/;

/**
* Cache client
* @param options options for the cache
*/
constructor(options?: CacheOptions) {
super();
this.options = options ? options : { source: 'local', autoupdate: true, rate: 3600000 };
this.source = this.options.source ? this.options.source : 'local';
this.autoupdate = this.options.autoupdate ? this.options.autoupdate : true;
this.rate = this.options.rate ? this.options.rate : 3600000;
if (this.source === 'hiei' && !this.options.hieiUrl) throw new Error('Option "hieiUrl" cannot be undefined when "source" is set to "hiei"');
if (this.source === 'hiei') {
this.ships = new Hiei.Ships(this);
this.equipments = new Hiei.Equipments(this);
this.chapters = new Hiei.Chapters(this);
this.voicelines = new Hiei.Voicelines(this);
this.barrages = new Hiei.Barrages(this);
} else {
this.ships = new Ships(this);
this.equipments = new Equipments(this);
this.chapters = new Chapters(this);
this.voicelines = new Voicelines(this);
this.barrages = new Barrages(this);
}
this.apis = {
ships: this.ships,
equipments: this.equipments,
chapters: this.chapters,
voicelines: this.voicelines,
barrages: this.barrages
};
this.updater = new Updater(this);
this.updater.init();
if (this.autoupdate && this.source === 'local') this.updater.start();
instance = this;
}

/**
* Cache client
* @param options options for the cache
*/
constructor(options?: CacheOptions) {
super();
this.options = options ? options : { source: 'local', autoupdate: true, rate: 3600000 };
this.source = this.options.source ? this.options.source : 'local';
this.autoupdate = this.options.autoupdate ? this.options.autoupdate : true;
this.rate = this.options.rate ? this.options.rate : 3600000;
this.updater = new Updater(this);
this.updater.init();
if (this.autoupdate) this.updater.start();
instance = this;
}

/**
* Set data in cache
* @param type A type of data (ship, equipment, voiceline, chapter, or barrage)
* @param raw Raw data in array
*/
set(type: datatype, raw: any[]) {
if (!raw) return;
let api = this.apis[type];
if (api) api.setData(raw);
return api;
}
/**
* Set data in cache
* @param type A type of data (ship, equipment, voiceline, chapter, or barrage)
* @param raw Raw data in array
*/
set(type: datatype, raw: any[]) {
if (!raw) return;
let api = this.apis[type];
if (api) api.setData(raw);
return api;
}
}
Loading

0 comments on commit 8d6811f

Please sign in to comment.