Skip to content

Unrestricted Open-source alternative to AI video platforms — Free AI image & video generation studio with 600+ models (Flux, Midjourney, Kling, Sora, Veo). No content filters. Self-hosted, MIT licensed.

Add server-backed generation history and per-identity localStorage scoping

Anil-matcha8fadaeddb7bf
diff --git a/packages/studio/src/components/AudioStudio.jsx b/packages/studio/src/components/AudioStudio.jsx
index ab8e423c..11c0dc0e 100644
--- a/packages/studio/src/components/AudioStudio.jsx
+++ b/packages/studio/src/components/AudioStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { generateAudio, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import { audioModels, getAudioModelById } from "../models.js";
// ---------------------------------------------------------------------------
@@ -480,7 +481,11 @@ export default function AudioStudio({
droppedFiles,
onFilesHandled,
}) {
- const PERSIST_KEY = "hg_audio_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_audio_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Mode & model state ──────────────────────────────────────────────────
const [selectedModelId, setSelectedModelId] = useState(audioModels[0]?.id ?? "");
diff --git a/packages/studio/src/components/CinemaStudio.jsx b/packages/studio/src/components/CinemaStudio.jsx
index 84fb008a..cdca0f0e 100644
--- a/packages/studio/src/components/CinemaStudio.jsx
+++ b/packages/studio/src/components/CinemaStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { generateImage, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import {
PromptAspectRatioIcon,
PromptAction,
@@ -486,7 +487,11 @@ export default function CinemaStudio({
onGenerationError,
historyItems,
}) {
- const PERSIST_KEY = "hg_cinema_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_cinema_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Settings state ──
const [settings, setSettings] = useState({
diff --git a/packages/studio/src/components/ClippingStudio.jsx b/packages/studio/src/components/ClippingStudio.jsx
index 1d8ff084..daff9bed 100644
--- a/packages/studio/src/components/ClippingStudio.jsx
+++ b/packages/studio/src/components/ClippingStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef } from "react";
import { runClipping, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import {
PROMPT_CONTROL_LABEL_CLASS,
PROMPT_MEDIA_PREVIEW_CLASS,
@@ -83,7 +84,11 @@ export default function ClippingStudio({
droppedFiles,
onFilesHandled,
}) {
- const PERSIST_KEY = "hg_clipping_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_clipping_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Clipping Parameters State ───────────────────────────────────────────
const [videoUrl, setVideoUrl] = useState("");
diff --git a/packages/studio/src/components/ImageStudio.jsx b/packages/studio/src/components/ImageStudio.jsx
index 07a1d4b2..df4b2be8 100644
--- a/packages/studio/src/components/ImageStudio.jsx
+++ b/packages/studio/src/components/ImageStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { generateImage, generateI2I, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import DrawModal from "./DrawModal.jsx";
import {
t2iModels,
@@ -850,7 +851,11 @@ export default function ImageStudio({
droppedFiles,
onFilesHandled,
}) {
- const PERSIST_KEY = "hg_image_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_image_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Model / mode state ──────────────────────────────────────────────────
const [imageMode, setImageMode] = useState(false); // false=t2i, true=i2i
diff --git a/packages/studio/src/components/LipSyncStudio.jsx b/packages/studio/src/components/LipSyncStudio.jsx
index 1db04bd9..03404b58 100644
--- a/packages/studio/src/components/LipSyncStudio.jsx
+++ b/packages/studio/src/components/LipSyncStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { processLipSync, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import {
lipsyncModels,
imageLipSyncModels,
@@ -319,7 +320,11 @@ export default function LipSyncStudio({
droppedFiles,
onFilesHandled,
}) {
- const PERSIST_KEY = "hg_lipsync_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_lipsync_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Mode & model state ──────────────────────────────────────────────────
const [inputMode, setInputMode] = useState("image"); // 'image' | 'video'
diff --git a/packages/studio/src/components/MarketingStudio.jsx b/packages/studio/src/components/MarketingStudio.jsx
index c5e71819..6c61e74b 100644
--- a/packages/studio/src/components/MarketingStudio.jsx
+++ b/packages/studio/src/components/MarketingStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { uploadFile, generateMarketingStudioAd } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import {
PROMPT_CONTROL_LABEL_CLASS,
PromptAspectRatioIcon,
@@ -268,7 +269,11 @@ function SimpleDropdown({ isOpen, title, options, selected, onSelect, onClose })
// ── Main Component ───────────────────────────────────────────────────────────
export default function MarketingStudio({ apiKey, droppedFiles, onFilesHandled, onGenerationComplete, onGenerationError, historyItems }) {
- const PERSIST_KEY = "hg_marketing_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_marketing_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
const [prompt, setPrompt] = useState("");
const [productImage, setProductImage] = useState(null);
diff --git a/packages/studio/src/components/RecastStudio.jsx b/packages/studio/src/components/RecastStudio.jsx
index d84c47c3..ec08961e 100644
--- a/packages/studio/src/components/RecastStudio.jsx
+++ b/packages/studio/src/components/RecastStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { processRecast, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import {
recastModels,
getRecastModelById,
@@ -410,7 +411,11 @@ export default function RecastStudio({
droppedFiles,
onFilesHandled,
}) {
- const PERSIST_KEY = "hg_recast_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_recast_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Model state ───────────────────────────────────────────────────────────
const firstModel = recastModels[0];
diff --git a/packages/studio/src/components/VibeMotionStudio.jsx b/packages/studio/src/components/VibeMotionStudio.jsx
index 5752d5be..05931b91 100644
--- a/packages/studio/src/components/VibeMotionStudio.jsx
+++ b/packages/studio/src/components/VibeMotionStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { runMotionGraphics, runMotionGraphicsEdit } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import {
PROMPT_CONTROL_LABEL_CLASS,
PromptAspectRatioIcon,
@@ -63,7 +64,11 @@ function DropdownItem({ label, selected, onClick }) {
// ── Main Component ────────────────────────────────────────────────────────────
export default function VibeMotionStudio({ apiKey, onGenerationComplete, onGenerationError }) {
- const PERSIST_KEY = "hg_vibe_motion_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_vibe_motion_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── Params ────────────────────────────────────────────────────────────────
const [prompt, setPrompt] = useState("");
diff --git a/packages/studio/src/components/VideoStudio.jsx b/packages/studio/src/components/VideoStudio.jsx
index e7d7a745..1a29f4dd 100644
--- a/packages/studio/src/components/VideoStudio.jsx
+++ b/packages/studio/src/components/VideoStudio.jsx
@@ -2,6 +2,7 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { generateVideo, generateI2V, processV2V, uploadFile } from "../muapi.js";
+import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import DrawModal from "./DrawModal.jsx";
import {
t2vModels,
@@ -407,7 +408,11 @@ export default function VideoStudio({
droppedFiles,
onFilesHandled,
}) {
- const PERSIST_KEY = "hg_video_studio_persistent";
+ const LEGACY_PERSIST_KEY = "hg_video_studio_persistent";
+ const PERSIST_KEY = scopedPersistKey(LEGACY_PERSIST_KEY, apiKey);
+ useEffect(() => {
+ migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
+ }, [PERSIST_KEY]);
// ── mode state ──
const [imageMode, setImageMode] = useState(false); // i2v
diff --git a/packages/studio/src/muapi.js b/packages/studio/src/muapi.js
index 693f567f..59b3e64f 100644
--- a/packages/studio/src/muapi.js
+++ b/packages/studio/src/muapi.js
@@ -705,6 +705,25 @@ export async function getAppInterests(apiKey) {
return await response.json();
}
+// Paginated past-generations list, scoped server-side to the calling identity
+// (BYOK key or white-label session token) — see GET /api/v1/history.
+export async function getHistory(apiKey, { cursor, limit = 50 } = {}) {
+ const params = new URLSearchParams();
+ if (cursor) params.set('cursor', cursor);
+ if (limit) params.set('limit', String(limit));
+ const response = await fetch(`${BASE_URL}/api/v1/history?${params.toString()}`, {
+ headers: {
+ 'Content-Type': 'application/json',
+ 'x-api-key': apiKey
+ }
+ });
+ if (!response.ok) {
+ const errText = await response.text();
+ throw new Error(`Failed to fetch history: ${response.status} - ${errText.slice(0, 100)}`);
+ }
+ return await response.json();
+}
+
export async function runClipping(apiKey, params) {
const payload = {
video_url: params.video_url,
diff --git a/packages/studio/src/persistKey.js b/packages/studio/src/persistKey.js
new file mode 100644
index 00000000..8cf219bf
--- /dev/null
+++ b/packages/studio/src/persistKey.js
@@ -0,0 +1,32 @@
+// Scopes a studio's localStorage persistence key to the calling identity
+// (white-label session token or BYOK API key). Without this, every identity
+// sharing one browser (different white-label end users, or BYOK vs white-label
+// mode) read/wrote the same fixed key — history and draft state leaked between
+// unrelated accounts on a shared device.
+export function scopedPersistKey(baseKey, apiKey) {
+ if (!apiKey) return baseKey;
+ // Short, stable hash — avoids putting a raw session token/API key verbatim
+ // into a localStorage key name.
+ let hash = 0;
+ for (let i = 0; i < apiKey.length; i++) {
+ hash = (hash * 31 + apiKey.charCodeAt(i)) | 0;
+ }
+ return `${baseKey}:${(hash >>> 0).toString(36)}`;
+}
+
+// One-time best-effort carryover from the old shared (unscoped) key into the
+// current identity's scoped key, then clears the old key so the next different
+// identity on this browser doesn't inherit (or re-leak) it.
+export function migrateLegacyPersistKey(baseKey, scopedKey) {
+ if (scopedKey === baseKey) return;
+ try {
+ if (localStorage.getItem(scopedKey)) return; // already migrated
+ const legacy = localStorage.getItem(baseKey);
+ if (legacy) {
+ localStorage.setItem(scopedKey, legacy);
+ localStorage.removeItem(baseKey);
+ }
+ } catch {
+ // localStorage unavailable (SSR/private mode) — nothing to migrate
+ }
+}