caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

64 lines
2.2 KiB
TypeScript

import * as FileSystem from "expo-file-system/legacy";
import { Platform, Share } from "react-native";
/**
* Save/share the generated cover image. There is no expo-sharing or
* media-library dependency in this app, so we lean on the platform share sheet
* (React Native's built-in `Share`), which already exposes "Save Image" /
* "Save to Files" on iOS and the equivalent targets on Android.
*
* We first try to download the remote JPG into the app cache and share the
* local `file://` URI (best experience — the OS treats it as an image and
* offers Save to Photos). If the download fails for any reason we degrade to
* sharing the presigned URL as a link, so the action never hard-fails.
*/
/** Derives a stable, filesystem-safe local filename for a job's cover. */
function localCoverPath(jobId: string): string {
const safeId = jobId.replace(/[^A-Za-z0-9_-]/g, "_");
// cacheDirectory is always present on native; guard for web/types anyway.
const dir = FileSystem.cacheDirectory ?? FileSystem.documentDirectory ?? "";
return `${dir}cover-${safeId}.jpg`;
}
export interface ShareCoverArgs {
/** Absolute (presigned) URL of the rendered cover image. */
url: string;
/** Job id — used only to name the downloaded file. */
jobId: string;
/** Message/title shown in the share sheet. */
message?: string;
}
/**
* Downloads the cover then opens the OS share sheet on the local file. Returns
* `true` when the user completed a share action, `false` when they dismissed it.
* Throws only on a genuinely unrecoverable error (e.g. Share unavailable).
*/
export async function saveOrShareCover({
url,
jobId,
message = "My reel cover",
}: Readonly<ShareCoverArgs>): Promise<boolean> {
let shareUrl = url;
try {
const target = localCoverPath(jobId);
const { uri } = await FileSystem.downloadAsync(url, target);
if (uri) shareUrl = uri;
} catch {
// Fall back to sharing the remote URL directly.
shareUrl = url;
}
// iOS uses `url` for a file/link; Android only surfaces `message`, so include
// the link there too.
const result = await Share.share(
Platform.OS === "ios"
? { url: shareUrl, message }
: { message: `${message}\n${shareUrl}` },
);
return result.action === Share.sharedAction;
}