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
+7 -38
View File
@@ -67,7 +67,7 @@ import type { Post } from "@/lib/social";
import { createShortLink } from "@/lib/share";
import {
displaySourceLabel,
referenceFromUrl,
structuredReferenceForPost,
} from "@/lib/source-reference";
import { useAuth } from "@/components/auth/auth-provider";
@@ -85,43 +85,12 @@ export function SharePostSheet({
// `reference` is the single-line citation used for UI chrome — the
// drawer header, email subject, etc. where multi-line doesn't render.
const reference = displaySourceLabel(post.source_url, post.source_title);
// `structuredRef` is the same citation split into its `{ title, detail }`
// halves so the share text can lay them on separate lines — matches
// the formatCopyText pattern from selection-toolbar/shared.tsx:
//
// "caption text"
//
// Source:
// Letter to Mukunda
// 15 January, 1968 · Calcutta
// short URL
//
// Two routes to the structured shape:
//
// 1. Book URLs → `referenceFromUrl` parses the path and returns
// a clean { title, detail } (e.g. Bhagavad-gītā /
// Chapter 2, Verse 13).
// 2. Everything else (letters, essays, transcriptions, magazines)
// → `source_title` was composed by compose-post.tsx
// as "Title — Detail" using ` — ` as the join.
// We split on the first ` — ` to recover the
// structured fields. Falls back to title-only if
// no separator is present (book-index pages,
// legacy posts, etc.).
const structuredRef = useMemo<{ title: string; detail: string | null }>(
() => {
const r = referenceFromUrl(post.source_url);
if (r) return r;
const stored = post.source_title?.trim() || "Source";
const idx = stored.indexOf(" — ");
if (idx === -1) {
return { title: stored, detail: null };
}
return {
title: stored.slice(0, idx).trim(),
detail: stored.slice(idx + 3).trim() || null,
};
},
// Structured `{ title, detail }` for the multi-line "Source:" block
// in the share payload. Same helper that the direct-mobile native
// share path in post-actions-footer.tsx uses, so both surfaces
// produce byte-identical citation lines.
const structuredRef = useMemo(
() => structuredReferenceForPost(post.source_url, post.source_title),
[post.source_url, post.source_title],
);
const firstImage = post.images?.[0]?.url ?? null;