Rename backgrounds API endpoints

This commit is contained in:
valadaptive 2023-12-07 15:17:19 -05:00
parent eb1d4aed4d
commit 2367f4f38f
2 changed files with 17 additions and 10 deletions

View File

@ -238,7 +238,7 @@ async function onRenameBackgroundClick(e) {
} }
const data = { old_bg: bgNames.oldBg, new_bg: bgNames.newBg }; const data = { old_bg: bgNames.oldBg, new_bg: bgNames.newBg };
const response = await fetch('/renamebackground', { const response = await fetch('/api/backgrounds/rename', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify(data), body: JSON.stringify(data),
@ -326,7 +326,7 @@ async function autoBackgroundCommand() {
} }
export async function getBackgrounds() { export async function getBackgrounds() {
const response = await fetch('/getbackgrounds', { const response = await fetch('/api/backgrounds/all', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({
@ -378,7 +378,7 @@ function getBackgroundFromTemplate(bg, isCustom) {
async function setBackground(bg) { async function setBackground(bg) {
jQuery.ajax({ jQuery.ajax({
type: 'POST', // type: 'POST', //
url: '/setbackground', // url: '/api/backgrounds/set', //
data: JSON.stringify({ data: JSON.stringify({
bg: bg, bg: bg,
}), }),
@ -398,7 +398,7 @@ async function setBackground(bg) {
} }
async function delBackground(bg) { async function delBackground(bg) {
await fetch('/delbackground', { await fetch('/api/backgrounds/delete', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({
@ -427,7 +427,7 @@ function onBackgroundUploadSelected() {
function uploadBackground(formData) { function uploadBackground(formData) {
jQuery.ajax({ jQuery.ajax({
type: 'POST', type: 'POST',
url: '/downloadbackground', url: '/api/backgrounds/upload',
data: formData, data: formData,
beforeSend: function () { beforeSend: function () {
}, },

View File

@ -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'); var images = getImages('public/backgrounds');
response.send(JSON.stringify(images)); response.send(JSON.stringify(images));
@ -807,7 +807,7 @@ app.post('/deleteuseravatar', jsonParser, function (request, response) {
return response.sendStatus(404); return response.sendStatus(404);
}); });
app.post('/setbackground', jsonParser, function (request, response) { app.post('/api/backgrounds/set', jsonParser, function (request, response) {
try { try {
const bg = `#bg1 {background-image: url('../backgrounds/${request.body.bg}');}`; const bg = `#bg1 {background-image: url('../backgrounds/${request.body.bg}');}`;
writeFileAtomicSync('public/css/bg_load.css', bg, 'utf8'); 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) return response.sendStatus(400);
if (request.body.bg !== sanitize(request.body.bg)) { if (request.body.bg !== sanitize(request.body.bg)) {
@ -838,7 +838,7 @@ app.post('/delbackground', jsonParser, function (request, response) {
return response.send('ok'); 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); if (!request.body) return response.sendStatus(400);
const oldFileName = path.join(DIRECTORIES.backgrounds, sanitize(request.body.old_bg)); 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'); return response.send('ok');
}); });
app.post('/downloadbackground', urlencodedParser, function (request, response) { app.post('/api/backgrounds/upload', urlencodedParser, function (request, response) {
response_dw_bg = response; response_dw_bg = response;
if (!request.body || !request.file) return response.sendStatus(400); if (!request.body || !request.file) return response.sendStatus(400);
@ -2002,6 +2002,13 @@ redirect('/getstats', '/api/stats/get');
redirect('/recreatestats', '/api/stats/recreate'); redirect('/recreatestats', '/api/stats/recreate');
redirect('/updatestats', '/api/stats/update'); 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 ** // ** REST CLIENT ASYNC WRAPPERS **
/** /**