Implementation:0xsline OpenChatCut HandleExportDestinationPut
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Video_Export, File_System, Delivery |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete HTTP handler that writes a rendered export file to a user-selected directory atomically via temp-file-and-rename, with grant authorization, size limits, and lease-based concurrency control.
Description
The handleExportDestinationPut function processes PUT requests to `/api/export-destinations/{grantId}/{filename}`:
- Grant authorization: Resolves the `grantId` from the URL path against `resolveExportDirectoryGrant`; rejects if not found.
- Path safety: The sanitized filename must resolve within the grant directory (no path traversal).
- Source flexibility: Supports two delivery modes:
- Stream mode: File data is the PUT body (streamed to temp file).
- Copy mode: File is copied from an upload source via the `x-openchatcut-export-source` header.
- Atomic write: Writes to `.openchatcut-<uuid>.part` then renames to the final name.
- Size limit: Maximum 100 GB (`MAX_EXPORT_BYTES`); rejects with 413 if exceeded.
- Empty rejection: Zero-byte results are rejected with 422.
- Lease: A per-target lease (`acquireTargetLease`) prevents two simultaneous writes to the same file.
- Error handling: Structured `ExportDestinationError` with HTTP status, code, retryable flag, cleanup status, and target path.
Usage
- Export delivery stage: Called by the export destination plugin after rendering and QA.
- Export destination plugin: `exportDestinationPlugin()` registers the route at `/api/export-destinations`.
Code Reference
Source Location
- Repository: OpenChatCut
- File:*** server/plugins/export-destination.ts
Signature
export async function handleExportDestinationPut(
req: IncomingMessage,
res: ServerResponse,
resolveSource?: (name: string) => string | null,
): Promise<void>;
export function exportDestinationPlugin(): Plugin;
Import
import {
handleExportDestinationPut,
exportDestinationPlugin,
} from '../server/plugins/export-destination.ts';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| req | IncomingMessage | Yes | HTTP PUT request (body stream or source header) |
| res | ServerResponse | Yes | HTTP response (204 on success) |
| resolveSource | null | No | Resolver for upload-source names (default: resolveUploadFile) |
| grantId | string | Yes | From URL path (32-128 chars) |
| filename | string | Yes | Sanitized filename (no reserved Windows names) |
| x-openchatcut-export-source | string | No | Header: upload name to copy from |
Outputs
| Name | Type | Description |
|---|---|---|
| HTTP 204 | No Content | File written atomically to the destination |
| HTTP 404 | JSON | Grant not found or source unavailable |
| HTTP 400 | JSON | Invalid filename (path traversal) |
| HTTP 410 | JSON | Destination directory unavailable |
| HTTP 413 | JSON | File exceeds 100 GB limit |
| HTTP 422 | JSON | File is empty |
| HTTP 500 | JSON | Write failed (structured ExportFailure) |
Usage Examples
Copy from Upload Source
# Copy an existing upload file to the export destination
curl -X PUT \
"http://localhost:5199/api/export-destinations/${GRANT_ID}/final-video.mp4" \
-H "x-openchatcut-export-source: abc123-uuid.mp4"
Stream File Body
# Stream file data directly
curl -X PUT \
"http://localhost:5199/api/export-destinations/${GRANT_ID}/final-video.mp4" \
--data-binary @/tmp/exports/output.mp4
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment