Commit graph

10 commits

Author SHA1 Message Date
Paulo Castellano
74e6d341ab
fix: sanitize invalid UTF-8 bytes in uploaded filenames (#265)
* fix: sanitize invalid UTF-8 bytes in uploaded filenames

A client-supplied filename containing a raw non-UTF-8 byte (e.g. 0x97,
a Windows-1252 em dash) crashed the media insert with an uncaught
QueryException: Postgres rejects invalid UTF-8 byte sequences outright
under UTF8 encoding. Centralized a sanitizeOriginalFilename() helper
in HasMedia and applied it to all three insert paths that store
original_filename: addMedia(), addMediaFromPath(), and
addMediaFromStoredPath() (the multipart cloud-upload registration
path) — so every upload entry point is covered, not just the one that
happened to crash in production.

Fixes Nightwatch issue #24.

* refactor: use mb_scrub() instead of the mb_convert_encoding same-encoding trick

mb_scrub() (PHP 8.1+) is the purpose-built function for scrubbing
invalid byte sequences — same behavior, clearer intent than the
convert-to-same-encoding workaround it replaces.

* test: cover addMediaFromStoredPath (previously untested, including sanitize fix)

addMediaFromStoredPath — the multipart cloud-upload registration path
— had zero test coverage before this PR, including for the invalid
UTF-8 filename fix applied to it. Added a basic happy-path test plus
the sanitize regression test, matching the coverage already added for
addMedia() and addMediaFromPath().

Verified the regression test actually catches the bug: reverted the
sanitize call for this one method locally, confirmed the test fails
with the exact Nightwatch #24 QueryException, then restored the fix.
2026-08-09 14:29:29 -03:00
Paulo Castellano
e4779dfcdf Clamp media byte caps to upload limits and surface truncated board lists.
Align editor/API/MCP size ceilings with trypost.media hard caps, return truncated from Pinterest board pagination stop conditions, and rename the signed-upload claim key and rate limiter away from the MCP-only naming.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 22:49:04 -03:00
Paulo Castellano
0d4e5fd963 Restore media-rule parity and release failed MCP upload tokens.
Keep Instagram feed requiring media and Discord/Telegram accepting GIFs after centralization, skip the empty workspace rate-limit bucket, and clear the signed upload claim when persistence fails so retries work.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 22:37:57 -03:00
Paulo Castellano
b28b18ef72 Address PR review: stream MCP uploads and close listing gaps.
Stream signed uploads through addMediaFromPath, return per-type max_bytes, harden Pinterest/Discord listing errors and pagination, and keep frontend duration fallbacks when Inertia once-props have not synced.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 22:00:07 -03:00
Paulo Castellano
3175fbe8c2 Centralize MCP upload size caps on trypost.media.
Drop the separate ai.mcp.upload.max_size_mb default and reuse Media\Type limits so MCP matches web/API (1GB video ceiling with per-type enforcement).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 21:29:41 -03:00
Paulo Castellano
564f157e44 Fix MCP upload rate limits and Instagram Reel duration caps.
Key signed uploads by workspace so ChatGPT's shared egress IPs don't throttle tenants together, raise the MCP upload cap to 300MB, and expose accurate Reel max durations via API/MCP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 21:21:39 -03:00
Paulo Castellano
7fac3aaf0f feat(media): rate-limit upload endpoint to 10 req/min/IP 2026-05-15 17:09:40 -03:00
Paulo Castellano
9845d15db3 refactor(media): MediaUploadResource + ws→workspace_id + cleanup 2026-05-15 16:48:09 -03:00
Paulo Castellano
d50348562b refactor(media): atomic upload_token via transaction and tighten test assertions 2026-05-15 16:16:42 -03:00
Paulo Castellano
b17026f3a1 feat(media): signed POST upload endpoint for MCP flow 2026-05-15 16:10:21 -03:00