1
0
Fork 0

Another big refactoring

This commit is contained in:
Julien Dessaux 2023-06-01 01:11:21 +02:00
parent 61b5c8493e
commit 68c457964a
Signed by: adyxax
GPG key ID: F92E51B86E07177E
10 changed files with 79 additions and 83 deletions

View file

@ -1,25 +1,6 @@
import * as api from './api.js';
import * as db from '../database/systems.js';
// Retrieves all systems information, should be called only once after registering
export async function init(ctx) {
if (db.isInit()) {
return;
}
for (let page=1; true; ++page) {
const response = await api.send({endpoint: `/systems?limit=20&page=${page}`, priority:100});
if (response.error !== undefined) {
throw response;
}
response.data.forEach(system => db.setSystem(system));
if (response.meta.total <= response.meta.limit * page) {
break;
}
}
console.log('Finished retrieving all systems information');
db.init();
}
// Retrieves a shipyard's information for ctx.symbol
export async function shipyard(ctx) {
const systemSymbol = ctx.symbol.match(/([^-]+-[^-]+)/)[1]; // TODO generalise this extraction