Repository navigation
fix: ebook and direct download names stay within the 255-byte limit - #478
Merged
Merged
Conversation
…474) The Anna's Archive ebook name and the direct download name were capped by characters, so long Cyrillic or CJK titles produced names over 255 bytes and the download failed with ENAMETOOLONG; the direct download 200-character cap could also cut off the extension. Both now use the byte caps from path-component.ts: the ebook name cuts the title first and keeps the author whole unless the title would get under half the room, and the direct download name keeps its extension. The 200-unit path template variable cap and the 100-unit ebook part cap now cut between grapheme clusters, so an emoji is never split. Names that fit are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…extension in the library (#474) Every caller that queues an Anna's Archive download now builds the name with buildEbookDownloadName(), which applies the title-first byte cap and leaves room for the longer extension the downloader may swap in. The organizer's 200-unit cap on an ebook source name now cuts the stem only, so a long name keeps its extension in the library, and FileOrganizer.sanitizePath cuts between grapheme clusters like the path template. Names that fit are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kikootwo
marked this pull request as ready for review
October 27, 2026 08:38
NichCodes
added a commit
to NichCodes/ReadMeABook
that referenced
this pull request
Nov 2, 2026
Conflict resolutions: - Approve route: kept the thin wrapper around processRequestApproval and moved upstream's route fixes into the shared service, so the Web UI, API tokens and Discord all get them: release-pick validation (guardTorrentSelection/guardEbookSelection, kikootwo#355) in a new request-approval-selection helper, run before the atomic claim, with 503 (source unreachable) and 400 (unusable admin pick) responses and the stored-pick fallback to automatic search; buildEbookDownloadName (kikootwo#478); readJsonBody body limits (kikootwo#438/kikootwo#442). The deleted-request guard (kikootwo#476) was already in the service. - Init route: took upstream's secret-gated POST/runAppInitOnce; the bot still starts once after the first successful init. - users/[id], notifications/test, organize-files: kept both sides. - package.json/lock: upstream versions plus discord.js. Follow-ups for upstream conventions and test changes: - Discord settings routes read bodies through readJsonBody. - Approve tests mock the updateMany claim (the shared Prisma mock now returns { count: 0 } by default).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #474
What changed
addStartDirectDownloadJob) now builds the name with the newbuildEbookDownloadName()(src/lib/utils/ebook-download-name.ts). The callers are the automatic search (src/lib/processors/search-ebook.processor.ts), the select-ebook routes (src/lib/services/ebook-selection.service.ts) and admin approval (src/app/api/admin/requests/[id]/approve/route.ts). Each used to pass a raw${title} - ${author}.${format}.capTitleAuthorBytes(),src/lib/utils/path-component.ts):Title - Author.formatfits in 255 UTF-8 bytes. The title is cut first and the author kept whole, unless that would leave the title less than half the room; then the title keeps half (all of itself when shorter) and the author is cut to the rest.-and the extension are kept whole, and every cut falls between characters. The downloader swaps the queued extension for the format of the file it finds, so room is left for a 5-byte extension: a name queued as.pdf,.fb2or.anyis cut to 254 bytes, so a.epubswapped in still fits.sanitizeFilename,src/lib/processors/direct-download.processor.ts): its 200-character cap is replaced bycapFilenameBytes(), so any name it receives fits in 255 bytes and keeps its extension.organizeEbook,src/lib/utils/file-organizer.ts) still caps the source name at 200 UTF-16 units, but now cuts the stem only, so a long ebook name keeps its extension in the library too.capGraphemeUnits()), so an emoji or a surrogate pair is never split. This covers each path template variable and a renamed file's base name (src/lib/utils/path-template.util.ts), andFileOrganizer.sanitizePath(the merge temp name, source-aware folder prefixes, the ebook source name).downloadEbook()insrc/lib/services/ebook-scraper.tshas no callers. ItssanitizeEbookFilenamegets the same rule, after the 100-unit cap per part it already had.documentation/integrations/ebook-sidecar.md(File Naming, Technical Files, new Fixed Issues entry) anddocumentation/phase3/file-organization.md(Path Sanitization, Fixed Fix Plex scan marking downloaded requests #16).Why
The download names were capped by characters, not bytes, or not capped at all. The callers queued the raw
Title - Author.format, and the downloader cut it at 200 characters. So a long Cyrillic or CJK name went through at up to about 600 bytes and the download failed withENAMETOOLONGbefore the file was organized, and a long Latin name lost its extension. The organizer then cut the library name at 200 characters, extension included, so even a name that downloaded fine could land in the library without one. The.slice(0, 200)caps counted UTF-16 code units, so a title ending in an emoji near the cap could leave half a character in a folder or file name. #473 added byte caps for the names the organizer builds; this applies them to the names written at download time and to the organizer's ebook name.Neither downloader writes a temporary or partial name next to these files (no
.part,.tmpor(N)): both stream straight to the final name. The organizer copies through fixed-length.rmab-partial-*.partnames, and the metadata tagger's.tmpcopy only applies to audio. So the download names use the full 255 bytes, less the extension room above.Evidence
tests/processors/search-ebook-download-name.test.ts(automatic search) andtests/api/ebook-download-name.routes.test.ts(select-ebook route, admin approval) run the real callers: a 150-letter Cyrillic title with a 54-byte author is queued as 96 letters plus the whole author, a.pdfname stays within 254 bytes, and names that fit are queued unchanged.tests/utils/file-organizer.ebook-name.test.tsruns the realorganizeEbook()on disk with renaming off. A 221-character Latin name lands as 200 characters ending in.epub, and four names that fit land unchanged.FileOrganizer.sanitizePathdrops a whole family emoji at unit 200 and keeps one that ends exactly at the cap.tests/processors/direct-download-name-bytes.test.tsruns the realprocessStartDirectDownload(): a 300-byte ASCII name becomes 250 characters plus.epub, a long CJK name keeps.pdf, and a 255-byte name is kept whole.tests/services/ebook-scraper-name-bytes.test.tscovers the rule throughdownloadEbook();tests/lib/utils/path-byte-limit.test.tscovers emoji at the template caps;tests/lib/utils/path-component.test.tsandtests/lib/utils/ebook-download-name.test.tsare unit tests for the helpers.mainat 836abed) and this round's four new test files: 6 failed and 7 passed, all on an assertion (439-byte and author-cut names from the callers, the library name without.epub, a split emoji). The helper's own unit test file fails because the helper didn't exist yet.main'ssrc(f182a0d) and the first round's four test files: 19 failed, 41 passed. The 10 behaviour tests fail on an assertion; the 9 helper unit tests fail because the helpers didn't exist yet.Checks
vitest relatedon the nine changedsrcfiles, plus the branch's 8 test files run on their own): PASS, 118 files, 1728 passed, 1 skipped; 8 files, 84/84tsc --noEmitclean; ESLint reports nothing new in the touched files compared withmain, and the new files are clean)src/appis the queued name in the admin approve routeRisk and rollback
.pdf,.fb2or.anyat exactly 255 bytes now loses one byte of title, to leave room for a.epubswapped in.downloadHistory.torrentName(the name shown in the UI) is unchanged.Release note
🤖 Generated with Claude Code