Repository navigation
feat: attach images to commits from the API - #660
Merged
xHeaven merged 2 commits intoOct 22, 2026
Merged
Conversation
simonhamp
marked this pull request as ready for review
October 20, 2026 00:22
The app sends images as multipart, signed the way the devnull commit script signs them: the JSON body goes in a payload part and the signature covers the SHA-256 of each image. The images of a commit that isn't published yet get temporary URLs, so the author can see them in the app, which has no web session.
simonhamp
force-pushed
the
feat/api-commit-images
branch
from
October 21, 2026 00:22
ca4d839 to
2f297e9
Compare
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.
Lets the mobile app attach images to a commit, a reply or a quote, as the web's composer does. It follows #130 and is one of a few small PRs for the endpoints the app (NativePHP/dev-null-app) uses on top of it.
Endpoint
POST /api/v1/commitsnow takes up to 3 images, with an optionalimage_descriptionslist in the same order. The limits are the web's, checked by the same rules: JPEG, PNG or WebP by their contents, at most 10 MB and 6000 pixels a side, and descriptions of up to 1000 characters. With images, the body may be short or left out. The images go through the web'sCreateCommit, so they are re-encoded as WebP without metadata, and the commit goes to the same moderation.The
201has the new commit with itsimages, as before.How images fit the request signature
A signed request's signature covers its raw body, and PHP keeps no raw body for a multipart request, which is why #130 refuses multipart. So a request with images is signed the way
devnull commitalready signs a commit with images:multipart/form-data, with the JSON body in apayloadfile part and the images inimages[], and nothing else.devnull-api-images, so a signature says which format it covers.The server hashes the files it received to rebuild the message, so a swapped, reordered or missing image fails the signature. Any other field or file, a payload that isn't JSON, or a payload sent as a text field is refused like any other body that isn't JSON. Once the signature checks out, the payload becomes the request's fields, cleaned by
TrimStringsandConvertEmptyStringsToNulllike a JSON body is. An image PHP couldn't take, for example one over its upload limit, is a422onimagesrather than a bad signature.I looked at two other ways:
Multipart keeps one request and one transaction, so a commit and its images still come and go together, and it reuses a format the CLI already has.
Pending images in the app
The images of a pending commit are only served by
commit-image.showto their author or a moderator over a web session, which the app doesn't have. So in a signed response, the images of a commit that isn't published yet come with a temporary signed URL instead, andShowCommitImageRequestaccepts a valid signature as long as the commit isn't deleted. The URL expires at the end of the next hour, so it stays the same for an hour at a time and the app can keep the image it loaded. Published images keep their plain URL.Worth a look: anyone holding one of those URLs can see that pending image until it expires. Only the author and admins are ever sent one.
Testing
Everything CI runs passes on this branch locally: Pint, Rector, the JS lint, PHPStan, tsc, type coverage, and all 3,634 tests at 100% coverage.
The README documents the format, with an example. KNOWLEDGE_BASE.md said the signed API can't attach images and that its bodies are JSON only; it now says both.
The app side is NativePHP/dev-null-app#24. It ran against all four of these PRs merged together on an iOS simulator: photos from the library with a description, a poll, the preview, a reply with a photo, and a vote.