From cddc69a393e8c1da3fc5b92fea5ffe4741d6b21e Mon Sep 17 00:00:00 2001 From: deltaaa00 Date: Sun, 15 Nov 2026 20:50:23 +0200 Subject: [PATCH 1/2] fix(worker): preserve ImageClip mask alpha and use prepared_bg_path in Rust render --- yt-dlp_serv.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/yt-dlp_serv.py b/yt-dlp_serv.py index 97859c3..d6a868f 100644 --- a/yt-dlp_serv.py +++ b/yt-dlp_serv.py @@ -813,18 +813,28 @@ def _veil_mask(t: float) -> np.ndarray: try: # pragma: no cover import automap_rs - def _to_rgba_bytes(arr: np.ndarray) -> bytes: - # Ensure 4-channel RGBA layout before passing raw bytes to Rust. - if arr.shape[2] == 3: + if not hasattr(automap_rs, "render_video_rs"): + raise ImportError("automap_rs native extension not built") + + def _clip_to_rgba_bytes(clip_obj, sample_t: float = 0.0) -> bytes: + # MoviePy splits RGBA inputs into 3-channel clip.img + float clip.mask. + arr = np.asarray(clip_obj.img, dtype=np.uint8) + if arr.ndim == 3 and arr.shape[2] == 4: + return arr.tobytes() + if getattr(clip_obj, "mask", None) is not None: + mask_frame = np.asarray(clip_obj.mask.get_frame(sample_t)) + alpha = np.clip(mask_frame * 255.0, 0, 255).astype(np.uint8) + if alpha.ndim == 2: + alpha = alpha[:, :, None] + else: alpha = np.full((arr.shape[0], arr.shape[1], 1), 255, dtype=np.uint8) - arr = np.concatenate([arr, alpha], axis=2) - return arr.tobytes() + return np.concatenate([arr[:, :, :3], alpha], axis=2).tobytes() static_rgba = None dynamic_overlays = [] veil_duration = 0.0 - # Skip clips[0] (background_video); Rust decodes it directly from bg_path. + # Skip clips[0] (background_video); Rust decodes it directly from prepared_bg_path. for clip in clips[1:]: if not hasattr(clip, "img"): continue @@ -833,7 +843,7 @@ def _to_rgba_bytes(arr: np.ndarray) -> bytes: is_full_canvas = clip.img.shape[:2] == (canvas_h, canvas_w) if not is_dynamic and is_full_canvas: - static_rgba = _to_rgba_bytes(clip.img) + static_rgba = _clip_to_rgba_bytes(clip, 0.0) elif is_dynamic and is_full_canvas and clip.img.shape[2] == 3: # Full-canvas 3-channel black clip represents the intro fade veil. veil_duration = float(clip.duration or 0.0) @@ -843,11 +853,11 @@ def _to_rgba_bytes(arr: np.ndarray) -> bytes: h, w = clip.img.shape[:2] x = (canvas_w - w) // 2 if pos[0] == "center" else int(pos[0]) y = (canvas_h - h) // 2 if pos[1] == "center" else int(pos[1]) - dynamic_overlays.append((_to_rgba_bytes(clip.img), x, y, int(w), int(h), 0.0, 0.0)) + dynamic_overlays.append((_clip_to_rgba_bytes(clip, float(bg_duration)), x, y, int(w), int(h), 0.0, 0.0)) - if static_rgba is not None and bg_path: + if static_rgba is not None and prepared_bg_path: automap_rs.render_video_rs( - bg_path, + prepared_bg_path, static_rgba, dynamic_overlays, veil_duration, From 0275c8d0ee19939e7fe646f5454cc0ba4666a3f3 Mon Sep 17 00:00:00 2001 From: deltaaa00 Date: Mon, 16 Nov 2026 00:06:11 +0200 Subject: [PATCH 2/2] feat(web): add confirmed reset of all browser user data --- static/studio-storage.js | 44 +++++++++++++++++++++++++++++- templates/index.html | 1 + templates/video.html | 1 + tests/browser/test_video_studio.py | 28 +++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/static/studio-storage.js b/static/studio-storage.js index 3958fbe..c500bd9 100644 --- a/static/studio-storage.js +++ b/static/studio-storage.js @@ -1,6 +1,7 @@ /* Shared browser storage for generated maps and selected video materials. */ window.StudioStorage = (() => { let connection; + let clearing = false; function open() { if (!connection) { connection = new Promise((resolve, reject) => { @@ -43,7 +44,9 @@ window.StudioStorage = (() => { } async function setAsset(key, file, metadata = {}) { + if (clearing) return; const db = await open(); + if (clearing) return; const record = { blob: file, name: file?.name, type: file?.type, lastModified: file?.lastModified, updatedAt: Date.now(), @@ -62,7 +65,9 @@ window.StudioStorage = (() => { /* Run a read/write history transaction, pruning entries older than 24 hours. */ async function historyTransaction(action) { + if (clearing) return []; const db = await open(); + if (clearing) return []; return new Promise((resolve, reject) => { const transaction = db.transaction('history', 'readwrite'); const store = transaction.objectStore('history'); @@ -98,10 +103,47 @@ window.StudioStorage = (() => { }); } - return {getAsset, setAsset, HISTORY_RETENTION_MS, + async function clearAll() { + clearing = true; + try { + const db = await open(); + await new Promise((resolve, reject) => { + const transaction = db.transaction(['assets', 'history'], 'readwrite'); + transaction.objectStore('assets').clear(); + transaction.objectStore('history').clear(); + transaction.oncomplete = resolve; + transaction.onabort = () => reject(transaction.error || new Error('Could not clear browser data.')); + transaction.onerror = () => reject(transaction.error); + }); + } catch (error) { + clearing = false; + throw error; + } + } + + return {getAsset, setAsset, clearAll, HISTORY_RETENTION_MS, getHistory: () => historyTransaction(), pruneHistory: () => historyTransaction({prune: true}), addHistory: entry => historyTransaction({entry}), clearHistory: () => historyTransaction({clear: true}), }; })(); + +/* Reset both studios together; cookies and server credentials are unaffected. */ +async function clearAllUserData(button) { + if (!window.confirm('Clear all data? This removes saved API keys, topics, settings, run history, maps, and selected video/audio materials from this browser. This cannot be undone.')) return; + button.disabled = true; + try { + await StudioStorage.clearAll(); + for (const storage of [localStorage, sessionStorage]) { + for (const key of Object.keys(storage)) { + if (/^automap[-_]/.test(key)) storage.removeItem(key); + } + } + // Navigate to a fresh document so inputs and in-memory previews reset too. + window.location.replace(window.location.pathname); + } catch (error) { + button.disabled = false; + window.alert('Could not clear all data. Please allow browser storage and try again.'); + } +} diff --git a/templates/index.html b/templates/index.html index da9e94e..910e5a5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -280,6 +280,7 @@

+ {% if config.WEB_AUTH_ENABLED and session.get('web_identity') %}
diff --git a/templates/video.html b/templates/video.html index d1fedb1..1248d59 100644 --- a/templates/video.html +++ b/templates/video.html @@ -374,6 +374,7 @@

AutoMap Vid 03 Frame & Render + {% if config.WEB_AUTH_ENABLED and session.get('web_identity') %} diff --git a/tests/browser/test_video_studio.py b/tests/browser/test_video_studio.py index df60a6f..930ddeb 100644 --- a/tests/browser/test_video_studio.py +++ b/tests/browser/test_video_studio.py @@ -666,3 +666,31 @@ def test_new_stickers_exist_on_both_sides_and_preview_offline(studio): page.wait_for_function("document.querySelector('#stageTopLeftSticker img')?.naturalWidth > 0") page.wait_for_function("document.querySelector('#stageTopRightSticker img')?.naturalWidth > 0") assert page.locator('#stageCompositeBox').evaluate("el => el.classList.contains('has-top-stickers')") + + +def test_clear_all_data_requires_confirmation_and_clears_both_studios(studio): + page, _ = studio + page.evaluate("""async () => { + localStorage.setItem('automap-gemini-api-key', 'private-key'); + localStorage.setItem('automap-map-topic', 'saved topic'); + localStorage.setItem('unrelated-setting', 'keep'); + sessionStorage.setItem('automap-test', 'session value'); + await StudioStorage.setAsset('latest-map', new File(['map'], 'map.png')); + await StudioStorage.addHistory({id: 'test', createdAt: Date.now(), state: {topic: 'saved topic'}}); + }""") + page.once('dialog', lambda dialog: dialog.dismiss()) + page.locator('#clearAllDataBtn').click() + assert page.evaluate("localStorage.getItem('automap-gemini-api-key')") == 'private-key' + assert page.evaluate("async () => (await StudioStorage.getHistory()).length") == 1 + page.once('dialog', lambda dialog: dialog.accept()) + with page.expect_navigation(): + page.locator('#clearAllDataBtn').click() + assert page.evaluate("localStorage.getItem('automap-gemini-api-key')") is None + assert page.evaluate("localStorage.getItem('automap-map-topic')") is None + assert page.evaluate("sessionStorage.getItem('automap-test')") is None + assert page.evaluate("localStorage.getItem('unrelated-setting')") == 'keep' + assert page.evaluate("async () => await StudioStorage.getAsset('latest-map')") is None + assert page.evaluate("async () => await StudioStorage.getHistory()") == [] + page.goto('http://automap.test/') + assert page.locator('#clearAllDataBtn').is_visible() + assert page.locator('#topicInput').input_value() == ''