Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: bake EXIF orientation into pixels before sending init image to mflux
Adam Eivyca8631dd05e7
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex d2de11c663..cbfef6dc08 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,6 +2,8 @@## Fixed+- **Flux i2i: portrait iPhone photos came out rotated 90°.** Modern browsers honor the EXIF Orientation tag when rendering `<img>`, so the upload thumbnail looked right — but mflux/PIL reads raw pixel data and ignores EXIF, so a portrait iPhone photo (Orientation=6 or 8) landed sideways in the generated output. The init image picker now passes the file through `createImageBitmap({ imageOrientation: 'from-image' })` and re-encodes via canvas before upload, baking the rotation into the actual pixels and stripping the EXIF tag. Any image decoder downstream now sees the same orientation the browser displayed. File: `client/src/pages/ImageGen.jsx`.+- **Multipart upload server crash: `Cannot read properties of null (reading 'write')`.** Streaming multipart parser (`server/lib/multipart.js`) crashed with an uncaught `TypeError` when the request stream's `'end'` event fired while a file part's `ws.end()` flush was still in flight. After consuming a part boundary, `endPart()` synchronously nulled `writeStream` but kept `state` at `STATE_BODY` until the async `ws.end` callback ran. If `req.on('end')` fired during that window, the end handler called `tick()`, which re-entered `STATE_BODY`, found another boundary in the trailing buffer, and called `writePartChunk()` → `writeStream.write(chunk)` on a `null` stream → process-killing `uncaughtException`. Fix: `tick()` now returns early when `pendingFlush > 0`; the existing `endPart` callback already re-invokes `tick()` once the flush completes and state has advanced. Added a regression test that defers the mocked `ws.end()` callback so the bug reproduces without the fix. File: `server/lib/multipart.js`.- **Image Gen status badge stuck on "SD API unreachable" when Local mode is selected.** The page mounts before settings load, so the first `refreshStatus` call goes out with `mode=external` (the fallback in `effectiveMode = selectedMode || status?.mode || 'external'`). The local-mode probe that fires moments later (after settings populate `selectedMode='local'`) returns instantly because it just checks if the Python path is set — but the original external-mode probe is still in flight, blocking on a TCP timeout against the unconfigured SD API URL. When that slow response finally arrived, it overwrote the green "mflux/local" badge with the red "SD API unreachable — Settings" message, even though the Local chip was clearly selected. Token-guarded `refreshStatus` so each call records a monotonically incrementing token and only applies its `setStatus` if its token still matches the latest one — stale responses get silently dropped. File: `client/src/pages/ImageGen.jsx`.diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsxindex 6a1e94856c..db0ead07a4 100644--- a/client/src/pages/ImageGen.jsx+++ b/client/src/pages/ImageGen.jsx@@ -220,9 +220,31 @@ export default function ImageGen() {// eslint-disable-next-line react-hooks/exhaustive-deps}, [searchParams]);- const handlePickInitImage = (e) => {- const file = e.target.files?.[0];- if (!file) return;+ // Strip EXIF orientation by re-encoding the image with rotation baked into+ // the pixels. Browsers honor EXIF when rendering <img>, so the upload+ // thumbnail looks right — but mflux/PIL reads raw pixels and ignores EXIF,+ // so a portrait iPhone photo (Orientation=6 or 8) lands sideways in the+ // generated output. createImageBitmap({ imageOrientation: 'from-image' })+ // applies the EXIF rotation; canvas re-encode produces an EXIF-free file+ // that any decoder will read in the same orientation as the browser shows.+ const normalizeImageOrientation = async (file) => {+ const bitmap = await window.createImageBitmap(file, { imageOrientation: 'from-image' }).catch(() => null);+ if (!bitmap) return file;+ const canvas = document.createElement('canvas');+ canvas.width = bitmap.width;+ canvas.height = bitmap.height;+ canvas.getContext('2d').drawImage(bitmap, 0, 0);+ bitmap.close?.();+ const blob = await new Promise((resolve) => canvas.toBlob(resolve, 'image/png'));+ if (!blob) return file;+ const newName = file.name.replace(/\.[^.]+$/, '.png');+ return new File([blob], newName, { type: 'image/png' });+ };++ const handlePickInitImage = async (e) => {+ const raw = e.target.files?.[0];+ if (!raw) return;+ const file = await normalizeImageOrientation(raw);if (initImage.previewUrl?.startsWith('blob:')) URL.revokeObjectURL(initImage.previewUrl);setInitImage({ source: 'upload', file, name: file.name, previewUrl: URL.createObjectURL(file) });};