/** * Cloudflare Stream Media Provider * * Provides integration with Cloudflare Stream for video hosting and streaming. * * Features: * - Browse uploaded videos * - Upload new videos (direct upload) * - Delete videos * - HLS/DASH streaming URLs * - Thumbnail generation * * @see https://developers.cloudflare.com/stream/ */ import type { MediaProviderDescriptor } from "emdash/media"; /** * Cloudflare Stream configuration */ export interface CloudflareStreamConfig { /** * Cloudflare Account ID * If not provided, reads from accountIdEnvVar at runtime */ accountId?: string; /** * Environment variable name containing the Account ID * @default "CF_ACCOUNT_ID" */ accountIdEnvVar?: string; /** * API Token with Stream permissions * If not provided, reads from apiTokenEnvVar at runtime * Should have "Stream: Read" and "Stream: Edit" permissions */ apiToken?: string; /** * Environment variable name containing the API token * @default "CF_STREAM_TOKEN" */ apiTokenEnvVar?: string; /** * Customer subdomain for Stream delivery (optional) * If not provided, uses customer-{hash}.cloudflarestream.com format */ customerSubdomain?: string; /** * Default player controls setting * @default true */ controls?: boolean; /** * Autoplay videos (muted by default to comply with browser policies) * @default false */ autoplay?: boolean; /** * Loop videos * @default false */ loop?: boolean; /** * Mute videos * @default false (true if autoplay is enabled) */ muted?: boolean; } // Cloudflare Stream icon (inline SVG as data URL) const STREAM_ICON = `data:image/svg+xml,${encodeURIComponent('')}`; /** * Cloudflare Stream media provider * * @example * ```ts * import { cloudflareStream } from "@emdash-cms/cloudflare"; * * emdash({ * mediaProviders: [ * // Uses CF_ACCOUNT_ID and CF_STREAM_TOKEN env vars by default * cloudflareStream({}), * * // Or with custom env var names * cloudflareStream({ * accountIdEnvVar: "MY_CF_ACCOUNT", * apiTokenEnvVar: "MY_CF_STREAM_KEY", * }), * ], * }) * ``` */ export function cloudflareStream( config: CloudflareStreamConfig, ): MediaProviderDescriptor { return { id: "cloudflare-stream", name: "Cloudflare Stream", icon: STREAM_ICON, entrypoint: "@emdash-cms/cloudflare/media/stream-runtime", capabilities: { browse: true, search: true, upload: true, delete: true, }, config, }; }