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();
|
require("dotenv").config();
|
||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
const semver = require('semver');
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bodyParser = require("body-parser");
|
const bodyParser = require("body-parser");
|
||||||
const status = require("http-status");
|
const status = require("http-status");
|
||||||
@ -113,11 +114,35 @@ class FE_Charts {
|
|||||||
limit: 1,
|
limit: 1,
|
||||||
order: [["Dttm_Last_Update", "DESC"]],
|
order: [["Dttm_Last_Update", "DESC"]],
|
||||||
}).then(results => {
|
}).then(results => {
|
||||||
version = results;
|
version = results[0].version;
|
||||||
}).catch(err => FE_Charts.logError(err));
|
}).catch(err => FE_Charts.logError(err));
|
||||||
return version;
|
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;
|
exports.FE_Charts = FE_Charts;
|
||||||
app.get('/', (req, res) => {
|
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* () {
|
app.get('/all', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const characters = yield FE_Charts.getAllCharacters();
|
const data = yield FE_Charts.getAllData();
|
||||||
const characterGrowthRates = yield FE_Charts.getAllCharactersGrowthRates();
|
res.status(status.OK).send(data);
|
||||||
const classesGrowthRates = yield FE_Charts.getAllClassesGrowthRates();
|
}));
|
||||||
const classes = yield FE_Charts.getAllClasses();
|
app.post('/update', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const genders = yield FE_Charts.getAllGenders();
|
const clientVersion = req.body.version;
|
||||||
const houses = yield FE_Charts.getAllHouses();
|
if (clientVersion) {
|
||||||
const restrictedClasses = yield FE_Charts.getAllRestrictedClasses();
|
FE_Charts.getCatalogueLastVersion().then((version) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const stats = yield FE_Charts.getAllStats();
|
try {
|
||||||
res.status(status.OK).send({
|
if (semver.gt(version, clientVersion)) {
|
||||||
characters: characters,
|
const data = yield FE_Charts.getAllData();
|
||||||
charGrowthRates: characterGrowthRates,
|
res.status(status.OK).send(data);
|
||||||
classGrowthRates: classesGrowthRates,
|
}
|
||||||
classes: classes,
|
else {
|
||||||
genders: genders,
|
res.status(status.OK).send(); // Catalogue up-to-date
|
||||||
houses: houses,
|
}
|
||||||
restrictedClasses: restrictedClasses,
|
}
|
||||||
stats: stats,
|
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
|
// Don't start the server if we're importing some data
|
||||||
if (process.argv.find(x => x == argImport) == undefined) {
|
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",
|
"express": "^4.17.1",
|
||||||
"http-status": "^1.4.1",
|
"http-status": "^1.4.1",
|
||||||
"mysql2": "^2.0.1",
|
"mysql2": "^2.0.1",
|
||||||
|
"semver": "^6.3.0",
|
||||||
"sequelize": "^5.21.2"
|
"sequelize": "^5.21.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
const semver = require('semver');
|
||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import * as bodyParser from "body-parser";
|
import * as bodyParser from "body-parser";
|
||||||
import * as status from "http-status";
|
import * as status from "http-status";
|
||||||
@ -9,7 +10,7 @@ const {Catalogue, Character, CharacterGrowthRate, ClassGrowthRate, FE_Class, Gen
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.NODE_PORT || 3000;
|
const port = process.env.NODE_PORT || 3000;
|
||||||
const argImport:string = "importing";
|
const argImport: string = "importing";
|
||||||
|
|
||||||
app.use(bodyParser.urlencoded({extended: false}));
|
app.use(bodyParser.urlencoded({extended: false}));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
@ -99,10 +100,34 @@ abstract class FE_Charts {
|
|||||||
limit: 1,
|
limit: 1,
|
||||||
order: [["Dttm_Last_Update", "DESC"]],
|
order: [["Dttm_Last_Update", "DESC"]],
|
||||||
}).then(results => {
|
}).then(results => {
|
||||||
version = results
|
version = results[0].version;
|
||||||
}).catch(err => FE_Charts.logError(err));
|
}).catch(err => FE_Charts.logError(err));
|
||||||
return version;
|
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) => {
|
app.get('/', (req, res) => {
|
||||||
@ -116,25 +141,29 @@ app.get('/version', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/all', async (req, res) => {
|
app.get('/all', async (req, res) => {
|
||||||
const characters = await FE_Charts.getAllCharacters();
|
const data = await FE_Charts.getAllData();
|
||||||
const characterGrowthRates = await FE_Charts.getAllCharactersGrowthRates();
|
res.status(status.OK).send(data);
|
||||||
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();
|
|
||||||
|
|
||||||
res.status(status.OK).send({
|
app.post('/update', async (req, res) => {
|
||||||
characters: characters,
|
const clientVersion = req.body.version;
|
||||||
charGrowthRates: characterGrowthRates,
|
|
||||||
classGrowthRates: classesGrowthRates,
|
if (clientVersion) {
|
||||||
classes: classes,
|
FE_Charts.getCatalogueLastVersion().then(async (version) => {
|
||||||
genders: genders,
|
try {
|
||||||
houses: houses,
|
if (semver.gt(version, clientVersion)) {
|
||||||
restrictedClasses: restrictedClasses,
|
const data = await FE_Charts.getAllData();
|
||||||
stats: stats,
|
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
|
// Don't start the server if we're importing some data
|
||||||
|
Reference in New Issue
Block a user