diff --git a/public/script.js b/public/script.js index 96f2c4fa0..d879b0a47 100644 --- a/public/script.js +++ b/public/script.js @@ -1190,7 +1190,7 @@ export function getEntitiesList({ doFilter } = {}) { } export async function getOneCharacter(avatarUrl) { - const response = await fetch('/getonecharacter', { + const response = await fetch('/api/characters/get', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ @@ -1214,7 +1214,7 @@ export async function getOneCharacter(avatarUrl) { } async function getCharacters() { - var response = await fetch('/getcharacters', { + var response = await fetch('/api/characters/all', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ @@ -1270,7 +1270,7 @@ async function replaceCurrentChat() { await clearChat(); chat.length = 0; - const chatsResponse = await fetch('/getallchatsofcharacter', { + const chatsResponse = await fetch('/api/characters/chats', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ avatar_url: characters[this_chid].avatar }), @@ -4166,7 +4166,7 @@ async function DupeChar() { } const body = { avatar_url: characters[this_chid].avatar }; - const response = await fetch('/dupecharacter', { + const response = await fetch('/api/characters/duplicate', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify(body), @@ -4793,7 +4793,7 @@ async function renameCharacter() { if (newValue && newValue !== characters[this_chid].name) { const body = JSON.stringify({ avatar_url: oldAvatar, new_name: newValue }); - const response = await fetch('/renamecharacter', { + const response = await fetch('/api/characters/rename', { method: 'POST', headers: getRequestHeaders(), body, @@ -5883,7 +5883,7 @@ export async function getChatsFromFiles(data, isGroupChat) { async function getPastCharacterChats() { if (!characters[this_chid]) return; - const response = await fetch('/getallchatsofcharacter', { + const response = await fetch('/api/characters/chats', { method: 'POST', body: JSON.stringify({ avatar_url: characters[this_chid].avatar }), headers: getRequestHeaders(), @@ -6841,7 +6841,7 @@ async function createOrEditCharacter(e) { if ($('#form_create').attr('actiontype') == 'createcharacter') { if ($('#character_name_pole').val().length > 0) { //if the character name text area isn't empty (only posible when creating a new character) - let url = '/createcharacter'; + let url = '/api/characters/create'; if (crop_data != undefined) { url += `?crop=${encodeURIComponent(JSON.stringify(crop_data))}`; @@ -6923,7 +6923,7 @@ async function createOrEditCharacter(e) { toastr.error('Name is required'); } } else { - let url = '/editcharacter'; + let url = '/api/characters/edit'; if (crop_data != undefined) { url += `?crop=${encodeURIComponent(JSON.stringify(crop_data))}`; @@ -7468,7 +7468,7 @@ async function importCharacter(file) { const data = await jQuery.ajax({ type: 'POST', - url: '/importcharacter', + url: '/api/characters/import', data: formData, async: true, cache: false, @@ -7576,7 +7576,7 @@ export async function handleDeleteCharacter(popup_type, this_chid, delete_chats) const msg = { avatar_url: avatar, delete_chats: delete_chats }; - const response = await fetch('/deletecharacter', { + const response = await fetch('/api/characters/delete', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify(msg), @@ -8990,7 +8990,7 @@ jQuery(async function () { await createOrEditCharacter(); const body = { format, avatar_url: characters[this_chid].avatar }; - const response = await fetch('/exportcharacter', { + const response = await fetch('/api/characters/export', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify(body), diff --git a/public/scripts/BulkEditOverlay.js b/public/scripts/BulkEditOverlay.js index 376865aaf..25944a40e 100644 --- a/public/scripts/BulkEditOverlay.js +++ b/public/scripts/BulkEditOverlay.js @@ -53,7 +53,7 @@ class CharacterContextMenu { static duplicate = async (characterId) => { const character = CharacterContextMenu.#getCharacter(characterId); - return fetch('/dupecharacter', { + return fetch('/api/characters/duplicate', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ avatar_url: character.avatar }), @@ -81,7 +81,7 @@ class CharacterContextMenu { }, }; - return fetch('/v2/editcharacterattribute', { + return fetch('/api/characters/merge-attributes', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify(data), @@ -115,7 +115,7 @@ class CharacterContextMenu { static delete = async (characterId, deleteChats = false) => { const character = CharacterContextMenu.#getCharacter(characterId); - return fetch('/deletecharacter', { + return fetch('/api/characters/delete', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ avatar_url: character.avatar, delete_chats: deleteChats }), @@ -124,7 +124,7 @@ class CharacterContextMenu { if (response.ok) { deleteCharacter(character.name, character.avatar).then(() => { if (deleteChats) { - fetch('/getallchatsofcharacter', { + fetch('/api/characters/chats', { method: 'POST', body: JSON.stringify({ avatar_url: character.avatar }), headers: getRequestHeaders(), diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 2cac19087..0711aafaa 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -42,7 +42,7 @@ async function getExistingChatNames() { const data = await getGroupPastChats(selected_group); return data.map(x => x.file_name); } else { - const response = await fetch('/getallchatsofcharacter', { + const response = await fetch('/api/characters/chats', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify({ avatar_url: characters[this_chid].avatar }), diff --git a/server.js b/server.js index a1ad3380f..46c0fc247 100644 --- a/server.js +++ b/server.js @@ -1027,7 +1027,7 @@ function charaFormatData(data) { return char; } -app.post('/createcharacter', urlencodedParser, async function (request, response) { +app.post('/api/characters/create', urlencodedParser, async function (request, response) { if (!request.body) return response.sendStatus(400); request.body.ch_name = sanitize(request.body.ch_name); @@ -1073,7 +1073,7 @@ app.post('/renamechat', jsonParser, async function (request, response) { return response.send({ ok: true }); }); -app.post('/renamecharacter', jsonParser, async function (request, response) { +app.post('/api/characters/rename', jsonParser, async function (request, response) { if (!request.body.avatar_url || !request.body.new_name) { return response.sendStatus(400); } @@ -1119,7 +1119,7 @@ app.post('/renamecharacter', jsonParser, async function (request, response) { } }); -app.post('/editcharacter', urlencodedParser, async function (request, response) { +app.post('/api/characters/edit', urlencodedParser, async function (request, response) { if (!request.body) { console.error('Error: no response body detected'); response.status(400).send('Error: no response body detected'); @@ -1166,7 +1166,7 @@ app.post('/editcharacter', urlencodedParser, async function (request, response) * @param {Object} response - The HTTP response object. * @returns {void} */ -app.post('/editcharacterattribute', jsonParser, async function (request, response) { +app.post('/api/characters/edit-attribute', jsonParser, async function (request, response) { console.log(request.body); if (!request.body) { console.error('Error: no response body detected'); @@ -1212,7 +1212,7 @@ app.post('/editcharacterattribute', jsonParser, async function (request, respons * * @returns {void} * */ -app.post('/v2/editcharacterattribute', jsonParser, async function (request, response) { +app.post('/api/characters/merge-attributes', jsonParser, async function (request, response) { const update = request.body; const avatarPath = path.join(charactersPath, update.avatar); @@ -1240,7 +1240,7 @@ app.post('/v2/editcharacterattribute', jsonParser, async function (request, resp } }); -app.post('/deletecharacter', jsonParser, async function (request, response) { +app.post('/api/characters/delete', jsonParser, async function (request, response) { if (!request.body || !request.body.avatar_url) { return response.sendStatus(400); } @@ -1413,7 +1413,7 @@ const processCharacter = async (item, i) => { /** - * HTTP POST endpoint for the "/getcharacters" route. + * HTTP POST endpoint for the "/api/characters/all" route. * * This endpoint is responsible for reading character files from the `charactersPath` directory, * parsing character data, calculating stats for each character and responding with the data. @@ -1426,7 +1426,7 @@ const processCharacter = async (item, i) => { * @param {object} response The HTTP response object. * @return {undefined} Does not return a value. */ -app.post('/getcharacters', jsonParser, function (request, response) { +app.post('/api/characters/all', jsonParser, function (request, response) { fs.readdir(charactersPath, async (err, files) => { if (err) { console.error(err); @@ -1449,7 +1449,7 @@ app.post('/getcharacters', jsonParser, function (request, response) { }); }); -app.post('/getonecharacter', jsonParser, async function (request, response) { +app.post('/api/characters/get', jsonParser, async function (request, response) { if (!request.body) return response.sendStatus(400); const item = request.body.avatar_url; const filePath = path.join(charactersPath, item); @@ -1916,7 +1916,7 @@ function getImages(path) { .sort(Intl.Collator().compare); } -app.post('/getallchatsofcharacter', jsonParser, async function (request, response) { +app.post('/api/characters/chats', jsonParser, async function (request, response) { if (!request.body) return response.sendStatus(400); const characterDirectory = (request.body.avatar_url).replace('.png', ''); @@ -1993,7 +1993,7 @@ function getPngName(file) { return file; } -app.post('/importcharacter', urlencodedParser, async function (request, response) { +app.post('/api/characters/import', urlencodedParser, async function (request, response) { if (!request.body || request.file === undefined) return response.sendStatus(400); @@ -2137,7 +2137,7 @@ app.post('/importcharacter', urlencodedParser, async function (request, response } }); -app.post('/dupecharacter', jsonParser, async function (request, response) { +app.post('/api/characters/duplicate', jsonParser, async function (request, response) { try { if (!request.body.avatar_url) { console.log('avatar URL not found in request body'); @@ -2252,7 +2252,7 @@ app.post('/exportchat', jsonParser, async function (request, response) { } }); -app.post('/exportcharacter', jsonParser, async function (request, response) { +app.post('/api/characters/export', jsonParser, async function (request, response) { if (!request.body.format || !request.body.avatar_url) { return response.sendStatus(400); }