Implementation:0xsline OpenChatCut ImportLocalMedia
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Media_Import, Pipeline, Media_Processing |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete function that imports a local media file by verifying it is a regular file, computing a content hash (skipped for large files), and registering a reference manifest without copying the file.
Description
The importLocalMedia function is the core of the media import pipeline. It:
- Verifies the source: Checks via `stat` that the source path is a regular file.
- Assigns a stored name: Generates a UUID-based filename with the original extension.
- Computes content hash: Calls `sha256File` for files under 1.5 GB; returns empty string for larger files.
- Validates the hash: Normalizes via `normalizeSha256Hash`; throws if the hash is invalid (not empty and not a valid SHA-256).
- Detects mid-import changes: Re-stats the file after hashing and verifies size and mtime have not changed (guards against TOCTOU).
- Registers a reference: Calls `registerMediaReference` to create a manifest in `.references/`.
- Returns: `{ src, storedName, contentHash }` with the `/media/uploads/<name>` path.
The function accepts optional `LocalMediaImportDependencies` for testability — the stat, hash, and register functions can be injected.
Usage
- CLI/agent import: The CLI `occ` tool and MCP agents call `importLocalMedia` to import local files.
- Desktop import: The Electron desktop app uses this for drag-and-drop and directory-watch imports.
- Transparent MOV proxy: `createTransparentMovProxy` is called separately after import to generate alpha-channel WebM proxies for transparent MOV files.
Code Reference
Source Location
- Repository: OpenChatCut
- File:*** server/local-media-import.ts
Signature
export interface LocalMediaImport {
src: string;
storedName: string;
contentHash: string;
}
export interface LocalMediaImportDependencies {
stat(path: string): Promise<{ isFile(): boolean; size: number; mtimeMs: number }>;
hashFile(path: string): Promise<string>;
registerReference(directory: string, name: string, sourcePath: string): Promise<void>;
}
export async function importLocalMedia(
sourcePath: string,
originalName: string,
dependencies?: LocalMediaImportDependencies,
): Promise<LocalMediaImport>;
export async function createTransparentMovProxy(
storedName: string,
signal?: AbortSignal,
): Promise<{ src: string } | null>;
Import
import { importLocalMedia, type LocalMediaImport } from '../server/local-media-import.ts';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sourcePath | string | Yes | Absolute path to the source file |
| originalName | string | Yes | Original filename (for extension) |
| dependencies | LocalMediaImportDependencies | No | Injectable stat/hash/register functions |
Outputs
| Name | Type | Description |
|---|---|---|
| src | string | `/media/uploads/<storedName>` public path |
| storedName | string | UUID + extension (e.g., `abc123.mp4`) |
| contentHash | string | 64-char SHA-256 hex, or empty for large files |
Usage Examples
Import a Local File
import { importLocalMedia } from '../server/local-media-import.ts';
const result = await importLocalMedia(
'/home/user/videos/clip.mp4',
'clip.mp4',
);
console.log(`Imported: ${result.src}`);
console.log(`Hash: ${result.contentHash || '(skipped — large file)'}`);
// Reference manifest at .references/<storedName>.json
With Custom Dependencies (Testing)
const result = await importLocalMedia('/path/to/file.mp4', 'file.mp4', {
stat: mockStat,
hashFile: mockHashFile,
registerReference: mockRegister,
});
Related Pages
Implements Principle
- Principle:0xsline_OpenChatCut_Media_Import_Pipeline
- Principle:0xsline_OpenChatCut_Content_Hash_Deduplication
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment