Skip to main content

useFreshPhotoUrl

Source: hooks/useFreshPhotoUrl.ts (86 lines) The useFreshPhotoUrl hook handles the complete photo upload lifecycle for embarrassing photo penalties, generating time-limited signed URLs and uploading the captured image to Convex Storage.

Upload Pipeline


Time-Limited URLs

The signed upload URL is valid for a short window (typically 60 seconds). This prevents replay attacks where a captured URL could be reused to upload arbitrary content at a later time.

Blob Conversion

The hook converts the local file URI (from the camera or gallery) into a Blob for upload:

Integration with useCommitTask

The useFreshPhotoUrl hook is called by useCommitTask before the Triple-Write executes. The returned storage ID is embedded in the penalty config, which is then frozen onto each generated task instance as part of the immutable penalty snapshot.

Error Handling

If the upload fails (network error, storage quota exceeded), the hook returns null for the storage ID. The useCommitTask hook checks for this and aborts the commit with a user-facing error message rather than creating a commitment with a broken penalty reference.