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
+6 -1
View File
@@ -20,6 +20,7 @@ import Image from "next/image";
import { ImagePlus, Save, X } from "lucide-react";
import { useAuth } from "@/components/auth/auth-provider";
import { auth, AuthError, type User } from "@/lib/auth";
import { compressImage } from "@/lib/compress-image";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
@@ -74,7 +75,11 @@ export function ProfileEditForm({
setError(null);
setUploading(true);
try {
const publicURL = await auth.uploadAvatar(file);
// Avatars display at ≤ 200 px in every surface, so cap the
// longest edge at 800 px — plenty of retina headroom while
// keeping the stored bytes small.
const compressed = await compressImage(file, { maxDimension: 800 });
const publicURL = await auth.uploadAvatar(compressed);
setAvatarUrl(publicURL);
} catch (err) {
setError(err instanceof AuthError ? err.message : "Upload failed.");