Add route to update catalogue
This commit is contained in:
69
server/dist/index.js
vendored
69
server/dist/index.js
vendored
@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv").config();
|
||||
const axios = require('axios').default;
|
||||
const cheerio = require('cheerio');
|
||||
const semver = require('semver');
|
||||
const express = require("express");
|
||||
const bodyParser = require("body-parser");
|
||||
const status = require("http-status");
|
||||
@ -113,11 +114,35 @@ class FE_Charts {
|
||||
limit: 1,
|
||||
order: [["Dttm_Last_Update", "DESC"]],
|
||||
}).then(results => {
|
||||
version = results;
|
||||
version = results[0].version;
|
||||
}).catch(err => FE_Charts.logError(err));
|
||||
return version;
|
||||
});
|
||||
}
|
||||
static getAllData() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const version = yield this.getCatalogueLastVersion();
|
||||
const characters = yield FE_Charts.getAllCharacters();
|
||||
const characterGrowthRates = yield FE_Charts.getAllCharactersGrowthRates();
|
||||
const classesGrowthRates = yield FE_Charts.getAllClassesGrowthRates();
|
||||
const classes = yield FE_Charts.getAllClasses();
|
||||
const genders = yield FE_Charts.getAllGenders();
|
||||
const houses = yield FE_Charts.getAllHouses();
|
||||
const restrictedClasses = yield FE_Charts.getAllRestrictedClasses();
|
||||
const stats = yield FE_Charts.getAllStats();
|
||||
return {
|
||||
version: version,
|
||||
characters: characters,
|
||||
charGrowthRates: characterGrowthRates,
|
||||
classGrowthRates: classesGrowthRates,
|
||||
classes: classes,
|
||||
genders: genders,
|
||||
houses: houses,
|
||||
restrictedClasses: restrictedClasses,
|
||||
stats: stats,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.FE_Charts = FE_Charts;
|
||||
app.get('/', (req, res) => {
|
||||
@ -129,24 +154,30 @@ app.get('/version', (req, res) => {
|
||||
});
|
||||
});
|
||||
app.get('/all', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const characters = yield FE_Charts.getAllCharacters();
|
||||
const characterGrowthRates = yield FE_Charts.getAllCharactersGrowthRates();
|
||||
const classesGrowthRates = yield FE_Charts.getAllClassesGrowthRates();
|
||||
const classes = yield FE_Charts.getAllClasses();
|
||||
const genders = yield FE_Charts.getAllGenders();
|
||||
const houses = yield FE_Charts.getAllHouses();
|
||||
const restrictedClasses = yield FE_Charts.getAllRestrictedClasses();
|
||||
const stats = yield FE_Charts.getAllStats();
|
||||
res.status(status.OK).send({
|
||||
characters: characters,
|
||||
charGrowthRates: characterGrowthRates,
|
||||
classGrowthRates: classesGrowthRates,
|
||||
classes: classes,
|
||||
genders: genders,
|
||||
houses: houses,
|
||||
restrictedClasses: restrictedClasses,
|
||||
stats: stats,
|
||||
});
|
||||
const data = yield FE_Charts.getAllData();
|
||||
res.status(status.OK).send(data);
|
||||
}));
|
||||
app.post('/update', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const clientVersion = req.body.version;
|
||||
if (clientVersion) {
|
||||
FE_Charts.getCatalogueLastVersion().then((version) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
try {
|
||||
if (semver.gt(version, clientVersion)) {
|
||||
const data = yield FE_Charts.getAllData();
|
||||
res.status(status.OK).send(data);
|
||||
}
|
||||
else {
|
||||
res.status(status.OK).send(); // Catalogue up-to-date
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
res.status(status.INTERNAL_SERVER_ERROR).send(e.message);
|
||||
}
|
||||
}));
|
||||
}
|
||||
else {
|
||||
res.status(status.BAD_REQUEST).send("'version' parameter undefined");
|
||||
}
|
||||
}));
|
||||
// Don't start the server if we're importing some data
|
||||
if (process.argv.find(x => x == argImport) == undefined) {
|
||||
|
2
server/dist/index.js.map
vendored
2
server/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@ -33,6 +33,7 @@
|
||||
"express": "^4.17.1",
|
||||
"http-status": "^1.4.1",
|
||||
"mysql2": "^2.0.1",
|
||||
"semver": "^6.3.0",
|
||||
"sequelize": "^5.21.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,6 +1,7 @@
|
||||
require("dotenv").config();
|
||||
const axios = require('axios').default;
|
||||
const cheerio = require('cheerio');
|
||||
const semver = require('semver');
|
||||
import * as express from "express";
|
||||
import * as bodyParser from "body-parser";
|
||||
import * as status from "http-status";
|
||||
@ -9,7 +10,7 @@ const {Catalogue, Character, CharacterGrowthRate, ClassGrowthRate, FE_Class, Gen
|
||||
|
||||
const app = express();
|
||||
const port = process.env.NODE_PORT || 3000;
|
||||
const argImport:string = "importing";
|
||||
const argImport: string = "importing";
|
||||
|
||||
app.use(bodyParser.urlencoded({extended: false}));
|
||||
app.use(bodyParser.json());
|
||||
@ -99,10 +100,34 @@ abstract class FE_Charts {
|
||||
limit: 1,
|
||||
order: [["Dttm_Last_Update", "DESC"]],
|
||||
}).then(results => {
|
||||
version = results
|
||||
version = results[0].version;
|
||||
}).catch(err => FE_Charts.logError(err));
|
||||
return version;
|
||||
}
|
||||
|
||||
static async getAllData() {
|
||||
const version = await this.getCatalogueLastVersion();
|
||||
const characters = await FE_Charts.getAllCharacters();
|
||||
const characterGrowthRates = await FE_Charts.getAllCharactersGrowthRates();
|
||||
const classesGrowthRates = await FE_Charts.getAllClassesGrowthRates();
|
||||
const classes = await FE_Charts.getAllClasses();
|
||||
const genders = await FE_Charts.getAllGenders();
|
||||
const houses = await FE_Charts.getAllHouses();
|
||||
const restrictedClasses = await FE_Charts.getAllRestrictedClasses();
|
||||
const stats = await FE_Charts.getAllStats();
|
||||
|
||||
return {
|
||||
version: version,
|
||||
characters: characters,
|
||||
charGrowthRates: characterGrowthRates,
|
||||
classGrowthRates: classesGrowthRates,
|
||||
classes: classes,
|
||||
genders: genders,
|
||||
houses: houses,
|
||||
restrictedClasses: restrictedClasses,
|
||||
stats: stats,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
@ -116,25 +141,29 @@ app.get('/version', (req, res) => {
|
||||
});
|
||||
|
||||
app.get('/all', async (req, res) => {
|
||||
const characters = await FE_Charts.getAllCharacters();
|
||||
const characterGrowthRates = await FE_Charts.getAllCharactersGrowthRates();
|
||||
const classesGrowthRates = await FE_Charts.getAllClassesGrowthRates();
|
||||
const classes = await FE_Charts.getAllClasses();
|
||||
const genders = await FE_Charts.getAllGenders();
|
||||
const houses = await FE_Charts.getAllHouses();
|
||||
const restrictedClasses = await FE_Charts.getAllRestrictedClasses();
|
||||
const stats = await FE_Charts.getAllStats();
|
||||
const data = await FE_Charts.getAllData();
|
||||
res.status(status.OK).send(data);
|
||||
});
|
||||
|
||||
res.status(status.OK).send({
|
||||
characters: characters,
|
||||
charGrowthRates: characterGrowthRates,
|
||||
classGrowthRates: classesGrowthRates,
|
||||
classes: classes,
|
||||
genders: genders,
|
||||
houses: houses,
|
||||
restrictedClasses: restrictedClasses,
|
||||
stats: stats,
|
||||
app.post('/update', async (req, res) => {
|
||||
const clientVersion = req.body.version;
|
||||
|
||||
if (clientVersion) {
|
||||
FE_Charts.getCatalogueLastVersion().then(async (version) => {
|
||||
try {
|
||||
if (semver.gt(version, clientVersion)) {
|
||||
const data = await FE_Charts.getAllData();
|
||||
res.status(status.OK).send(data);
|
||||
} else {
|
||||
res.status(status.OK).send(); // Catalogue up-to-date
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(status.INTERNAL_SERVER_ERROR).send(e.message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(status.BAD_REQUEST).send("'version' parameter undefined");
|
||||
}
|
||||
});
|
||||
|
||||
// Don't start the server if we're importing some data
|
||||
|
Reference in New Issue
Block a user