Skip to content

add clear requests functionality with confirmation prompt#9

Merged
knktc merged 1 commit intomainfrom
feature-add-purge-button
Feb 11, 2026
Merged

add clear requests functionality with confirmation prompt#9
knktc merged 1 commit intomainfrom
feature-add-purge-button

Conversation

@knktc
Copy link
Owner

@knktc knktc commented Feb 11, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 11, 2026 01:03
@knktc knktc merged commit a68fa19 into main Feb 11, 2026
4 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a “clear captured requests” action to Tiny RequestBin’s web UI, backed by a new API endpoint to wipe the in-memory request store.

Changes:

  • Add i18n strings and UI controls (Clear + Refresh) in the left “Captured Requests” panel.
  • Implement client-side clear flow with a two-step confirmation state.
  • Add a new POST /api/requests/clear endpoint that resets the request store.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
templates/main.tmpl Adds Clear/Refresh buttons and related JS logic + new translation keys.
main.go Routes and implements /api/requests/clear to wipe stored requests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -430,36 +439,77 @@
toggleManualRefreshButton();
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggleManualRefreshButton() is still called in the auto-refresh checkbox handler, but the function (and the old manualRefreshButton) was removed. This will throw a ReferenceError on change and can break subsequent JS initialization. Either remove this call entirely or replace it with new logic that toggles the visibility/disabled state of the current refresh control (listRefreshButton) when auto-refresh is enabled.

Suggested change
toggleManualRefreshButton();
// Disable manual list refresh when auto-refresh is enabled
if (typeof listRefreshButton !== 'undefined' && listRefreshButton) {
listRefreshButton.disabled = checkbox.checked;
}

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +19
'clear_requests': 'Clear',
'confirm': 'Confirm',
'clear_confirm': 'Clear all captured requests?',
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new i18n key clear_confirm is added for both languages but never used anywhere in the template/script. Either wire it into the UI (e.g., a tooltip/inline prompt/modal text) or remove it to avoid dead/unused translation entries that will drift over time.

Copilot uses AI. Check for mistakes.
clearConfirmTimer = setTimeout(resetClearButton, 2500);
return;
}

Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The confirmation timeout (clearConfirmTimer) isn’t cleared when the user proceeds with the actual clear (second click). If the POST takes longer than 2.5s, the timer can fire mid-request and reset the button UI while it’s disabled/in-flight. Clear the timeout when entering the “submit clear” branch (and optionally call resetClearButton() only after the request completes/fails).

Suggested change
if (clearConfirmTimer) {
clearTimeout(clearConfirmTimer);
clearConfirmTimer = null;
}

Copilot uses AI. Check for mistakes.
Comment on lines +223 to +228
func clearRequestsHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.Header().Set("Allow", http.MethodPost)
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
return
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/api/requests/clear introduces a destructive action that can be triggered by any POST request to the server (including cross-site requests to a locally running instance). Consider adding a same-origin check (validate Origin/Referer) and/or requiring a per-session token/custom header to reduce CSRF-style drive-by clears when the service is bound to 0.0.0.0.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments