fix: harden EPUB optimiser UI gating, size reporting, and picker teardown#1947
fix: harden EPUB optimiser UI gating, size reporting, and picker teardown#1947zgredex wants to merge 3 commits into
Conversation
- Show the "Optimize EPUB" panel only when at least one selected file has the .epub extension; force the checkbox off when the selection changes to non-EPUB so the "Optimize & Upload" button doesn't linger. - Pass the real file/blob sizes to logSummary() instead of the sum-of-image-bytes accumulators, so the conversion summary's Original / Optimized / Saved rows match what's actually on disk.
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
📝 WalkthroughWalkthroughFilesPage.html: show EPUB conversion options only when at least one selected file is an EPUB; reset conversion/image UI state for non-EPUB or empty selections. Track per-file original/new byte sizes through upload/conversion and include aggregated totals in batch summary only when applicable. convertEpubFile() no longer accumulates image-size totals and calls logSummary(originalSize, newSize, timeElapsed) directly. ChangesEPUB Conversion Workflow Updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/network/html/FilesPage.html (1)
2950-2956:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winClear stale image picker when selection is no longer single-EPUB eligible.
If the picker is already visible (from a previous single-EPUB selection), switching to multi-file selection can leave stale picker content on screen. Add an explicit clear when the single-EPUB condition is not met.
💡 Suggested patch
- if (advancedContent.classList.contains('visible') && files.length === 1 && convertEnabled && files[0].name.toLowerCase().endsWith('.epub')) { - showImagePicker(files[0]).catch(err => console.error('Image picker error:', err)); - } + if (advancedContent.classList.contains('visible') && files.length === 1 && convertEnabled && files[0].name.toLowerCase().endsWith('.epub')) { + showImagePicker(files[0]).catch(err => console.error('Image picker error:', err)); + } else { + clearImagePicker(); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/network/html/FilesPage.html` around lines 2950 - 2956, The current logic only calls showImagePicker(files[0]) when the single-EPUB condition is met, but does not clear an existing image picker when the user switches to a multi-file or non-EPUB selection; add an explicit clear/hide step in the else path so stale UI is removed. Specifically, after computing advancedContent, convertEnabled and checking the condition that leads to showImagePicker(files[0]), add an else branch that calls a clear/hide routine (e.g., hideImagePicker() or remove the DOM node with id 'imagePicker' / clearImagePicker()) to remove any existing picker and cancel any related state; reference showImagePicker, advancedSettingsContent, convertBeforeUpload and files when locating where to insert the else/clear logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/network/html/FilesPage.html`:
- Around line 2950-2956: The current logic only calls showImagePicker(files[0])
when the single-EPUB condition is met, but does not clear an existing image
picker when the user switches to a multi-file or non-EPUB selection; add an
explicit clear/hide step in the else path so stale UI is removed. Specifically,
after computing advancedContent, convertEnabled and checking the condition that
leads to showImagePicker(files[0]), add an else branch that calls a clear/hide
routine (e.g., hideImagePicker() or remove the DOM node with id 'imagePicker' /
clearImagePicker()) to remove any existing picker and cancel any related state;
reference showImagePicker, advancedSettingsContent, convertBeforeUpload and
files when locating where to insert the else/clear logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5d6d3fca-73f2-4045-b0d6-92b198cd4f66
📒 Files selected for processing (1)
src/network/html/FilesPage.html
📜 Review details
🔇 Additional comments (2)
src/network/html/FilesPage.html (2)
2934-2947: Good EPUB-only gating and reset behavior.Line 2934–Line 2947 correctly restricts Optimize UI to selections containing at least one
.epub, and the forced uncheck/reset prevents stale “Optimize & Upload” state.
4513-4513: Nice fix for summary size accuracy.Line 4513 now reports true file-level sizes (
file.sizevsnewBlob.size), which matches user-visible expectations for “Original/Optimized/Saved”.
Wire up the previously-unused batchStats.totalOriginalSize and totalNewSize: snapshot the picked-file size before the converted blob replaces it, capture convertedBlob.size on success, and pass both through saveToFileBatchLog (now (fileName, succeeded, originalSize=0, newSize=0)). Failed conversions and fallback-to- original uploads pass 0/0 so they don't poison the totals. finalizeBatchLog renders three new rows (Total original / optimised / saved) only when at least one file actually contributed sizes, reusing formatBytes and the existing .saved / .increased styling.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
I appreciate the nod towards my ability to review a change like this but I think it best to defer to @itsthisjustin or another whos got deeper experience with the web gui. I've not worked in this code and I dont really use the feature currently so any insight I can provide wont be the best. |
No problem. I’ll fix one more thing and assign more people |
|
Happy to review when needed. I'd run into these issues myself when using the optimizer so I can test |
validateFile() opens the image picker on a single-EPUB selection with advanced settings expanded, but had no else branch — re-picking multiple files left the previous file's thumbnails and picker-mode layout visible. Add an else that calls the existing idempotent clearImagePicker() helper so the grid, picker-mode classes, and the Start Conversion button are torn down whenever the selection no longer matches the open-picker condition.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@itsthisjustin It should be good now, hope I didn't miss anything. You can test. From a broader perspective - this needs to become device aware. Currently everything is calculated with 480x800 resolution. If we are to embrace x3 the optimizer needs an update. I don't own x3 though. |
|
ok want me to add support and test? |
Sure, if you can spare some time. |
Summary
Four fixes in the web file-upload modal's EPUB optimiser (
src/network/html/FilesPage.html):"Optimize EPUB" was offered for any file type. The convert-options panel was shown unconditionally on every file selection. It now appears only when at least one selected file ends in
.epub. When the selection changes back to non-EPUB, the checkbox is force-unchecked viatoggleConvertOptions()so the "Optimize & Upload" button label and image-picker state reset cleanly. Mixed selections still show the option — the existing batch loop already filters EPUBs.Per-file conversion summary reported wrong sizes.
logSummary()was being fedtotalImageSize/totalNewSize(sum of image bytes only), so whenever the EPUB contained any images, Original size, Optimized size, and Saved (X%) didn't match the actual file on disk. It now receivesoriginalSize = file.sizeandnewSize = newBlob.size. The now-unused accumulators are removed.Batch summary had no aggregate size totals.
batchStats.totalOriginalSize/totalNewSizewere declared but never incremented or rendered. They are now wired up:saveToFileBatchLogtakes optional(originalSize, newSize), snapshotted before the converted blob replaces the picked file, and the batch summary renders Total original, Total optimised, Total saved (X%) whenever at least one file successfully converted. Files that fell back to original upload (or never converted) contribute 0/0 and don't poison the totals.Image picker stayed visible after switching to multi-file selection.
validateFile()opened the picker on a single-EPUB selection with Advanced Mode expanded, but had no else branch — re-picking multiple files left the previous file's thumbnails andpicker-modelayout visible. Added an else that calls the existing idempotentclearImagePicker()so the grid, layout classes, and the Start Conversion button tear down whenever the selection no longer matches the open-picker condition.Per-image before/after numbers logged by
logImage()are unchanged. Reuses the existingformatBytes()helper and.saved/.increasedCSS classes — no new styling.Commits
b38e0561fix: gate EPUB optimiser by extension and report real file sizesfef6b242feat: aggregate Total original / optimised / saved rows in batch summary4ca511bcfix: clear stale image picker when selection switches to multi-fileTest plan
pio runsucceeds (regeneratesFilesPageHtml.generated.h).txt→ "Optimize EPUB" panel hidden.epub→ panel shown.epub, tick Optimize, then re-pick.txtwithout closing modal → panel hides, button reverts from "Optimize & Upload" to "Upload".epub+ one.txt→ panel shown; running it optimises the EPUB and uploads the TXT untouched.epub, tick Optimize, expand Advanced Mode → picker appears. Re-pick multiple.epubfiles → picker disappears, no leftover thumbnails or Start Conversion button.epub→ picker re-populates with the new file's thumbnails