videogen/apps/web/lib/job-media.ts
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
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

89 lines
3.5 KiB
TypeScript

/**
* Helpers for turning a Job's media references into browser-usable URLs.
*
* The backend exposes `result_url` as a presigned URL, and (Creator Studio,
* Phase 6) `poster_key` / `preview_key` for a generated thumbnail + short teaser
* clip. Those may arrive already presigned to an absolute URL. The browser has
* no R2 credentials, so a bare object key cannot be resolved client-side — we
* only ever hand `<img>`/`<video>` a value that is already an absolute HTTP(S)
* URL and otherwise degrade gracefully (placeholder / fall back to the result).
*/
import type { Job } from "@/lib/types";
/** Returns `value` only when it is a usable absolute media URL, else undefined. */
export function toDisplayUrl(value?: string | null): string | undefined {
if (!value) return undefined;
const trimmed = value.trim();
return /^https?:\/\//i.test(trimmed) ? trimmed : undefined;
}
/** Signed poster/thumbnail URL for a job. */
export function jobPosterUrl(
job: Pick<Job, "poster_url" | "poster_key">,
): string | undefined {
return toDisplayUrl(job.poster_url) ?? toDisplayUrl(job.poster_key);
}
/** Signed short preview-clip URL for a job. */
export function jobPreviewUrl(
job: Pick<Job, "preview_url" | "preview_key">,
): string | undefined {
return toDisplayUrl(job.preview_url) ?? toDisplayUrl(job.preview_key);
}
/** Presigned final-result video URL for a job, when present. */
export function jobResultUrl(job: Pick<Job, "result_url">): string | undefined {
return toDisplayUrl(job.result_url);
}
/**
* Presigned "Made with Menivor" free-tier export URL (MG-WATERMARK), when
* present. The backend only ever sets `free_export_key`/`free_export_url` for
* a job whose owner was on the free tier at render time — a paid owner's job
* never has it — so its presence alone is the right client-side gate, with
* no separate entitlement check needed here.
*/
export function jobFreeExportUrl(
job: Pick<Job, "free_export_url" | "free_export_key">,
): string | undefined {
return toDisplayUrl(job.free_export_url) ?? toDisplayUrl(job.free_export_key);
}
/**
* The best video a "ready" job can actually show: the clean `result_url` for
* a paid owner, or the "Made with Menivor" `free_export_url` for a free-tier
* owner (whose job never carries `result_url` at all, see
* `_can_access_clean_result`). Every result-page video/download control
* should read from this, not `jobResultUrl` alone -- a free-tier job falling
* through to `jobResultUrl` renders nothing playable and nothing
* downloadable at the single highest-stakes screen in the funnel (the "your
* reel is ready" win moment), found in the 2026-11-11 real-funnel audit.
*/
export function jobPlayableUrl(
job: Pick<Job, "result_url" | "free_export_url" | "free_export_key">,
): string | undefined {
return jobResultUrl(job) ?? jobFreeExportUrl(job);
}
/**
* Generated cover-image URL for a job, when `cover_url`/`cover_key` resolves to
* an absolute URL (Cover Generator). Prefer this over the poster as the reel's
* thumbnail.
*/
export function jobCoverUrl(
job: Pick<Job, "cover_url" | "cover_key">,
): string | undefined {
return toDisplayUrl(job.cover_url) ?? toDisplayUrl(job.cover_key);
}
/**
* The best available thumbnail URL for a job: the generated cover if present,
* otherwise the poster frame. Returns undefined when neither resolves.
*/
export function jobThumbnailUrl(
job: Pick<Job, "cover_url" | "cover_key" | "poster_url" | "poster_key">,
): string | undefined {
return jobCoverUrl(job) ?? jobPosterUrl(job);
}