From ccf1e60ad45cca28ab84eaf9fd9fefd9b7f15a31 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 15 Oct 2024 02:16:23 +0200 Subject: [PATCH] [backend/razor] Require confirmation of queue job abandon/deschedule action --- Iceshrimp.Backend/Pages/QueueJob.cshtml | 2 +- Iceshrimp.Backend/wwwroot/js/queue.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Iceshrimp.Backend/Pages/QueueJob.cshtml b/Iceshrimp.Backend/Pages/QueueJob.cshtml index 42f8ca72..12d58232 100644 --- a/Iceshrimp.Backend/Pages/QueueJob.cshtml +++ b/Iceshrimp.Backend/Pages/QueueJob.cshtml @@ -56,7 +56,7 @@ Actions - @abandonName + @abandonName } diff --git a/Iceshrimp.Backend/wwwroot/js/queue.js b/Iceshrimp.Backend/wwwroot/js/queue.js index 9c4d964c..a69f3b19 100644 --- a/Iceshrimp.Backend/wwwroot/js/queue.js +++ b/Iceshrimp.Backend/wwwroot/js/queue.js @@ -34,6 +34,17 @@ function getCookie(key) { 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) { const cookie = getCookie('admin_session'); if (cookie == null) throw new Error('Failed to get admin_session cookie'); @@ -64,7 +75,7 @@ async function retryAllOnPage(queue) { window.location.reload(); } -async function abandon(id) { - await callApiMethod(`/api/iceshrimp/admin/queue/jobs/${id}/abandon`); +async function abandon(id, target) { + await confirm(target, () => callApiMethod(`/api/iceshrimp/admin/queue/jobs/${id}/abandon`)); window.location.reload(); } \ No newline at end of file