fix: re-enable convert button when an upload fails

MO
1mo ago
+8-4

[!NOTE]
AI-generated, not reviewed by a human. This pull request was written by an AI coding agent and then checked by a separate AI review agent, which re-ran the tests described below. No human has reviewed the code. It is submitted by @monsterlag, who runs these agents. If that does not fit how you want to receive contributions, please feel free to close it.

Summary

  • pendingFiles was only decremented in the upload XHR's onload handler. When an upload fails (presumably the dropped-folder case in the issue: the browser cannot read a folder as a file, so the request most likely fires error instead of load; not checked in a real browser), the counter never returns to 0, so the Convert button stays disabled for every later upload until the page is reloaded.
  • Move the counter and button update into onloadend, which fires after load, error, abort and timeout. This also covers the case where onload throws on a non-JSON response before reaching the decrement.
  • Only re-enable the button when files remain in the list, matching the check already used when a target format is picked.

A failed file still stays in the list (with no error state) until the user removes it, as before; showing an error for it is left out of this change.

Fixes #634.

Testing

  • Reproduced the issue's steps (failed folder upload, remove it, upload a normal file, format already selected) with a throwaway Node script that loads public/script.js against minimal DOM/XHR stubs. Before the fix it ended with pendingFiles=1, the button disabled and labelled "Uploading..."; after the fix, pendingFiles=0 and the button is enabled and labelled "Convert". The script is not part of this PR because the repository has no test setup for the browser scripts in public/.
  • bun run test: 458 passed, 0 failed.
  • bun run lint: passed (tsc, Knip, ESLint, Prettier, XSS scan).

Not tested in a real browser; the failure path for a dropped folder relies on the browser firing error for that request.


Summary by cubic

Fixes the convert button staying disabled after a failed upload, so subsequent uploads can be converted without reloading the page.

  • Moves the pending file counter and button update from the XHR onload handler to onloadend, which also fires on error, abort, and timeout.
  • Re-enables the button only when files remain in the list, matching the existing check when a target format is picked.