mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-10-17 21:29:20 +02:00
A file named IMG_0001.JPG was refused with "is not a valid image upload", although the page lets it be attached. The chat route gave the upload parser a list of extensions, and @adonisjs/bodyparser compares an extension case-sensitively, so only jpg, jpeg, png and webp in lower case were valid. The parser now checks size only, and normalizeChatImage checks the parser's extname against the same list without regard to case. The extname is the type the parser read from the file's bytes when the name has no extension or a lower-case one it recognizes, and the extension as written otherwise. A refusal is the same 422. The options move to CHAT_IMAGE_UPLOAD_OPTIONS in chat_images.ts, so a test can use the controller's value; size is MAX_CHAT_IMAGE_BYTES, the same 8 MB. Behavior, from 62 combinations of file name and content run through the real parser and normalizeChatImages on dev and on this change: nothing that was accepted is refused, 39 are unchanged, and every difference comes from an upper-case or mixed-case extension. Upper-case and mixed-case JPEG, PNG and WebP names are accepted, and so is an animated PNG named .PNG: the parser does not read the bytes behind an upper-case name, so sharp takes its first frame, as it already does for one named .jpeg. A GIF, TIFF, AVIF or SVG named .JPG or .PNG gets 415 from sharp instead of 422. Text, PDF and one-byte files named .JPG or .PNG keep their 422, and the message changes from "is not a valid image upload" to "could not be decoded as an image". Tests: tests/unit/chat_image_upload.spec.ts sends files through the real multipart parser with those options, then normalizeChatImages. It fails if the list goes back into the parser options, if the extension check is dropped, if it is made case-sensitive, or if a file with no extname is let through. The hand-built files in chat_images.spec.ts and ollama_controller_chat.spec.ts gain an extname, as the parser sets one. The 13 tests in chat_image_upload.spec.ts and chat_images.spec.ts pass, and typecheck shows the same 11 errors as dev, from packages missing or older in my checkout. Not run: the controller in a running install, and its Japa spec (openai is missing in my checkout); that spec's hand-built file was checked against normalizeChatImages directly. |
||
|---|---|---|
| .. | ||
| app | ||
| bin | ||
| commands | ||
| config | ||
| constants | ||
| database | ||
| docs | ||
| inertia | ||
| providers | ||
| public | ||
| resources | ||
| scripts | ||
| start | ||
| tests | ||
| types | ||
| util | ||
| views | ||
| .editorconfig | ||
| .env.example | ||
| ace.js | ||
| adonisrc.ts | ||
| eslint.config.js | ||
| package-lock.json | ||
| package.json | ||
| tailwind.config.ts | ||
| tsconfig.json | ||
| vite.config.ts | ||