mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
WIP way to edit a char
This commit is contained in:
32
server.js
32
server.js
@@ -1026,6 +1026,38 @@ app.post("/editcharacter", urlencodedParser, async function (request, response)
|
||||
}
|
||||
});
|
||||
|
||||
// take the name of a character, the field to be chaged, and the new value
|
||||
// and change the value of the field in the character's json file
|
||||
// and save the file.
|
||||
app.post("/editcharacterattribute", urlencodedParser, async function (request, response) {
|
||||
if (!request.body) {
|
||||
console.error('Error: no response body detected');
|
||||
response.status(400).send('Error: no response body detected');
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.body.ch_name === '' || request.body.ch_name === undefined || request.body.ch_name === '.') {
|
||||
console.error('Error: invalid name.');
|
||||
response.status(400).send('Error: invalid name.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const avatarPath = path.join(charactersPath, request.body.avatar_url);
|
||||
charaRead(avatarPath).then((char) => {
|
||||
char = JSON.parse(char);
|
||||
char[request.body.field] = request.body.value;
|
||||
char = JSON.stringify(char);
|
||||
|
||||
}).then(() => {
|
||||
charaWrite(avatarPath, char, request.body.avatar_url, response, 'Character saved');
|
||||
});
|
||||
}
|
||||
catch {
|
||||
console.error('An error occured, character edit invalidated.');
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/deletecharacter", urlencodedParser, function (request, response) {
|
||||
if (!request.body || !request.body.avatar_url) {
|
||||
return response.sendStatus(400);
|
||||
|
Reference in New Issue
Block a user