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
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.
81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
/**
|
|
* A tiny, sessionStorage-backed handoff for SPARK → wizard prefill.
|
|
*
|
|
* The Ideas page stashes an idea's create-job-shaped fields here, then routes
|
|
* to `/new`; the wizard reads (and clears) them once on mount to pre-fill its
|
|
* form. sessionStorage keeps the payload off the URL and scoped to the tab.
|
|
* Nothing here is a secret. All reads validate the untrusted stored value.
|
|
*/
|
|
|
|
import type { Language, Layout } from "@/lib/types";
|
|
|
|
/** The wizard-ready fields an idea contributes when "Make this" is clicked. */
|
|
export interface SparkPrefill {
|
|
/** Seed for `params.video_subject` (derived from the idea's hook + angle). */
|
|
videoSubject: string;
|
|
/** Seed for the optional `params.video_script` (the idea's script outline). */
|
|
prompt: string;
|
|
/** Suggested composition layout. */
|
|
layout: Layout;
|
|
/** Suggested caption-style id. */
|
|
captionStyle: string;
|
|
/** Suggested output language. */
|
|
language: Language;
|
|
}
|
|
|
|
const STORAGE_KEY = "reelforge:spark-prefill";
|
|
|
|
const LAYOUTS: readonly Layout[] = ["pip", "hook_intro", "split"];
|
|
const LANGUAGES: readonly Language[] = ["auto", "tr", "en"];
|
|
|
|
function asString(value: unknown): string {
|
|
return typeof value === "string" ? value : "";
|
|
}
|
|
|
|
/** Narrows an untrusted parsed value back into a safe {@link SparkPrefill}. */
|
|
function coerce(value: unknown): SparkPrefill | null {
|
|
if (!value || typeof value !== "object") return null;
|
|
const raw = value as Record<string, unknown>;
|
|
|
|
const layout = LAYOUTS.includes(raw.layout as Layout)
|
|
? (raw.layout as Layout)
|
|
: "pip";
|
|
const language = LANGUAGES.includes(raw.language as Language)
|
|
? (raw.language as Language)
|
|
: "auto";
|
|
|
|
return {
|
|
videoSubject: asString(raw.videoSubject),
|
|
prompt: asString(raw.prompt),
|
|
layout,
|
|
captionStyle: asString(raw.captionStyle) || "karaoke_yellow",
|
|
language,
|
|
};
|
|
}
|
|
|
|
/** Persist a prefill for the wizard to pick up on its next mount. */
|
|
export function stashSparkPrefill(prefill: Readonly<SparkPrefill>): void {
|
|
if (typeof window === "undefined") return;
|
|
try {
|
|
window.sessionStorage.setItem(STORAGE_KEY, JSON.stringify(prefill));
|
|
} catch {
|
|
// sessionStorage may be unavailable (private mode/quota) — fail silently.
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Read and remove the stashed prefill, if any. Returns `null` when nothing was
|
|
* stashed or the stored value is unusable. Single-use by design.
|
|
*/
|
|
export function takeSparkPrefill(): SparkPrefill | null {
|
|
if (typeof window === "undefined") return null;
|
|
try {
|
|
const raw = window.sessionStorage.getItem(STORAGE_KEY);
|
|
if (!raw) return null;
|
|
window.sessionStorage.removeItem(STORAGE_KEY);
|
|
return coerce(JSON.parse(raw) as unknown);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|