Rename chat API endpoints

This commit is contained in:
valadaptive 2023-12-05 22:34:52 -05:00
parent 55d7bd6a87
commit 6efe95f4f1
4 changed files with 32 additions and 32 deletions

View File

@ -1249,7 +1249,7 @@ async function getCharacters() {
} }
async function delChat(chatfile) { async function delChat(chatfile) {
const response = await fetch('/delchat', { const response = await fetch('/api/chats/delete', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({
@ -3883,7 +3883,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
toastr.error(data.response, 'API Error'); toastr.error(data.response, 'API Error');
} }
} }
console.debug('/savechat called by /Generate'); console.debug('/api/chats/save called by /Generate');
await saveChatConditional(); await saveChatConditional();
is_send_press = false; is_send_press = false;
@ -4903,7 +4903,7 @@ async function renamePastChats(newAvatar, newValue) {
for (const { file_name } of pastChats) { for (const { file_name } of pastChats) {
try { try {
const fileNameWithoutExtension = file_name.replace('.jsonl', ''); const fileNameWithoutExtension = file_name.replace('.jsonl', '');
const getChatResponse = await fetch('/getchat', { const getChatResponse = await fetch('/api/chats/get', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({
@ -4927,7 +4927,7 @@ async function renamePastChats(newAvatar, newValue) {
} }
} }
const saveChatResponse = await fetch('/savechat', { const saveChatResponse = await fetch('/api/chats/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ body: JSON.stringify({
@ -5018,7 +5018,7 @@ async function saveChat(chat_name, withMetadata, mesId) {
]; ];
return jQuery.ajax({ return jQuery.ajax({
type: 'POST', type: 'POST',
url: '/savechat', url: '/api/chats/save',
data: JSON.stringify({ data: JSON.stringify({
ch_name: characters[this_chid].name, ch_name: characters[this_chid].name,
file_name: file_name, file_name: file_name,
@ -5110,11 +5110,11 @@ function getThumbnailUrl(type, file) {
} }
async function getChat() { async function getChat() {
//console.log('/getchat -- entered for -- ' + characters[this_chid].name); //console.log('/api/chats/get -- entered for -- ' + characters[this_chid].name);
try { try {
const response = await $.ajax({ const response = await $.ajax({
type: 'POST', type: 'POST',
url: '/getchat', url: '/api/chats/get',
data: JSON.stringify({ data: JSON.stringify({
ch_name: characters[this_chid].name, ch_name: characters[this_chid].name,
file_name: characters[this_chid].chat, file_name: characters[this_chid].chat,
@ -5875,7 +5875,7 @@ export async function getChatsFromFiles(data, isGroupChat) {
let chat_promise = chat_list.map(({ file_name }) => { let chat_promise = chat_list.map(({ file_name }) => {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
try { try {
const endpoint = isGroupChat ? '/getgroupchat' : '/getchat'; const endpoint = isGroupChat ? '/api/chats/group/get' : '/api/chats/get';
const requestBody = isGroupChat const requestBody = isGroupChat
? JSON.stringify({ id: file_name }) ? JSON.stringify({ id: file_name })
: JSON.stringify({ : JSON.stringify({
@ -6562,7 +6562,7 @@ export async function saveChatConditional() {
async function importCharacterChat(formData) { async function importCharacterChat(formData) {
await jQuery.ajax({ await jQuery.ajax({
type: 'POST', type: 'POST',
url: '/importchat', url: '/api/chats/import',
data: formData, data: formData,
beforeSend: function () { beforeSend: function () {
}, },
@ -7732,7 +7732,7 @@ jQuery(async function () {
registerSlashCommand('dupe', DupeChar, [], ' duplicates the currently selected character', true, true); registerSlashCommand('dupe', DupeChar, [], ' duplicates the currently selected character', true, true);
registerSlashCommand('api', connectAPISlash, [], '<span class="monospace">(kobold, horde, novel, ooba, oai, claude, windowai, openrouter, scale, ai21, palm)</span> connect to an API', true, true); registerSlashCommand('api', connectAPISlash, [], '<span class="monospace">(kobold, horde, novel, ooba, oai, claude, windowai, openrouter, scale, ai21, palm)</span> connect to an API', true, true);
registerSlashCommand('impersonate', doImpersonate, ['imp'], ' calls an impersonation response', true, true); registerSlashCommand('impersonate', doImpersonate, ['imp'], ' calls an impersonation response', true, true);
registerSlashCommand('delchat', doDeleteChat, [], ' deletes the current chat', true, true); registerSlashCommand('api/chats/delete', doDeleteChat, [], ' deletes the current chat', true, true);
registerSlashCommand('closechat', doCloseChat, [], ' closes the current chat', true, true); registerSlashCommand('closechat', doCloseChat, [], ' closes the current chat', true, true);
registerSlashCommand('panels', doTogglePanels, ['togglepanels'], ' toggle UI panels on/off', true, true); registerSlashCommand('panels', doTogglePanels, ['togglepanels'], ' toggle UI panels on/off', true, true);
registerSlashCommand('forcesave', doForceSave, [], ' forces a save of the current chat and settings', true, true); registerSlashCommand('forcesave', doForceSave, [], ' forces a save of the current chat and settings', true, true);
@ -8161,7 +8161,7 @@ jQuery(async function () {
}; };
try { try {
const response = await fetch('/renamechat', { const response = await fetch('/api/chats/rename', {
method: 'POST', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),
headers: getRequestHeaders(), headers: getRequestHeaders(),
@ -8215,7 +8215,7 @@ jQuery(async function () {
}; };
console.log(body); console.log(body);
try { try {
const response = await fetch('/exportchat', { const response = await fetch('/api/chats/export', {
method: 'POST', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),
headers: getRequestHeaders(), headers: getRequestHeaders(),
@ -8352,7 +8352,7 @@ jQuery(async function () {
if (id == 'option_select_chat') { if (id == 'option_select_chat') {
if ((selected_group && !is_group_generating) || (this_chid !== undefined && !is_send_press) || fromSlashCommand) { if ((selected_group && !is_group_generating) || (this_chid !== undefined && !is_send_press) || fromSlashCommand) {
displayPastChats(); displayPastChats();
//this is just to avoid the shadow for past chat view when using /delchat //this is just to avoid the shadow for past chat view when using /api/chats/delete
//however, the dialog popup still gets one.. //however, the dialog popup still gets one..
if (!fromSlashCommand) { if (!fromSlashCommand) {
console.log('displaying shadow'); console.log('displaying shadow');

View File

@ -320,7 +320,7 @@ async function convertSoloToGroupChat() {
} }
// Save group chat // Save group chat
const createChatResponse = await fetch('/savegroupchat', { const createChatResponse = await fetch('/api/chats/group/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: chatName, chat: groupChat }), body: JSON.stringify({ id: chatName, chat: groupChat }),

View File

@ -152,7 +152,7 @@ async function regenerateGroup() {
} }
async function loadGroupChat(chatId) { async function loadGroupChat(chatId) {
const response = await fetch('/getgroupchat', { const response = await fetch('/api/chats/group/get', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: chatId }), body: JSON.stringify({ id: chatId }),
@ -401,7 +401,7 @@ async function saveGroupChat(groupId, shouldSaveGroup) {
const group = groups.find(x => x.id == groupId); const group = groups.find(x => x.id == groupId);
const chat_id = group.chat_id; const chat_id = group.chat_id;
group['date_last_chat'] = Date.now(); group['date_last_chat'] = Date.now();
const response = await fetch('/savegroupchat', { const response = await fetch('/api/chats/group/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: chat_id, chat: [...chat] }), body: JSON.stringify({ id: chat_id, chat: [...chat] }),
@ -455,7 +455,7 @@ export async function renameGroupMember(oldAvatar, newAvatar, newName) {
} }
if (hadChanges) { if (hadChanges) {
const saveChatResponse = await fetch('/savegroupchat', { const saveChatResponse = await fetch('/api/chats/group/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: chatId, chat: [...messages] }), body: JSON.stringify({ id: chatId, chat: [...messages] }),
@ -1659,7 +1659,7 @@ export async function deleteGroupChat(groupId, chatId) {
delete group.past_metadata[chatId]; delete group.past_metadata[chatId];
updateChatMetadata(group.chat_metadata, true); updateChatMetadata(group.chat_metadata, true);
const response = await fetch('/deletegroupchat', { const response = await fetch('/api/chats/group/delete', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: chatId }), body: JSON.stringify({ id: chatId }),
@ -1679,7 +1679,7 @@ export async function deleteGroupChat(groupId, chatId) {
export async function importGroupChat(formData) { export async function importGroupChat(formData) {
await jQuery.ajax({ await jQuery.ajax({
type: 'POST', type: 'POST',
url: '/importgroupchat', url: '/api/chats/group/import',
data: formData, data: formData,
beforeSend: function () { beforeSend: function () {
}, },
@ -1720,7 +1720,7 @@ export async function saveGroupBookmarkChat(groupId, name, metadata, mesId) {
await editGroup(groupId, true, false); await editGroup(groupId, true, false);
await fetch('/savegroupchat', { await fetch('/api/chats/group/save', {
method: 'POST', method: 'POST',
headers: getRequestHeaders(), headers: getRequestHeaders(),
body: JSON.stringify({ id: name, chat: [...trimmed_chat] }), body: JSON.stringify({ id: name, chat: [...trimmed_chat] }),

View File

@ -723,7 +723,7 @@ app.post('/api/textgenerationwebui/generate', jsonParser, async function (reques
} }
}); });
app.post('/savechat', jsonParser, function (request, response) { app.post('/api/chats/save', jsonParser, function (request, response) {
try { try {
var dir_name = String(request.body.avatar_url).replace('.png', ''); var dir_name = String(request.body.avatar_url).replace('.png', '');
let chat_data = request.body.chat; let chat_data = request.body.chat;
@ -737,7 +737,7 @@ app.post('/savechat', jsonParser, function (request, response) {
} }
}); });
app.post('/getchat', jsonParser, function (request, response) { app.post('/api/chats/get', jsonParser, function (request, response) {
try { try {
const dirName = String(request.body.avatar_url).replace('.png', ''); const dirName = String(request.body.avatar_url).replace('.png', '');
const chatDirExists = fs.existsSync(DIRECTORIES.chats + dirName); const chatDirExists = fs.existsSync(DIRECTORIES.chats + dirName);
@ -830,7 +830,7 @@ app.post('/getstatus', jsonParser, async function (request, response) {
}); });
app.post('/renamechat', jsonParser, async function (request, response) { app.post('/api/chats/rename', jsonParser, async function (request, response) {
if (!request.body || !request.body.original_file || !request.body.renamed_file) { if (!request.body || !request.body.original_file || !request.body.renamed_file) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -967,8 +967,8 @@ app.post('/delbackground', jsonParser, function (request, response) {
return response.send('ok'); return response.send('ok');
}); });
app.post('/delchat', jsonParser, function (request, response) { app.post('/api/chats/delete', jsonParser, function (request, response) {
console.log('/delchat entered'); console.log('/api/chats/delete entered');
if (!request.body) { if (!request.body) {
console.log('no request body seen'); console.log('no request body seen');
return response.sendStatus(400); return response.sendStatus(400);
@ -1237,7 +1237,7 @@ function getImages(path) {
.sort(Intl.Collator().compare); .sort(Intl.Collator().compare);
} }
app.post('/exportchat', jsonParser, async function (request, response) { app.post('/api/chats/export', jsonParser, async function (request, response) {
if (!request.body.file || (!request.body.avatar_url && request.body.is_group === false)) { if (!request.body.file || (!request.body.avatar_url && request.body.is_group === false)) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -1305,7 +1305,7 @@ app.post('/exportchat', jsonParser, async function (request, response) {
} }
}); });
app.post('/importgroupchat', urlencodedParser, function (request, response) { app.post('/api/chats/group/import', urlencodedParser, function (request, response) {
try { try {
const filedata = request.file; const filedata = request.file;
@ -1325,7 +1325,7 @@ app.post('/importgroupchat', urlencodedParser, function (request, response) {
} }
}); });
app.post('/importchat', urlencodedParser, function (request, response) { app.post('/api/chats/import', urlencodedParser, function (request, response) {
if (!request.body) return response.sendStatus(400); if (!request.body) return response.sendStatus(400);
var format = request.body.file_type; var format = request.body.file_type;
@ -1344,7 +1344,7 @@ app.post('/importchat', urlencodedParser, function (request, response) {
if (format === 'json') { if (format === 'json') {
const jsonData = JSON.parse(data); const jsonData = JSON.parse(data);
if (jsonData.histories !== undefined) { if (jsonData.histories !== undefined) {
//console.log('/importchat confirms JSON histories are defined'); //console.log('/api/chats/import confirms JSON histories are defined');
const chat = { const chat = {
from(history) { from(history) {
return [ return [
@ -1701,7 +1701,7 @@ app.post('/editgroup', jsonParser, (request, response) => {
return response.send({ ok: true }); return response.send({ ok: true });
}); });
app.post('/getgroupchat', jsonParser, (request, response) => { app.post('/api/chats/group/get', jsonParser, (request, response) => {
if (!request.body || !request.body.id) { if (!request.body || !request.body.id) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -1721,7 +1721,7 @@ app.post('/getgroupchat', jsonParser, (request, response) => {
} }
}); });
app.post('/deletegroupchat', jsonParser, (request, response) => { app.post('/api/chats/group/delete', jsonParser, (request, response) => {
if (!request.body || !request.body.id) { if (!request.body || !request.body.id) {
return response.sendStatus(400); return response.sendStatus(400);
} }
@ -1737,7 +1737,7 @@ app.post('/deletegroupchat', jsonParser, (request, response) => {
return response.send({ error: true }); return response.send({ error: true });
}); });
app.post('/savegroupchat', jsonParser, (request, response) => { app.post('/api/chats/group/save', jsonParser, (request, response) => {
if (!request.body || !request.body.id) { if (!request.body || !request.body.id) {
return response.sendStatus(400); return response.sendStatus(400);
} }