[backend/razor] Require confirmation of queue job abandon/deschedule action

This commit is contained in:
Laura Hausmann 2024-10-15 02:16:23 +02:00
parent ade4593260
commit ccf1e60ad4
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 14 additions and 3 deletions

View file

@ -56,7 +56,7 @@
<tr> <tr>
<td>Actions</td> <td>Actions</td>
<td> <td>
<a class="fake-link" onclick="abandon('@Model.Job.Id.ToStringLower()')">@abandonName</a> <a class="fake-link" onclick="abandon('@Model.Job.Id.ToStringLower()', event)">@abandonName</a>
</td> </td>
</tr> </tr>
} }

View file

@ -34,6 +34,17 @@ function getCookie(key) {
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? (result[1]) : null; return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? (result[1]) : null;
} }
async function confirm(target, action) {
const match = " (confirm)";
if (!target.innerText.endsWith(match)) {
target.innerText += match;
}
else {
await action();
window.location.reload();
}
}
async function callApiMethod(route) { async function callApiMethod(route) {
const cookie = getCookie('admin_session'); const cookie = getCookie('admin_session');
if (cookie == null) throw new Error('Failed to get admin_session cookie'); if (cookie == null) throw new Error('Failed to get admin_session cookie');
@ -64,7 +75,7 @@ async function retryAllOnPage(queue) {
window.location.reload(); window.location.reload();
} }
async function abandon(id) { async function abandon(id, target) {
await callApiMethod(`/api/iceshrimp/admin/queue/jobs/${id}/abandon`); await confirm(target, () => callApiMethod(`/api/iceshrimp/admin/queue/jobs/${id}/abandon`));
window.location.reload(); window.location.reload();
} }