feat: image compress before upload

This commit is contained in:
gosangam
2026-05-31 09:56:53 +05:30
parent 5506afa758
commit 8bd82a0e8a
10 changed files with 673 additions and 60 deletions
@@ -27,6 +27,7 @@ import {
import { posts, SocialError } from "@/lib/social";
import { buildHighlightUrl } from "@/lib/text-highlight";
import { getSourceReference } from "@/lib/source-reference";
import { compressImage } from "@/lib/compress-image";
import { useSharePost } from "@/components/social/share-post-provider";
const MAX_IMAGES = 5;
@@ -75,7 +76,12 @@ export function ComposePost({
await Promise.all(
picked.map(async (file, i) => {
try {
const url = await posts.uploadImage(file);
// Compress in the browser before the presigned PUT — keeps
// R2 storage bounded, makes share pre-fetch fast, strips
// EXIF as a side effect. Falls back to the original file
// on any decode failure.
const compressed = await compressImage(file);
const url = await posts.uploadImage(compressed);
setImages((prev) => {
const next = [...prev];
next[baseIndex + i] = { url, uploading: false };