Rename stats API endpoints
This commit is contained in:
parent
d6f5e63d85
commit
26ebb417f4
|
@ -172,7 +172,7 @@ async function characterStatsHandler(characters, this_chid) {
|
||||||
* Fetches the character stats from the server.
|
* Fetches the character stats from the server.
|
||||||
*/
|
*/
|
||||||
async function getStats() {
|
async function getStats() {
|
||||||
const response = await fetch('/getstats', {
|
const response = await fetch('/api/stats/get', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
|
@ -189,13 +189,13 @@ async function getStats() {
|
||||||
/**
|
/**
|
||||||
* Asynchronously recreates the stats file from chat files.
|
* Asynchronously recreates the stats file from chat files.
|
||||||
*
|
*
|
||||||
* Sends a POST request to the "/recreatestats" endpoint. If the request fails,
|
* Sends a POST request to the "/api/stats/recreate" endpoint. If the request fails,
|
||||||
* it displays an error notification and throws an error.
|
* it displays an error notification and throws an error.
|
||||||
*
|
*
|
||||||
* @throws {Error} If the request to recreate stats is unsuccessful.
|
* @throws {Error} If the request to recreate stats is unsuccessful.
|
||||||
*/
|
*/
|
||||||
async function recreateStats() {
|
async function recreateStats() {
|
||||||
const response = await fetch('/recreatestats', {
|
const response = await fetch('/api/stats/recreate', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
|
@ -232,7 +232,7 @@ function calculateGenTime(gen_started, gen_finished) {
|
||||||
* Sends a POST request to the server to update the statistics.
|
* Sends a POST request to the server to update the statistics.
|
||||||
*/
|
*/
|
||||||
async function updateStats() {
|
async function updateStats() {
|
||||||
const response = await fetch('/updatestats', {
|
const response = await fetch('/api/stats/update', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify(charStats),
|
body: JSON.stringify(charStats),
|
||||||
|
|
13
server.js
13
server.js
|
@ -788,13 +788,11 @@ app.post('/getstatus', jsonParser, async function (request, response) {
|
||||||
* @param {Object} response - The HTTP response object.
|
* @param {Object} response - The HTTP response object.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
app.post('/getstats', jsonParser, function (request, response) {
|
app.post('/api/stats/get', jsonParser, function (request, response) {
|
||||||
response.send(JSON.stringify(statsHelpers.getCharStats()));
|
response.send(JSON.stringify(statsHelpers.getCharStats()));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Endpoint: POST /recreatestats
|
|
||||||
*
|
|
||||||
* Triggers the recreation of statistics from chat files.
|
* Triggers the recreation of statistics from chat files.
|
||||||
* - If successful: returns a 200 OK status.
|
* - If successful: returns a 200 OK status.
|
||||||
* - On failure: returns a 500 Internal Server Error status.
|
* - On failure: returns a 500 Internal Server Error status.
|
||||||
|
@ -802,7 +800,7 @@ app.post('/getstats', jsonParser, function (request, response) {
|
||||||
* @param {Object} request - Express request object.
|
* @param {Object} request - Express request object.
|
||||||
* @param {Object} response - Express response object.
|
* @param {Object} response - Express response object.
|
||||||
*/
|
*/
|
||||||
app.post('/recreatestats', jsonParser, async function (request, response) {
|
app.post('/api/stats/recreate', jsonParser, async function (request, response) {
|
||||||
try {
|
try {
|
||||||
await statsHelpers.recreateStats(DIRECTORIES.chats, DIRECTORIES.characters);
|
await statsHelpers.recreateStats(DIRECTORIES.chats, DIRECTORIES.characters);
|
||||||
return response.sendStatus(200);
|
return response.sendStatus(200);
|
||||||
|
@ -823,7 +821,7 @@ app.post('/recreatestats', jsonParser, async function (request, response) {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
app.post('/updatestats', jsonParser, function (request, response) {
|
app.post('/api/stats/update', jsonParser, function (request, response) {
|
||||||
if (!request.body) return response.sendStatus(400);
|
if (!request.body) return response.sendStatus(400);
|
||||||
statsHelpers.setCharStats(request.body);
|
statsHelpers.setCharStats(request.body);
|
||||||
return response.sendStatus(200);
|
return response.sendStatus(200);
|
||||||
|
@ -2051,6 +2049,11 @@ redirect('/deleteworldinfo', '/api/worldinfo/delete');
|
||||||
redirect('/importworldinfo', '/api/worldinfo/import');
|
redirect('/importworldinfo', '/api/worldinfo/import');
|
||||||
redirect('/editworldinfo', '/api/worldinfo/edit');
|
redirect('/editworldinfo', '/api/worldinfo/edit');
|
||||||
|
|
||||||
|
// Redirect deprecated stats API endpoints
|
||||||
|
redirect('/getstats', '/api/stats/get');
|
||||||
|
redirect('/recreatestats', '/api/stats/recreate');
|
||||||
|
redirect('/updatestats', '/api/stats/update');
|
||||||
|
|
||||||
// ** REST CLIENT ASYNC WRAPPERS **
|
// ** REST CLIENT ASYNC WRAPPERS **
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue