Rename group API endpoints

This commit is contained in:
valadaptive 2023-12-06 12:40:58 -05:00
parent dcde1bd5ba
commit 8027372fc2
3 changed files with 15 additions and 9 deletions

View File

@ -251,7 +251,7 @@ async function convertSoloToGroupChat() {
const metadata = Object.assign({}, chat_metadata); const metadata = Object.assign({}, chat_metadata);
delete metadata.main_chat; delete metadata.main_chat;
const createGroupResponse = await fetch('/creategroup', { const createGroupResponse = await fetch('/api/groups/create', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({

View File

@ -116,7 +116,7 @@ setInterval(groupChatAutoModeWorker, 5000);
const saveGroupDebounced = debounce(async (group, reload) => await _save(group, reload), 500); const saveGroupDebounced = debounce(async (group, reload) => await _save(group, reload), 500);
async function _save(group, reload = true) { async function _save(group, reload = true) {
await fetch('/editgroup', { await fetch('/api/groups/edit', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify(group), body: JSON.stringify(group),
@ -476,7 +476,7 @@ export async function renameGroupMember(oldAvatar, newAvatar, newName) {
} }
async function getGroups() { async function getGroups() {
const response = await fetch('/getgroups', { const response = await fetch('/api/groups/all', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
}); });
@ -968,7 +968,7 @@ function activateNaturalOrder(members, input, lastMessage, allowSelfResponses, i
async function deleteGroup(id) { async function deleteGroup(id) {
const group = groups.find((x) => x.id === id); const group = groups.find((x) => x.id === id);
const response = await fetch('/deletegroup', { const response = await fetch('/api/groups/delete', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: id }), body: JSON.stringify({ id: id }),
@ -1521,7 +1521,7 @@ async function createGroup() {
const chatName = humanizedDateTime(); const chatName = humanizedDateTime();
const chats = [chatName]; const chats = [chatName];
const createGroupResponse = await fetch('/creategroup', { const createGroupResponse = await fetch('/api/groups/create', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({

View File

@ -1300,7 +1300,7 @@ app.post('/listimgfiles/:folder', (req, res) => {
}); });
app.post('/getgroups', jsonParser, (_, response) => { app.post('/api/groups/all', jsonParser, (_, response) => {
const groups = []; const groups = [];
if (!fs.existsSync(DIRECTORIES.groups)) { if (!fs.existsSync(DIRECTORIES.groups)) {
@ -1344,7 +1344,7 @@ app.post('/getgroups', jsonParser, (_, response) => {
return response.send(groups); return response.send(groups);
}); });
app.post('/creategroup', jsonParser, (request, response) => { app.post('/api/groups/create', jsonParser, (request, response) => {
if (!request.body) { if (!request.body) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -1375,7 +1375,7 @@ app.post('/creategroup', jsonParser, (request, response) => {
return response.send(groupMetadata); return response.send(groupMetadata);
}); });
app.post('/editgroup', jsonParser, (request, response) => { app.post('/api/groups/edit', jsonParser, (request, response) => {
if (!request.body || !request.body.id) { if (!request.body || !request.body.id) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -1387,7 +1387,7 @@ app.post('/editgroup', jsonParser, (request, response) => {
return response.send({ ok: true }); return response.send({ ok: true });
}); });
app.post('/deletegroup', jsonParser, async (request, response) => { app.post('/api/groups/delete', jsonParser, async (request, response) => {
if (!request.body || !request.body.id) { if (!request.body || !request.body.id) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -2248,6 +2248,12 @@ redirect('/getgroupchat', '/api/chats/group/get');
redirect('/deletegroupchat', '/api/chats/group/delete'); redirect('/deletegroupchat', '/api/chats/group/delete');
redirect('/savegroupchat', '/api/chats/group/save'); redirect('/savegroupchat', '/api/chats/group/save');
// Redirect deprecated group API endpoints
redirect('/getgroups', '/api/groups/all');
redirect('/creategroup', '/api/groups/create');
redirect('/editgroup', '/api/groups/edit');
redirect('/deletegroup', '/api/groups/delete');
// ** REST CLIENT ASYNC WRAPPERS ** // ** REST CLIENT ASYNC WRAPPERS **
/** /**