Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut MaterializeServerExportMedia

From Leeroopedia
Knowledge Sources
Domains Video_Export, Media_Processing, Security
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete function that resolves every render-visible media reference in an export snapshot to a local, same-origin file path through SSRF-safe fetching, then freezes the snapshot for rendering.

Description

The materializeServerExportMedia function walks a timeline or project snapshot, finds all media references (local uploads, remote URLs, product assets), downloads remote ones through the SSRF-safe fetcher, validates local ones, and replaces all remote URLs with local paths in a deep-frozen copy of the snapshot.

Key behaviors:

  • Media plan collection: Uses `collectExportMediaPlan` to find all render-visible references.
  • Local reference validation: Checks local references exist and are safe.
  • Remote reference download: Downloads through `safePublicFetch` with byte and time bounds.
  • Atomic publishing: Downloaded files are atomically published to the upload directory.
  • Source replacement: All remote URLs in the snapshot are replaced with local `/media/uploads/` paths.
  • Snapshot freezing: The returned snapshot is deep-frozen (`Object.freeze`) so the renderer cannot mutate it.
  • Cleanup function: Returns a `cleanup()` to remove downloaded temp files.
  • Abort signal: Honors `options.signal` at every step.

Usage

  • Export submission: Called by `acceptExportSubmission` to materialize media before rendering.
  • Direct materialization: Can be called independently to pre-flight media for a render.

Code Reference

Source Location

  • Repository: OpenChatCut
  • File:*** server/plugins/export-media-plan.ts

Signature

export interface MaterializedServerExportMedia<Value> {
  readonly snapshot: Value;       // deep-frozen, same-origin paths
  readonly plan: ExportMediaPlan;
  readonly localPaths: readonly string[];
  cleanup(): Promise<void>;
}

export async function materializeServerExportMedia<Value>(
  snapshot: Value,
  options?: ServerExportMediaOptions,
): Promise<MaterializedServerExportMedia<Value>>;

export type ServerExportMediaOptions = {
  publicDirectory?: string;
  uploadDirectory?: string;
  fetcher?: typeof safePublicFetch;
  maxMaterializedBytes?: number;  // default 10 GB
  signal?: AbortSignal;
};

Import

import {
  materializeServerExportMedia,
  type ServerExportMediaOptions,
  type MaterializedServerExportMedia,
} from '../server/plugins/export-media-plan.ts';

I/O Contract

Inputs

Name Type Required Description
snapshot Value Yes Timeline state or project doc with media references
options.uploadDirectory string No Override upload directory
options.fetcher typeof safePublicFetch No Override SSRF-safe fetcher
options.maxMaterializedBytes number No Max total download bytes (default 10 GB)
options.signal AbortSignal No Abort signal for cancellation

Outputs

Name Type Description
snapshot Value Deep-frozen copy with all remote URLs replaced by local paths
plan ExportMediaPlan Media plan with all references and any issues
localPaths readonly string[] Local file paths created (for cleanup)
cleanup() Promise<void> Removes all downloaded temp files

Usage Examples

Materialize a Timeline

import { materializeServerExportMedia } from '../server/plugins/export-media-plan.ts';

const result = await materializeServerExportMedia(timelineState, {
  signal: controller.signal,
});

console.log(`Materialized ${result.localPaths.length} files`);
// result.snapshot is frozen — safe to pass to renderer
await renderTimeline({ state: result.snapshot, outputLocation: 'out.mp4' });
// Clean up
await result.cleanup();

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment