mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Update sprite delete call
This commit is contained in:
@ -2081,20 +2081,25 @@ async function onClickExpressionDelete(event) {
|
|||||||
// Prevents the expression from being set
|
// Prevents the expression from being set
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
const confirmation = await callPopup('<h3>Are you sure?</h3>Once deleted, it\'s gone forever!', 'confirm');
|
const expressionListItem = $(this).closest('.expression_list_item');
|
||||||
|
const expression = expressionListItem.data('expression');
|
||||||
|
|
||||||
|
const confirmation = await Popup.show.confirm(t`Delete Expression`, t`Are you sure you want to delete this expression? Once deleted, it\'s gone forever!`
|
||||||
|
+ '<br /><br />'
|
||||||
|
+ t`Expression: `
|
||||||
|
+ expressionListItem.attr('data-filename'));
|
||||||
if (!confirmation) {
|
if (!confirmation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const expression = $(this).closest('.expression_list_item').data('expression');
|
const fileName = expressionListItem.attr('data-filename');
|
||||||
const name = $('#image_list').data('name');
|
const name = $('#image_list').data('name');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch('/api/sprites/delete', {
|
await fetch('/api/sprites/delete', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({ name, label: expression }),
|
body: JSON.stringify({ name, label: expression, spriteName: fileName }),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toastr.error('Failed to delete image. Try again later.');
|
toastr.error('Failed to delete image. Try again later.');
|
||||||
|
@ -147,8 +147,9 @@ router.get('/get', jsonParser, function (request, response) {
|
|||||||
router.post('/delete', jsonParser, async (request, response) => {
|
router.post('/delete', jsonParser, async (request, response) => {
|
||||||
const label = request.body.label;
|
const label = request.body.label;
|
||||||
const name = request.body.name;
|
const name = request.body.name;
|
||||||
|
const spriteName = request.body.spriteName || label;
|
||||||
|
|
||||||
if (!label || !name) {
|
if (!spriteName || !name) {
|
||||||
return response.sendStatus(400);
|
return response.sendStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ router.post('/delete', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
// Remove existing sprite with the same label
|
// Remove existing sprite with the same label
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (path.parse(file).name === label) {
|
if (path.parse(file).name === spriteName) {
|
||||||
fs.rmSync(path.join(spritesPath, file));
|
fs.rmSync(path.join(spritesPath, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user