From 2367f4f38fb4421af057546793e80fdc12e1e59b Mon Sep 17 00:00:00 2001 From: valadaptive Date: Thu, 7 Dec 2023 15:17:19 -0500 Subject: [PATCH] Rename backgrounds API endpoints --- public/scripts/backgrounds.js | 10 +++++----- server.js | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/public/scripts/backgrounds.js b/public/scripts/backgrounds.js index bc52c2f22..70465122e 100644 --- a/public/scripts/backgrounds.js +++ b/public/scripts/backgrounds.js @@ -238,7 +238,7 @@ async function onRenameBackgroundClick(e) { } const data = { old_bg: bgNames.oldBg, new_bg: bgNames.newBg }; - const response = await fetch('/renamebackground', { + const response = await fetch('/api/backgrounds/rename', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify(data), @@ -326,7 +326,7 @@ async function autoBackgroundCommand() { } export async function getBackgrounds() { - const response = await fetch('/getbackgrounds', { + const response = await fetch('/api/backgrounds/all', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ @@ -378,7 +378,7 @@ function getBackgroundFromTemplate(bg, isCustom) { async function setBackground(bg) { jQuery.ajax({ type: 'POST', // - url: '/setbackground', // + url: '/api/backgrounds/set', // data: JSON.stringify({ bg: bg, }), @@ -398,7 +398,7 @@ async function setBackground(bg) { } async function delBackground(bg) { - await fetch('/delbackground', { + await fetch('/api/backgrounds/delete', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ @@ -427,7 +427,7 @@ function onBackgroundUploadSelected() { function uploadBackground(formData) { jQuery.ajax({ type: 'POST', - url: '/downloadbackground', + url: '/api/backgrounds/upload', data: formData, beforeSend: function () { }, diff --git a/server.js b/server.js index 32bff0962..e3abec476 100644 --- a/server.js +++ b/server.js @@ -777,7 +777,7 @@ app.post('/getstatus', jsonParser, async function (request, response) { -app.post('/getbackgrounds', jsonParser, function (request, response) { +app.post('/api/backgrounds/all', jsonParser, function (request, response) { var images = getImages('public/backgrounds'); response.send(JSON.stringify(images)); @@ -807,7 +807,7 @@ app.post('/deleteuseravatar', jsonParser, function (request, response) { return response.sendStatus(404); }); -app.post('/setbackground', jsonParser, function (request, response) { +app.post('/api/backgrounds/set', jsonParser, function (request, response) { try { const bg = `#bg1 {background-image: url('../backgrounds/${request.body.bg}');}`; writeFileAtomicSync('public/css/bg_load.css', bg, 'utf8'); @@ -818,7 +818,7 @@ app.post('/setbackground', jsonParser, function (request, response) { } }); -app.post('/delbackground', jsonParser, function (request, response) { +app.post('/api/backgrounds/delete', jsonParser, function (request, response) { if (!request.body) return response.sendStatus(400); if (request.body.bg !== sanitize(request.body.bg)) { @@ -838,7 +838,7 @@ app.post('/delbackground', jsonParser, function (request, response) { return response.send('ok'); }); -app.post('/renamebackground', jsonParser, function (request, response) { +app.post('/api/backgrounds/rename', jsonParser, function (request, response) { if (!request.body) return response.sendStatus(400); const oldFileName = path.join(DIRECTORIES.backgrounds, sanitize(request.body.old_bg)); @@ -859,7 +859,7 @@ app.post('/renamebackground', jsonParser, function (request, response) { return response.send('ok'); }); -app.post('/downloadbackground', urlencodedParser, function (request, response) { +app.post('/api/backgrounds/upload', urlencodedParser, function (request, response) { response_dw_bg = response; if (!request.body || !request.file) return response.sendStatus(400); @@ -2002,6 +2002,13 @@ redirect('/getstats', '/api/stats/get'); redirect('/recreatestats', '/api/stats/recreate'); redirect('/updatestats', '/api/stats/update'); +// Redirect deprecated backgrounds API endpoints +redirect('/getbackgrounds', '/api/backgrounds/all'); +redirect('/setbackground', '/api/backgrounds/set'); +redirect('/delbackground', '/api/backgrounds/delete'); +redirect('/renamebackground', '/api/backgrounds/rename'); +redirect('/downloadbackground', '/api/backgrounds/upload'); // yes, the downloadbackground endpoint actually uploads one + // ** REST CLIENT ASYNC WRAPPERS ** /**