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 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 () {
},

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');
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 **
/**