Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Import image and video batches from History and collections (#12158)
[._.]/15b8a77980f1
diff --git a/client/src/components/media/MediaBatchImport.jsx b/client/src/components/media/MediaBatchImport.jsxnew file mode 100644index 0000000000..41f1cb061b--- /dev/null+++ b/client/src/components/media/MediaBatchImport.jsx@@ -0,0 +1,91 @@+import { useEffect, useRef, useState } from 'react';+import { Upload } from 'lucide-react';+import FilePickerButton from '../ui/FilePickerButton';+import { importGalleryFile, assignImportedMedia } from '../../services/apiMedia';+import { formatCount } from '../../utils/formatters';+import useMounted from '../../hooks/useMounted';++const ACCEPT = 'image/png,image/jpeg,image/gif,image/webp,video/mp4,video/quicktime,video/webm,.png,.jpg,.jpeg,.gif,.webp,.mp4,.m4v,.mov,.webm,.mkv';++export default function MediaBatchImport({ collectionId, onImported }) {+ const [rows, setRows] = useState([]);+ const [busy, setBusy] = useState(false);+ const [stopping, setStopping] = useState(false);+ const running = useRef(false);+ const cancelled = useRef(false);+ const mounted = useMounted();+ const importedCallback = useRef(onImported);+ useEffect(() => { importedCallback.current = onImported; }, [onImported]);+ useEffect(() => () => { cancelled.current = true; }, []);++ const run = async (batch) => {+ if (running.current) return;+ running.current = true;+ cancelled.current = false;+ setBusy(true);+ setStopping(false);+ const publish = () => { if (mounted.current) setRows(batch.map(row => ({ ...row }))); };+ for (const row of batch) {+ if (row.status === 'done') continue;+ if (cancelled.current) { row.status = 'cancelled'; continue; }+ row.error = null;+ row.status = row.saved ? 'assigning' : 'uploading';+ publish();+ // Finish the current request so cancellation never misreports a durable+ // import as aborted. The saved reference survives assignment retries.+ const imported = row.saved || await importGalleryFile(row.file, { silent: true }).catch(error => {+ row.error = `${error.message || 'Upload failed.'} If the connection was lost, check History before retrying.`;+ return null;+ });+ if (!imported) { row.status = 'failed'; publish(); continue; }+ row.saved = imported;+ let collection;+ if (collectionId) {+ row.status = 'assigning';+ publish();+ const assigned = await assignImportedMedia(collectionId, imported, { silent: true }).catch(error => {+ row.error = `Imported to History; collection assignment failed: ${error.message}. Retry will only assign the existing import.`;+ return null;+ });+ if (!assigned) { row.status = 'failed'; publish(); continue; }+ collection = assigned.collection;+ }+ row.status = 'done';+ publish();+ if (mounted.current) importedCallback.current?.(imported, collection);+ }+ publish();+ running.current = false;+ if (mounted.current) { setBusy(false); setStopping(false); }+ };++ const completed = rows.filter(row => row.status === 'done').length;+ const retryable = rows.some(row => ['failed', 'cancelled'].includes(row.status));+ return (+ <section aria-label="Import media" className="min-w-0 space-y-2">+ <div className="flex flex-wrap items-center gap-2">+ <FilePickerButton multiple accept={ACCEPT} disabled={busy}+ onChange={event => run(Array.from(event.target.files || []).map(file => ({ file, status: 'queued' })))}+ className="inline-flex min-h-[44px] items-center gap-2 rounded border border-port-border px-3 text-sm text-port-accent hover:bg-port-border/50">+ <Upload className="h-4 w-4" aria-hidden="true" /> Upload / import+ </FilePickerButton>+ <span className="text-xs text-gray-400">Images and videos · embedded prompts checked{collectionId ? ' · added to this collection' : ''}</span>+ {busy && <button type="button" disabled={stopping} className="min-h-[44px] px-3 text-sm text-port-accent disabled:opacity-50"+ onClick={() => { cancelled.current = true; setStopping(true); }}>+ {stopping ? 'Finishing current file…' : 'Cancel remaining'}+ </button>}+ {!busy && retryable && <button type="button" onClick={() => run(rows)} className="min-h-[44px] px-3 text-sm text-port-accent">Retry failed / cancelled</button>}+ </div>+ {rows.length > 0 && <>+ <p role="status" className="text-xs text-gray-400">{formatCount(completed)} of {formatCount(rows.length)} imported{busy ? ' — working…' : ''}</p>+ <ul className="max-h-56 overflow-y-auto space-y-1 text-xs" aria-label="Import results">+ {rows.map((row, index) => <li key={index} className="break-words rounded border border-port-border px-2 py-1">+ <span className="font-medium">{row.file.name}</span>: {row.status === 'done' ? 'Imported' : row.status}+ {row.status === 'done' && <span> — {row.saved.data.importWarnings?.length ? row.saved.data.importWarnings.join(' ') : row.saved.data.prompt ? 'Embedded prompt imported' : 'No supported embedded prompt found'}</span>}+ {row.error && <p role="alert" className="text-port-error">{row.error}</p>}+ </li>)}+ </ul>+ </>}+ </section>+ );+}diff --git a/client/src/components/media/MediaBatchImport.test.jsx b/client/src/components/media/MediaBatchImport.test.jsxnew file mode 100644index 0000000000..5f86df755b--- /dev/null+++ b/client/src/components/media/MediaBatchImport.test.jsx@@ -0,0 +1,98 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';+const { request } = vi.hoisted(() => ({ request: vi.fn() }));+vi.mock('../../services/apiCore.js', async importOriginal => ({ ...await importOriginal(), request }));+import MediaBatchImport from './MediaBatchImport';++const image = new File(['png'], 'portrait.png', { type: 'image/png' });+const video = new File(['mp4'], 'clip.mp4', { type: 'video/mp4' });+const pick = files => fireEvent.change(screen.getByLabelText('Upload / import'), { target: { files } });+const savedImage = { filename: 'upload-image.png', path: '/data/images/upload-image.png', metadata: { prompt: 'A paper boat', seed: 42 } };+const savedVideo = { id: 'upload-video', filename: 'upload-video.mp4', source: 'upload', prompt: 'Clouds' };+beforeEach(() => {+ request.mockReset();+ request.mockImplementation(async path => {+ if (path === '/image-gen/upload') return savedImage;+ if (path === '/video-gen/upload') return savedVideo;+ return { collection: { id: 'collection-a', items: [] } };+ });+});++describe('shared gallery batch import', () => {+ it('posts a mixed batch through the Prompt gallery endpoints and reports unsupported and failed files independently', async () => {+ const imported = vi.fn();+ request.mockRejectedValueOnce(new Error('Image decoder rejected the bytes'));+ render(<MediaBatchImport onImported={imported} />);+ pick([image, video, new File(['x'], 'unsafe.svg'), image]);+ await waitFor(() => expect(imported).toHaveBeenCalledTimes(2));+ expect(screen.getByText('2 of 4 imported')).toBeInTheDocument();+ expect(screen.getByText(/Unsupported type/)).toBeInTheDocument();+ expect(screen.getByText(/Image decoder rejected the bytes/)).toBeInTheDocument();+ expect(request.mock.calls.map(([path]) => path)).toEqual(['/image-gen/upload', '/video-gen/upload', '/image-gen/upload']);+ for (const [, options] of request.mock.calls) {+ expect(options.body).toBeInstanceOf(FormData);+ expect(options.silent).toBe(true);+ }+ expect(imported.mock.calls[1][0]).toMatchObject({ kind: 'image', ref: savedImage.filename, data: { prompt: 'A paper boat', seed: 42 } });+ });++ it('retries only assignment after an import succeeds, using the idempotent collection bulk endpoint', async () => {+ let failAssignment = true;+ request.mockImplementation(async path => {+ if (path === '/image-gen/upload') return savedImage;+ if (failAssignment) throw new Error('Collection temporarily unavailable');+ return { collection: { id: 'collection-a', items: [{ kind: 'image', ref: savedImage.filename }] } };+ });+ const imported = vi.fn();+ render(<MediaBatchImport collectionId="collection-a" onImported={imported} />);+ pick([image]);+ await screen.findByText(/Imported to History; collection assignment failed/);+ failAssignment = false;+ fireEvent.click(screen.getByRole('button', { name: 'Retry failed / cancelled' }));+ await screen.findByText('1 of 1 imported');+ expect(request.mock.calls.filter(([path]) => path === '/image-gen/upload')).toHaveLength(1);+ const assignments = request.mock.calls.filter(([path]) => path === '/media/collections/collection-a/items/bulk');+ expect(assignments).toHaveLength(2);+ expect(JSON.parse(assignments[1][1].body)).toEqual({ add: [{ kind: 'image', ref: savedImage.filename }] });+ expect(imported).toHaveBeenCalledTimes(1);+ });++ it('finishes the active file on cancellation and resumes only remaining files', async () => {+ let finish;+ request.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));+ render(<MediaBatchImport />);+ pick([image, video]);+ fireEvent.click(screen.getByRole('button', { name: 'Cancel remaining' }));+ await act(async () => finish(savedImage));+ expect(request).toHaveBeenCalledTimes(1);+ expect(screen.getByText('1 of 2 imported')).toBeInTheDocument();+ fireEvent.click(screen.getByRole('button', { name: 'Retry failed / cancelled' }));+ await screen.findByText('2 of 2 imported');+ expect(request).toHaveBeenCalledTimes(2);+ });++ it('stops queued work and drops callbacks when its collection is left during an upload', async () => {+ let finish;+ request.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));+ const imported = vi.fn();+ const view = render(<MediaBatchImport collectionId="old-collection" onImported={imported} />);+ pick([image, video]);+ view.unmount();+ await act(async () => finish(savedImage));+ expect(imported).not.toHaveBeenCalled();+ expect(request.mock.calls.map(([path]) => path)).toEqual(['/image-gen/upload', '/media/collections/old-collection/items/bulk']);+ });+});++it('uses the current view callback when filters change during upload', async () => {+ let finish;+ request.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));+ const oldView = vi.fn();+ const newView = vi.fn();+ const view = render(<MediaBatchImport onImported={oldView} />);+ pick([image]);+ view.rerender(<MediaBatchImport onImported={newView} />);+ await act(async () => finish(savedImage));+ expect(oldView).not.toHaveBeenCalled();+ expect(newView).toHaveBeenCalledTimes(1);+});diff --git a/client/src/components/media/PromptFromMedia.jsx b/client/src/components/media/PromptFromMedia.jsxindex 25a433bb84..a4b5abd922 100644--- a/client/src/components/media/PromptFromMedia.jsx+++ b/client/src/components/media/PromptFromMedia.jsx@@ -414,6 +414,7 @@ export default function PromptFromMedia({onSelect={(item) => { setSource(sourceFromItem(item)); setResult(null); }}/><GalleryVideoPicker+ uploadToGalleryopen={videoPickerOpen}onClose={() => setVideoPickerOpen(false)}allowUploaddiff --git a/client/src/pages/MediaCollectionDetail.jsx b/client/src/pages/MediaCollectionDetail.jsxindex 133deacdf1..1f5e3be355 100644--- a/client/src/pages/MediaCollectionDetail.jsx+++ b/client/src/pages/MediaCollectionDetail.jsx@@ -1,3 +1,4 @@+import MediaBatchImport from '../components/media/MediaBatchImport';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useParams, Link, useNavigate } from 'react-router';import { ArrowLeft, Cloud, CloudOff, CheckSquare, Copy, DatabaseZap, FolderInput, HardDriveDownload, Inbox, Lock, Pencil, Star, StarOff, Trash2, X } from 'lucide-react';@@ -475,6 +476,18 @@ export default function MediaCollectionDetail() {)}</div>+ <MediaBatchImport key={id} collectionId={isUnsorted ? undefined : id} onImported={(item, updated) => {+ // Mutation responses omit GET-only peer locations. Keep those for+ // existing members so remote-only thumbnails do not disappear.+ if (updated) setCollection(previous => ({ ...updated, items: updated.items.map(member => ({+ ...previous?.items.find(existing => existing.kind === member.kind && existing.ref === member.ref),+ ...member,+ ...(member.kind === item.kind && member.ref === item.ref ? { location: 'local' } : {}),+ })) }));+ page.setItems(previous => [item, ...previous.filter(row => !(row.kind === item.kind && row.data.filename === item.data.filename))]);+ page.refresh();+ }} />+{selectMode && (<div className="bg-port-card border border-port-border rounded-lg px-3 py-2 flex flex-wrap items-center gap-2 sticky top-0 z-30"><span className="text-xs text-gray-300">diff --git a/client/src/pages/MediaCollectionDetail.test.jsx b/client/src/pages/MediaCollectionDetail.test.jsxindex 22dd69a9d6..ba24f4cd6f 100644--- a/client/src/pages/MediaCollectionDetail.test.jsx+++ b/client/src/pages/MediaCollectionDetail.test.jsx@@ -1,5 +1,7 @@+const batchApi = vi.hoisted(() => ({ importGalleryFile: vi.fn(), assignImportedMedia: vi.fn() }));+vi.mock('../services/apiMedia', () => batchApi);import { describe, it, expect, vi, beforeEach } from 'vitest';-import { act, render, screen, waitFor } from '@testing-library/react';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter, Route, Routes } from 'react-router';@@ -497,3 +499,45 @@ describe('MediaCollectionDetail — bulkMoveOrCopy move/remove failures', () =>await waitFor(() => expect(mockLocalizeMediaCollection).toHaveBeenCalledWith(REAL_COLLECTION.id, ['image:hosted-on-peer.png'], { silent: true }));});});++it('uploads image and video files into the selected collection without replacing existing membership', async () => {+ let collection = { ...REAL_COLLECTION, items: [...REAL_COLLECTION.items] };+ const uploaded = [+ { kind: 'image', ref: 'new.png', data: { filename: 'new.png', prompt: 'Imported image' } },+ { kind: 'video', ref: 'new-video', data: { id: 'new-video', filename: 'new.mp4', prompt: 'Imported video' } },+ ];+ batchApi.importGalleryFile.mockReset().mockResolvedValueOnce(uploaded[0]).mockResolvedValueOnce(uploaded[1]);+ batchApi.assignImportedMedia.mockReset().mockImplementation(async (_id, item) => {+ collection = { ...collection, items: [...collection.items, { kind: item.kind, ref: item.ref }] };+ return { collection };+ });+ mockGetMediaCollection.mockImplementation(async () => collection);+ mockListImageGallery.mockResolvedValue([IMAGE_A, uploaded[0].data]);+ mockListVideoHistory.mockResolvedValue([uploaded[1].data]);+ renderReal();+ const input = await screen.findByLabelText('Upload / import');+ expect(input.multiple).toBe(true);+ fireEvent.change(input, { target: { files: [new File(['png'], 'new.png'), new File(['mp4'], 'new.mp4')] } });+ await screen.findByText('2 of 2 imported');+ expect(batchApi.assignImportedMedia.mock.calls.map(call => call[0])).toEqual(['col-real', 'col-real']);+ expect(collection.items).toEqual([REAL_COLLECTION.items[0], { kind: 'image', ref: 'new.png' }, { kind: 'video', ref: 'new-video' }]);+});++it('preserves peer-only image locations when assigning an uploaded file', async () => {+ const remote = { kind: 'image', ref: 'remote.png', location: 'remote', hostPeerId: 'peer-example', hostPeerName: 'Example Peer' };+ const imported = { kind: 'image', ref: 'local-upload.png', data: { filename: 'local-upload.png' } };+ mockGetMediaCollection.mockResolvedValue({ ...REAL_COLLECTION, items: [remote] });+ mockListImageGallery.mockResolvedValue([]);+ mockListVideoHistory.mockResolvedValue([]);+ batchApi.importGalleryFile.mockReset().mockResolvedValue(imported);+ batchApi.assignImportedMedia.mockReset().mockResolvedValue({ collection: { ...REAL_COLLECTION, items: [+ { kind: 'image', ref: remote.ref }, { kind: 'image', ref: imported.ref },+ ] } });+ renderReal();+ await screen.findByText('remote.png');+ fireEvent.change(screen.getByLabelText('Upload / import'), { target: { files: [new File(['png'], 'local-upload.png')] } });+ await screen.findByText('1 of 1 imported');+ expect(screen.getByText('remote.png')).toBeInTheDocument();+ expect(screen.getByTitle('Hosted by Example Peer — streamed on demand, not stored on this machine')).toBeInTheDocument();+ expect(screen.getByRole('button', { name: /Copy 1 to this machine/ })).toBeInTheDocument();+});diff --git a/client/src/pages/MediaHistory.jsx b/client/src/pages/MediaHistory.jsxindex a21b23b482..e8991bc852 100644--- a/client/src/pages/MediaHistory.jsx+++ b/client/src/pages/MediaHistory.jsx@@ -1,3 +1,4 @@+import MediaBatchImport from '../components/media/MediaBatchImport';import InfiniteScrollFooter from '../components/ui/InfiniteScrollFooter';/*** Media History — unified timeline of generated images + videos with filter@@ -208,6 +209,13 @@ export default function MediaHistory() {</div></div>+ <MediaBatchImport onImported={item => {+ if ((filter === 'all' || filter === item.kind) && !query && !favoritesOnly) {+ page.setItems(previous => [item, ...previous.filter(row => !(row.kind === item.kind && row.data.filename === item.data.filename))]);+ }+ refresh();+ }} />+{page.error && items.length === 0 && <p role="alert" className="text-port-error">{page.error} <button type="button" onClick={page.retry}>Retry</button></p>}{loading && items.length === 0 ? (<PageSkeleton header="none" label="Loading media history" layout="grid" cards={10} gridColsClass="grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5" />diff --git a/client/src/pages/MediaHistory.test.jsx b/client/src/pages/MediaHistory.test.jsxindex 5ec85ae411..90ac1986b5 100644--- a/client/src/pages/MediaHistory.test.jsx+++ b/client/src/pages/MediaHistory.test.jsx@@ -1,3 +1,5 @@+const batchApi = vi.hoisted(() => ({ importGalleryFile: vi.fn(), assignImportedMedia: vi.fn() }));+vi.mock('../services/apiMedia', () => batchApi);import { beforeEach, describe, expect, it, vi } from 'vitest';import { render, screen, fireEvent, waitFor } from '@testing-library/react';import { MemoryRouter } from 'react-router';@@ -121,3 +123,22 @@ describe('bounded media history', () => {expect(fetchPage).toHaveBeenCalledWith({ limit: 1, kind: 'image', filename: '60.png' }, { silent: true });});});++it('imports a mixed batch from History and inserts both returned records', async () => {+ batchApi.importGalleryFile.mockImplementation(async file => {+ const row = file.name.endsWith('.png')+ ? { kind: 'image', ref: 'new.png', data: { filename: 'new.png', prompt: 'Imported image prompt' } }+ : { kind: 'video', ref: 'new-video', data: { id: 'new-video', filename: 'new.mp4', prompt: 'Imported video prompt' } };+ rows.unshift(row);+ return row;+ });+ open();+ await screen.findByText('Picture 0');+ const input = screen.getByLabelText('Upload / import');+ expect(input.multiple).toBe(true);+ fireEvent.change(input, { target: { files: [new File(['png'], 'new.png'), new File(['mp4'], 'new.mp4')] } });+ await screen.findByText('2 of 2 imported');+ expect(await screen.findByText('Imported image prompt')).toBeInTheDocument();+ expect(await screen.findByText('Imported video prompt')).toBeInTheDocument();+ expect(batchApi.assignImportedMedia).not.toHaveBeenCalled();+});diff --git a/client/src/services/README.md b/client/src/services/README.mdindex 8a2cdcfdcc..0dac3912ba 100644--- a/client/src/services/README.md+++ b/client/src/services/README.md@@ -105,7 +105,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire|---|---|| `apiImageVideo.js` | Image-gen local backend extras; bounded image/mixed gallery pages, global facets and collection summaries, exact-reference `getGalleryImages`, one image's original-vs-cleaned variant set via `listImageVariants`, plus models, LoRAs, cancel and delete. || `apiLoraTraining.js` | Character LoRA training — datasets (CRUD, upload, generate, slice, caption), training runs (start/list/cancel + status), character→LoRA link lookup. |-| `apiMedia.js` | Screenshots + media assets. Also owns the multi-file upload orchestration — `processScreenshotUploads` / `processAttachmentUploads` — moved from `utils/fileUpload.js` since they perform network I/O, not pure transforms. `utils/fileUpload.js` keeps only the pure helpers/constants and no longer re-exports these. |+| `apiMedia.js` | `importGalleryFile` dispatches image/video imports through the Prompt gallery upload endpoints; `assignImportedMedia` adds existing imports through idempotent bulk membership. Screenshots + media assets. Also owns the multi-file upload orchestration — `processScreenshotUploads` / `processAttachmentUploads` — moved from `utils/fileUpload.js` since they perform network I/O, not pure transforms. `utils/fileUpload.js` keeps only the pure helpers/constants and no longer re-exports these. || `apiMediaJobs.js` | Media generation job tracking + `refineMediaPrompt` / `promptFromMedia` (vision reverse-prompt). || `apiDecks.js` | Decks (playing-card / tarot designer) — deck + card CRUD, sample-design style analysis, universe casting + prompt generation (plus its SSE progress URL), single/batch card renders. || `apiCreativeDirector.js` | Creative Director (video production). |diff --git a/client/src/services/apiMedia.js b/client/src/services/apiMedia.jsindex 75ee300e65..cb54670a7a 100644--- a/client/src/services/apiMedia.js+++ b/client/src/services/apiMedia.js@@ -1,3 +1,5 @@+import { uploadGalleryImage } from './apiSystem.js';+import { uploadGalleryVideo } from './apiImageVideo.js';import { uploadBody, request, API_BASE, throwApiError } from './apiCore.js';import { formatBytes } from '../utils/formatters.js';import {@@ -364,3 +366,23 @@ export const fetchCleanResult = async (jobId) => {// page's own useAsyncAction/catch owns the error toast.export const saveCleanResult = (jobId, options = {}) =>request(`/image-clean/result/${encodeURIComponent(jobId)}/save`, { method: 'POST', ...options });++// Reuse the same upload endpoints as the Prompt page's gallery pickers.+export async function importGalleryFile(file, options = {}) {+ const extension = file.name.split('.').pop().toLowerCase();+ if (!file.size) throw new Error('The file is empty.');+ if (['png', 'jpg', 'jpeg', 'webp', 'gif'].includes(extension)) {+ const saved = await uploadGalleryImage(file, options);+ return { kind: 'image', data: { ...saved, ...saved.metadata }, ref: saved.filename };+ }+ if (['mp4', 'm4v', 'mov', 'webm', 'mkv'].includes(extension)) {+ const saved = await uploadGalleryVideo(file, file.name, options);+ return { kind: 'video', data: saved, ref: saved.id };+ }+ throw new Error('Unsupported type. Use PNG, JPEG, GIF, WebP, MP4, MOV, M4V, WebM, or MKV.');+}++export const assignImportedMedia = (collectionId, item, options = {}) => request(+ `/media/collections/${encodeURIComponent(collectionId)}/items/bulk`, {+ method: 'POST', body: JSON.stringify({ add: [{ kind: item.kind, ref: item.ref }] }), ...options,+ });diff --git a/server/lib/README.md b/server/lib/README.mdindex 17d6694c16..79ed2c4e19 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -401,7 +401,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `imageRgba.js` | Sharp-backed RGBA boundary: `decodeRgbaFrame` decodes an image to `{ data, width, height }`, and `encodePng` turns a raw frame into PNG bytes for the caller's destination/hash policy. || `imageWatermark.js` | `removeCornerWatermark` (erases the visible Gemini/Nano-Banana bottom-right ✦ via dependency-free harmonic/Laplace inpaint) + pure helpers `resolveWatermarkRegion` / `inpaintRegion`. Distinct from SynthID regen — this targets the *visible* corner logo. || `localImageFilename.js` | `localImageFilename(urlOrPath)` resolves a stored image reference to the bare gallery-image filename under `data/images/` (or null for empty/external-URL/non-image-path) — the unit the peer-sync asset pipeline hashes + transfers. Single source of truth for the authors/artists/albums/Creative-Director filename resolvers (`headshotImageFilename`/`portraitImageFilename`/`coverImageFilename`/`startingImageFilename` are thin wrappers). Also exports `assetBasename(pathOrName)`, the shared strip-querystring→basename primitive (reused by moodBoard's `imageUrlToAppAsset`). |-| `pngMetadata.js` | `extractPngGenerationMetadataFile` seeks past pixel data for bounded disk-file metadata extraction. Bounded PNG `tEXt`/`zTXt`/`iTXt` extraction for Stable Diffusion-compatible provenance plus normalization of prompt, negative prompt, sampler, steps, CFG, seed, size, model, and model hash fields; `GENERATION_METADATA_LIMITS` shares the projection bounds with catalog sync validation. Pure. |+| `pngMetadata.js` | `extractGenerationMetadataEntries` shares the bounded projection between PNG text chunks and video container tags. `extractPngGenerationMetadataFile` seeks past pixel data for bounded disk-file metadata extraction. Bounded PNG `tEXt`/`zTXt`/`iTXt` extraction for Stable Diffusion-compatible provenance plus normalization of prompt, negative prompt, sampler, steps, CFG, seed, size, model, and model hash fields; `GENERATION_METADATA_LIMITS` shares the projection bounds with catalog sync validation. Pure. || `threejsModel.js` | Validated declarative procedural-model schema plus deterministic standalone Three.js factory export for the Three.js Models workspace. Also the cross-section gate: `evaluateThreejsFlatness(spec)` counts distinct vertex planes per axis — relative to the mesh's own size, with a rotation-invariant zero-volume check behind it — and treats an `extrude` with no bevel thickness as the two-plane slab it is to report when the majority of identity-priority features are built only from flat parts — a model that reads right head-on and like cardboard when orbited. `buildThreejsFlatnessFeedback(flatness)` turns that into default refinement feedback; `listSpecNames(names)` is the shared capped name-list formatter both gates use in finding messages. Also the material-plausibility gate: `evaluateThreejsMaterialPlausibility(spec)` keys a bounded per-family prior table (metal, wood, plastic, glass, fabric, ceramic, rubber, stone, leather, paper) off tokens in each material's id and reports channels whose values the named substance does not support — metalness 0.9 oak, transmission 1.0 steel — skipping any id that names no family or two, and any channel the material's `type` never forwards to Three.js. Advisory only: it never clamps, because a stylized model may legitimately break every prior. `buildThreejsMaterialFeedback(plausibility)` turns that into default refinement feedback. The same pass emits a `reflective-material-without-environment` note when a spec authors reflective channels (metalness above 0.6, or any transmission/clearcoat/iridescence) while `environment.preset` is `none` — those channels read off an environment, so in that scene their values cannot be judged at all. Attachments are declared in two forms — the original anchor-less `attachmentPartIds` and the anchored `attachments: [{ partId, anchorPartId | anchorSocket, maxOffset }]` — and `resolveThreejsAttachments(articulation)` merges them into one canonical list (an anchored entry wins over a bare id) so every gate reads the same set; `isThreejsAttachmentAnchored(attachment)` is the shared anchored/unanchored predicate and `DEFAULT_ATTACHMENT_MAX_OFFSET` the default tolerance. The spec-level refinement rejects an anchor that does not resolve, one that is the attachment itself, an anchor chain that cycles, and the model root (the sole top-level part) — which carries no relationship to any body part. The spec carries an optional `environment` block (see `threejsModelEnvironment.js`), and `buildThreejsFactorySource()` stamps its render profile onto `root.userData.sculptRuntime.render` and exports it as `renderProfile`, so a consumer wiring their own `WebGLRenderer` reproduces the model instead of a differently tone-mapped approximation. || `threejsModelAnimation.js` | `summarizeThreejsAnimation(spec)` — clip inventory *and* playback gate over an already-validated Three.js spec: `{ animated, clipCount, cueCount, sequenceCount, movingPartCount, longestClipSeconds, findings, warningCount, clips }`. The schema proves a declared `animation` block is well *formed* (sequences on real parts, inside their clip, never two on one channel at once, never a cue without motion); this reports what the model *declared* — one entry per clip with its role, duration, sequence and distinct-cue counts — plus the ways a well-formed clip still plays badly: a clip authored against a pose the assembly does not build (`clip-start-pose-mismatch`), a handover between sequences that do not meet (`clip-sequence-jump`), a `loop: true` clip that does not return to where it began, a one-shot `idle`, an unfired cue, a long dead tail, and an articulation graph with no clip at all. Advisory warnings only — a static assembly is a complete answer. `buildThreejsAnimationFeedback(animation)` turns those findings into default refinement feedback. A spec with no `animation` key summarizes as not animated — never as evaluated-and-empty. || `threejsModelCoverage.js` | `evaluateThreejsPartCoverage(spec, { family })` — structural assembly gate over an already-validated Three.js spec: flags promised features fused onto the same part set, geometry claimed by no detail, and details nothing was built for (folded minor relief stays a `note`). With a subject family it also warns on a required component the spec never mentions at all — the one check that can fault a spec for what it failed to *promise*. `buildThreejsCoverageFeedback(coverage)` turns the error findings (plus any family gap) into default refinement feedback. |@@ -443,7 +443,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `upgradeFallback.js` | `installUpgradeFallback(server, options)` bounds the lifetime of unclaimed HTTP upgrade requests (ending and destroying them after `timeoutMs`, default 1000ms) to replace engine.io's `destroyUpgrade` timer so reverse proxies with slow upstreams (e.g. Eidoverse `/ws`) can complete handshakes without being cut short (#12069). Exempts claimed upgrades (`socket.portosUpgradeClaimed = true` via `markUpgradeClaimed(socket)`) and requests matching Engine.IO's listener on the server. || `httpCompression.js` | `httpCompression` negotiates Brotli/gzip for API and static responses while preserving streaming, ranges, existing encodings, and `no-transform`. || `execGit.js` | `execGit(args, cwd, options)` and `execGitSafe(args, cwd, options)` shared process boundary for Git operations, worktrees, and `services/forgeAuth.js` credential resolution. The safe variant converts rejections into `{ exitCode: 1, stdout: '', stderr }`; `services/git.js` re-exports both for compatibility. `cwd` is REQUIRED — it rejects on a missing/blank one rather than letting `spawn` fall back to `process.cwd()` and run git against PortOS's own checkout (#4554). |-| `ffmpeg.js` | Shared ffmpeg helpers (videoGen + videoTimeline). `vfrSyncArgs(bin)` probes/caches supported VFR output flags per binary (fps_mode on current builds, vsync on older builds); inconclusive probes stay uncached. `probeVideoGeometry(videoPath)` measures a finished clip's `{ width, height, fps, numFrames, durationSec }` (null when any axis is unreadable) for hosted renders that record no frame count. `generateThumbnail(videoPath, jobId, { atSec } = {})` accepts a clamped poster seek while preserving the single-clip default. Includes `probeFrameCount(videoPath)` (metadata `nb_frames`, falling back to a real `-count_frames` pass — expensive, so call it once per file) and `trimVideoFromFrame(videoPath, outPath, {startFrame, fps})` — a frame-EXACT head cut via the `trim` filter (an `-ss` seek can drift a frame, which reads as a stutter at a stitch seam), keeping audio in sync with `atrim` when the clip has a soundtrack and taking `-an` when it doesn't. Re-encodes by necessity, so a later concat must re-encode too; `outPath` may equal the input (temp-file + rename install). Used by the chained-render context window — see `videoContinuity.js`. `buildTrimConcatArgs({inputs, outPath, width, height, fps, withAudio})` builds the argv for the other half of that job: a concat that drops leading frames from some of its inputs inside a `filter_complex` graph, so the cuts ride along with the timeline encode instead of costing one pre-encode per clip (pass `withAudio` only when EVERY input has an audio stream — check with `hasAudioStream`). `buildExtendSpliceArgs({sourcePath, generatedPath, outPath, keepFrames, newStartFrame, width, height, fps, audio, sourceAudioPath, masterOutPath})` is the plain-Extend counterpart: source frames `[0, keep)` + render frames from `newStartFrame`, one encode, audio crossfaded (~40 ms linear) at the seam; `sourceAudioPath` swaps the source span's audio for a lossless master and `masterOutPath` also writes the mix as a 24-bit FLAC master, so the delivered AAC is encoded once from PCM. Its stream-copy sibling is `buildExtendNewSpanArgs` (encode only the render's new span) + `buildExtendConcatList` + `buildExtendCopyArgs` (join it to the untouched source with `-c:v copy`); `probeVideoCodecSignature` gates it and `videoFrameHashes` (per-frame MD5) proves the join before anything is replaced; `audioFingerprint` / `sealAudioMaster` / `readAudioMasterFingerprint` bind a master to the exact decoded soundtrack it was mixed for so a replaced soundtrack invalidates it — driven by `services/videoGen/extendSplice.js`. `H264_ENCODE_ARGS` / `AAC_ENCODE_ARGS` are the shared encode profile: clips produced by different paths here get concatenated together, so a mismatch shows up as one segment graded differently from its neighbours — spread these rather than re-typing the flags. Every re-encode here also pins BT.709: `BT709_CONTAINER_ARGS` (the `colr` atom, always emitted) plus `bt709TagFilter()` → the `BT709_TAG_FILTER` `setparams=…` string, or `null` on an ffmpeg without that filter (`supportsSetparamsFilter()` probes `-filters` once per process; `null` = not probed, and a probe that couldn't run stays uncached). Both halves are required — from ffmpeg 8 the encoder reads color properties off the FRAMES, silently overriding the container flags, so a flags-only output decodes washed-out. `buildTrimConcatArgs` takes the filter as its `colorTagFilter` option rather than probing, to stay pure. `installEncodedVideo(tmpPath, targetPath, label)` is the shared in-place install: move the original aside to a `.bak` on Windows (where `fs.rename` refuses an existing destination), rename the new file over it, and restore the backup — plus unlink the temp — on any failure, returning `{ok:true,outPath}` / `{ok:false,reason}` so the worst case is "skipped", never "the video is gone". Use it for EVERY replace-a-video-with-its-re-encode path; `pipeline/audioMux.js` is the out-of-module caller. `edgeFadeFilter(durationSec)` is the `-af` fade-in/fade-out fragment a mid-song clip (a social cut) appends to its trim. Loudness mastering (#10249): `MASTER_LOUDNESS` (-14 LUFS / -1.5 dBTP / LRA 11), `planLoudnessMaster` (measure then build the linear apply filter; throws on a silent source), `reportMasteredLoudness` (post-encode before/after numbers). |+| `ffmpeg.js` | `probeMediaTags` reads container/stream tags, returning null when inspection fails. Shared ffmpeg helpers (videoGen + videoTimeline). `vfrSyncArgs(bin)` probes/caches supported VFR output flags per binary (fps_mode on current builds, vsync on older builds); inconclusive probes stay uncached. `probeVideoGeometry(videoPath)` measures a finished clip's `{ width, height, fps, numFrames, durationSec }` (null when any axis is unreadable) for hosted renders that record no frame count. `generateThumbnail(videoPath, jobId, { atSec } = {})` accepts a clamped poster seek while preserving the single-clip default. Includes `probeFrameCount(videoPath)` (metadata `nb_frames`, falling back to a real `-count_frames` pass — expensive, so call it once per file) and `trimVideoFromFrame(videoPath, outPath, {startFrame, fps})` — a frame-EXACT head cut via the `trim` filter (an `-ss` seek can drift a frame, which reads as a stutter at a stitch seam), keeping audio in sync with `atrim` when the clip has a soundtrack and taking `-an` when it doesn't. Re-encodes by necessity, so a later concat must re-encode too; `outPath` may equal the input (temp-file + rename install). Used by the chained-render context window — see `videoContinuity.js`. `buildTrimConcatArgs({inputs, outPath, width, height, fps, withAudio})` builds the argv for the other half of that job: a concat that drops leading frames from some of its inputs inside a `filter_complex` graph, so the cuts ride along with the timeline encode instead of costing one pre-encode per clip (pass `withAudio` only when EVERY input has an audio stream — check with `hasAudioStream`). `buildExtendSpliceArgs({sourcePath, generatedPath, outPath, keepFrames, newStartFrame, width, height, fps, audio, sourceAudioPath, masterOutPath})` is the plain-Extend counterpart: source frames `[0, keep)` + render frames from `newStartFrame`, one encode, audio crossfaded (~40 ms linear) at the seam; `sourceAudioPath` swaps the source span's audio for a lossless master and `masterOutPath` also writes the mix as a 24-bit FLAC master, so the delivered AAC is encoded once from PCM. Its stream-copy sibling is `buildExtendNewSpanArgs` (encode only the render's new span) + `buildExtendConcatList` + `buildExtendCopyArgs` (join it to the untouched source with `-c:v copy`); `probeVideoCodecSignature` gates it and `videoFrameHashes` (per-frame MD5) proves the join before anything is replaced; `audioFingerprint` / `sealAudioMaster` / `readAudioMasterFingerprint` bind a master to the exact decoded soundtrack it was mixed for so a replaced soundtrack invalidates it — driven by `services/videoGen/extendSplice.js`. `H264_ENCODE_ARGS` / `AAC_ENCODE_ARGS` are the shared encode profile: clips produced by different paths here get concatenated together, so a mismatch shows up as one segment graded differently from its neighbours — spread these rather than re-typing the flags. Every re-encode here also pins BT.709: `BT709_CONTAINER_ARGS` (the `colr` atom, always emitted) plus `bt709TagFilter()` → the `BT709_TAG_FILTER` `setparams=…` string, or `null` on an ffmpeg without that filter (`supportsSetparamsFilter()` probes `-filters` once per process; `null` = not probed, and a probe that couldn't run stays uncached). Both halves are required — from ffmpeg 8 the encoder reads color properties off the FRAMES, silently overriding the container flags, so a flags-only output decodes washed-out. `buildTrimConcatArgs` takes the filter as its `colorTagFilter` option rather than probing, to stay pure. `installEncodedVideo(tmpPath, targetPath, label)` is the shared in-place install: move the original aside to a `.bak` on Windows (where `fs.rename` refuses an existing destination), rename the new file over it, and restore the backup — plus unlink the temp — on any failure, returning `{ok:true,outPath}` / `{ok:false,reason}` so the worst case is "skipped", never "the video is gone". Use it for EVERY replace-a-video-with-its-re-encode path; `pipeline/audioMux.js` is the out-of-module caller. `edgeFadeFilter(durationSec)` is the `-af` fade-in/fade-out fragment a mid-song clip (a social cut) appends to its trim. Loudness mastering (#10249): `MASTER_LOUDNESS` (-14 LUFS / -1.5 dBTP / LRA 11), `planLoudnessMaster` (measure then build the linear apply filter; throws on a silent source), `reportMasteredLoudness` (post-encode before/after numbers). || `ffmpegFilterGraph.js` | `filterGraphViaFile(bin, args, path)` moves a `-filter_complex` graph over `FILTER_GRAPH_ARG_LIMIT` into a file (`-/filter_complex`, or `-filter_complex_script` before ffmpeg 7), since Linux and Windows cap argument length. Used by the music video render and excerpt encodes. || `forgeAccessErrors.js` | `isForgeNoAccessError(err)` / `isForgeNoAccessMessage(text)` / `logForgeNoAccessOnce(scope, repoSpec, detail)` / `forgeNoAccessRemedy(repoSpec)` — tells a PERMANENT `gh` no-access 404 (`Could not resolve to a Repository`, `HTTP 404`) apart from a transient blip. `execGh` stamps `ghNoAccess` on the rejection and keeps it OUT of the consecutive-failure backoff (which caps at 15 min and then re-fires forever), and the polling jobs (`branchReconcile`, `prWatcher`) narrate it exactly once per scope+repo per process with a remedy line instead of once per tick. `__resetForgeNoAccessLog()` is the test seam. || `forkHead.js` | `normalizeForkHead(value)` / `forkRemoteName(ownerLogin)` / `resolveTaskForkHead(metadata)` — the validated `{remoteUrl, ownerLogin}` address of a cross-repository PR's head branch, which has no `origin/<branch>` to attach to. Fail-closed: anything that isn't a usable pair (or that starts with `-`, which git would read as an option) is `null`, so every caller falls back to origin-only behavior instead of guessing. `forkRemoteName` is the deterministic `fork-<owner>` remote name that makes a re-attach reuse the remote it already added. Shared by `appPullRequests.js` (produces), `agentWorktreeCleanup.js`/`prRemediationFollowUp.js` (persist in task metadata), `agentWorkspacePrep.js` (threads), and `worktreeManager.js` (consumes — it has no forge client of its own). `resolveTaskForkHead` is the single reader of the generic `forkHead` task-metadata key, the fork-side counterpart to `taskTargetBranch.js`. |diff --git a/server/lib/ffmpeg.js b/server/lib/ffmpeg.jsindex 22f6b24141..d234c902e3 100644--- a/server/lib/ffmpeg.js+++ b/server/lib/ffmpeg.js@@ -1126,3 +1126,17 @@ export const optimizeForStreaming = async (videoPath) => {const installed = await installEncodedVideo(tmpPath, videoPath, 'streaming-optimized');if (!installed.ok) console.log(`⚠️ ${installed.reason} (at ${videoPath})`);};++// null means inspection failed; {} means the file was inspected and had no tags.+export async function probeMediaTags(mediaPath) {+ const stdout = await runFfprobe([+ '-v', 'error', '-show_entries', 'format_tags:stream_tags', '-of', 'json', mediaPath,+ ]);+ if (!stdout) return null;+ try {+ const result = JSON.parse(stdout);+ return Object.assign({}, ...(result.streams || []).map(stream => stream.tags || {}), result.format?.tags || {});+ } catch {+ return null;+ }+}diff --git a/server/lib/ffmpeg.test.js b/server/lib/ffmpeg.test.jsindex 5dbaa39d1c..242d2121d5 100644--- a/server/lib/ffmpeg.test.js+++ b/server/lib/ffmpeg.test.js@@ -6,7 +6,7 @@ import { join, resolve } from 'path';import {verifyVideoPlayable, safeUnder, runFfmpegProcess, hasAudioStream, buildTrimConcatArgs,- probeVideoStreamInfo, findFfmpeg, installEncodedVideo,+ probeVideoStreamInfo, findFfmpeg, installEncodedVideo, probeMediaTags,BT709_TAG_FILTER, BT709_CONTAINER_ARGS, bt709TagFilter, supportsSetparamsFilter, __resetSetparamsProbe,} from './ffmpeg.js';@@ -85,11 +85,12 @@ describe('probeVideoStreamInfo', () => {const clip = join(tmpDir, 'probe.mp4');const made = await runFfmpegProcess({bin: ffmpeg,- args: ['-f', 'lavfi', '-i', 'testsrc=size=96x64:rate=10:duration=1', '-pix_fmt', 'yuv420p', '-y', clip],+ args: ['-f', 'lavfi', '-i', 'testsrc=size=96x64:rate=10:duration=1', '-pix_fmt', 'yuv420p', '-metadata', 'comment={"prompt":"Paper boat","seed":42}', '-y', clip],stderrTailBytes: 0,});if (!made.ok) return;const info = await probeVideoStreamInfo(clip);+ expect(await probeMediaTags(clip)).toMatchObject({ comment: '{"prompt":"Paper boat","seed":42}' });expect(info.width).toBe(96);expect(info.height).toBe(64);expect(info.fps).toBeCloseTo(10, 5);diff --git a/server/lib/pngMetadata.js b/server/lib/pngMetadata.jsindex 64d4b5ddb4..e2297bc900 100644--- a/server/lib/pngMetadata.js+++ b/server/lib/pngMetadata.js@@ -273,15 +273,25 @@ export function parseStableDiffusionParameters(value) {* remains usable; sharp remains the authoritative image-format validator.*/export function extractPngGenerationMetadata(value) {+ return extractGenerationMetadataEntries(readTextChunks(value));+}++// Container adapters supply bounded text entries; projection and field policy+// stay identical for PNG uploads and video tags.+export function extractGenerationMetadataEntries(entries) {const result = {};- for (const chunk of readTextChunks(value)) {+ for (const chunk of entries) {+ if (typeof chunk.keyword !== 'string' || typeof chunk.text !== 'string' || chunk.text.length > MAX_TEXT_BYTES) continue;const key = chunk.keyword.toLowerCase();let candidate = {};if (key === 'parameters') {candidate = parseStableDiffusionParameters(chunk.text);- } else if (METADATA_KEYS.has(key)) {+ } else if (METADATA_KEYS.has(key) || key === 'comment' || key === 'description') {const json = parseJsonObject(chunk.text);- candidate = json ? normalizeGenerationMetadata(json) : normalizeGenerationMetadata({ [key]: chunk.text });+ candidate = json ? normalizeGenerationMetadata(json)+ : /^(comment|description)$/.test(key) && /(?:^|\n)Steps:\s*\d+/i.test(chunk.text)+ ? parseStableDiffusionParameters(chunk.text)+ : normalizeGenerationMetadata({ [key]: chunk.text });}for (const [field, fieldValue] of Object.entries(candidate)) {if (result[field] === undefined || result[field] === null || result[field] === '') result[field] = fieldValue;diff --git a/server/services/videoUpload.js b/server/services/videoUpload.jsindex 762c70563e..248a469d3a 100644--- a/server/services/videoUpload.js+++ b/server/services/videoUpload.js@@ -25,7 +25,8 @@ import { randomUUID } from 'crypto';import { ServerError } from '../lib/errorHandler.js';import { PATHS, ensureDir, atomicWrite, unlinkGuarded, copyFileGuarded } from '../lib/fileUtils.js';import { MAX_BASE64_UPLOAD_BYTES } from '../lib/uploadLimits.js';-import { generateThumbnail, probeVideoDuration } from '../lib/ffmpeg.js';+import { generateThumbnail, probeVideoDuration, probeMediaTags } from '../lib/ffmpeg.js';+import { extractGenerationMetadataEntries } from '../lib/pngMetadata.js';import { mutateVideoHistory } from './videoGen/history.js';import { videoGenEvents } from './videoGen/events.js';import { withBackupAssetPublication } from '../lib/backupSnapshotBoundary.js';@@ -112,15 +113,23 @@ async function persistGalleryVideo(header, originalName, size, write) {await write(outPath);// Both best-effort: a missing ffmpeg/ffprobe degrades to a thumbnail-less// entry (normalizeVideo renders a no-preview tile), never a failed upload.- const [thumbnail, durationSec] = await Promise.all([+ const [thumbnail, durationSec, tags] = await Promise.all([generateThumbnail(outPath, id).catch(() => null),probeVideoDuration(outPath).catch(() => null),+ probeMediaTags(outPath).catch(() => null),]);if (!thumbnail) await unlinkGuarded(join(PATHS.videoThumbnails, `${id}.jpg`)).catch(() => {});const title = typeof originalName === 'string' && originalName.trim()? originalName.trim().slice(0, 200): '';- const entry = buildUploadHistoryEntry({ id, filename, thumbnail, durationSec, title });+ const metadata = extractGenerationMetadataEntries(Object.entries(tags || {}).map(([keyword, text]) => ({ keyword, text })));+ const entry = {+ ...buildUploadHistoryEntry({ id, filename, thumbnail, durationSec, title }),+ ...metadata,+ ...(metadata.model ? { modelId: metadata.model } : {}),+ ...(metadata.cfgScale != null ? { guidanceScale: metadata.cfgScale } : {}),+ ...(tags === null ? { importWarnings: ['Embedded prompt metadata could not be inspected (ffprobe unavailable or invalid media).'] } : {}),+ };await mutateVideoHistory((history) => { history.unshift(entry); return history; });return entry;} catch (err) {diff --git a/server/services/videoUpload.test.js b/server/services/videoUpload.test.jsindex 35119aa977..a9033d4981 100644--- a/server/services/videoUpload.test.js+++ b/server/services/videoUpload.test.js@@ -23,7 +23,7 @@ vi.mock('../lib/fileUtils.js', async (original) => {const actual = await original();return { ...actual, PATHS: { ...actual.PATHS, get videos() { return uploadState.root; } } };});-vi.mock('../lib/ffmpeg.js', () => ({ generateThumbnail: vi.fn(async () => null), probeVideoDuration: vi.fn(async () => 2) }));+vi.mock('../lib/ffmpeg.js', () => ({ generateThumbnail: vi.fn(async () => null), probeVideoDuration: vi.fn(async () => 2), probeMediaTags: vi.fn(async () => ({})) }));vi.mock('./videoGen/history.js', () => ({ mutateVideoHistory: vi.fn(async (mutate) => {if (uploadState.fail) throw new Error('history write failed');uploadState.history = mutate(uploadState.history);@@ -104,3 +104,20 @@ it('imports a large staged video without the JSON ceiling and removes failed impexpect(readdirSync(uploadState.root).sort()).toEqual(before);expect(existsSync(tempPath)).toBe(true);});++ it('projects embedded video tags with the PNG import parser and preserves original bytes', async () => {+ uploadState.fail = false;+ const { probeMediaTags } = await import('../lib/ffmpeg.js');+ const parameters = 'Paper boat\nNegative prompt: text\nSteps: 20, Seed: 42, Size: 512x512, CFG scale: 7, Model: example-model';+ probeMediaTags.mockResolvedValueOnce({ comment: parameters, title: 'must not become a prompt' });+ const bytes = ftyp('isom');+ const entry = await saveUploadedGalleryVideoBuffer(bytes, '../../universe-character.mp4');+ expect(entry).toMatchObject({ prompt: 'Paper boat', negativePrompt: 'text', seed: 42, source: 'upload', modelId: 'example-model', guidanceScale: 7 });+ expect(entry.universeId).toBeUndefined();+ expect(uploadState.history[0]).toEqual(entry);+ expect(readFileSync(join(uploadState.root, entry.filename))).toEqual(bytes);+ probeMediaTags.mockResolvedValueOnce({ metadata: '{invalid JSON', title: 'Do not infer this' });+ expect(await saveUploadedGalleryVideoBuffer(bytes)).not.toHaveProperty('prompt');+ probeMediaTags.mockResolvedValueOnce(null);+ expect(await saveUploadedGalleryVideoBuffer(bytes)).toMatchObject({ importWarnings: [expect.stringContaining('could not be inspected')] });+ });