🎥 Make videos programmatically with React
Require asset source type
Cursor Agent73d81241e193
diff --git a/packages/studio-server/src/helpers/resolve-composition-component.ts b/packages/studio-server/src/helpers/resolve-composition-component.tsindex 2bb947135a..db90469a01 100644--- a/packages/studio-server/src/helpers/resolve-composition-component.ts+++ b/packages/studio-server/src/helpers/resolve-composition-component.ts@@ -14,7 +14,7 @@ import type {VariableDeclaration,} from '@babel/types';import {- isRemotionSfxUrl,+ isUrl,type InsertableCompositionElement,} from '@remotion/studio-shared';import type {namedTypes} from 'ast-types';@@ -1454,11 +1454,8 @@ const createInsertableJsxElement = ({}if (element.type === 'asset') {- if (- element.srcType === 'remote' &&- (element.assetType !== 'audio' || !isRemotionSfxUrl(element.src))- ) {- throw new Error('Only @remotion/sfx audio URLs can be inserted remotely');+ if (element.srcType === 'remote' && !isUrl(element.src)) {+ throw new Error('Remote asset source must be a URL');}const staticFileLocalName =diff --git a/packages/studio-server/src/preview-server/routes/download-remote-asset.ts b/packages/studio-server/src/preview-server/routes/download-remote-asset.tsindex ebdc8205d4..31962f4898 100644--- a/packages/studio-server/src/preview-server/routes/download-remote-asset.ts+++ b/packages/studio-server/src/preview-server/routes/download-remote-asset.ts@@ -337,6 +337,7 @@ export const downloadRemoteAssetHandler: ApiHandler<type: 'asset',assetType: fileType.type === 'gif' ? 'gif' : 'image',src: assetPath,+ srcType: 'static',dimensions: fileType.dimensions,};diff --git a/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts b/packages/studio-server/src/preview-server/routes/insert-jsx-element.tsindex 8203007065..9073cc45dd 100644--- a/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts+++ b/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts@@ -1,6 +1,6 @@import {RenderInternals} from '@remotion/renderer';import {- isRemotionSfxUrl,+ isUrl,type InsertJsxElementRequest,type InsertJsxElementResponse,type InsertableCompositionElement,@@ -32,10 +32,8 @@ const validateElement = (element: InsertableCompositionElement) => {if (element.type === 'asset') {if (element.srcType === 'remote') {- if (element.assetType !== 'audio' || !isRemotionSfxUrl(element.src)) {- throw new Error(- 'Only @remotion/sfx audio URLs can be inserted remotely',- );+ if (!isUrl(element.src)) {+ throw new Error('Remote asset source must be a URL');}} else if (!element.src || element.src.includes('\\')) {throw new Error('Asset path must be a static file path');diff --git a/packages/studio-server/src/test/download-remote-asset.test.ts b/packages/studio-server/src/test/download-remote-asset.test.tsindex 96f47acb49..9766f15e6c 100644--- a/packages/studio-server/src/test/download-remote-asset.test.ts+++ b/packages/studio-server/src/test/download-remote-asset.test.ts@@ -93,6 +93,7 @@ test('follows validated redirects for remote assets', async () => {width: 800,},src: 'raw-link.gif',+ srcType: 'static',type: 'asset',},sizeInBytes: gif.byteLength,diff --git a/packages/studio-server/src/test/resolve-composition-component.test.ts b/packages/studio-server/src/test/resolve-composition-component.test.tsindex 7ecfbb1cc5..515e964e69 100644--- a/packages/studio-server/src/test/resolve-composition-component.test.ts+++ b/packages/studio-server/src/test/resolve-composition-component.test.ts@@ -692,6 +692,7 @@ test('inserts an Img asset into the resolved composition component', async () =>type: 'asset',assetType: 'image',src: 'image.png',+ srcType: 'static',dimensions: {width: 800,height: 600,@@ -750,6 +751,7 @@ test('rejects inserting a Video asset if Video is already defined', async () =>type: 'asset',assetType: 'video',src: 'clip.mp4',+ srcType: 'static',dimensions: null,},prettierConfigOverride: {singleQuote: true, useTabs: true},@@ -794,6 +796,7 @@ test('inserts a Gif asset into the resolved composition component', async () =>type: 'asset',assetType: 'gif',src: 'animation.gif',+ srcType: 'static',dimensions: {width: 320,height: 180,@@ -849,6 +852,7 @@ test('inserts an Audio asset into the resolved composition component', async ()type: 'asset',assetType: 'audio',src: 'audio.mp3',+ srcType: 'static',dimensions: null,},prettierConfigOverride: {singleQuote: true, useTabs: true},@@ -865,7 +869,7 @@ test('inserts an Audio asset into the resolved composition component', async ()}});-test('inserts a remote SFX audio asset with a literal URL', async () => {+test('inserts a remote audio asset with a literal URL', async () => {const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'remotion-resolve-'));try {await fs.writeFile(@@ -898,7 +902,7 @@ test('inserts a remote SFX audio asset with a literal URL', async () => {element: {type: 'asset',assetType: 'audio',- src: 'https://remotion.media/whip.wav',+ src: 'https://example.com/whip.wav',srcType: 'remote',dimensions: null,},@@ -908,7 +912,7 @@ test('inserts a remote SFX audio asset with a literal URL', async () => {expect(result.output).toContain("import { Audio } from '@remotion/media';");expect(result.output).toContain("import { AbsoluteFill } from 'remotion';");expect(result.output).toContain('<Audio');- expect(result.output).toContain('src="https://remotion.media/whip.wav"');+ expect(result.output).toContain('src="https://example.com/whip.wav"');expect(result.output).not.toContain('staticFile');expect(result.output).not.toContain('@remotion/sfx');} finally {@@ -953,6 +957,7 @@ test('rejects inserting an Audio asset if Audio is already defined', async () =>type: 'asset',assetType: 'audio',src: 'audio.mp3',+ srcType: 'static',dimensions: null,},prettierConfigOverride: {singleQuote: true, useTabs: true},diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex 297bdc0481..489b63d6b1 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -603,7 +603,7 @@ export type InsertableCompositionElement =type: 'asset';assetType: 'image' | 'video' | 'gif' | 'audio';src: string;- srcType?: 'static' | 'remote';+ srcType: 'static' | 'remote';dimensions: {width: number;height: number;diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex 67dfb8f548..00e9e790d2 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -198,9 +198,7 @@ export {getFieldsToShow,} from './schema-field-info';export {- REMOTION_MEDIA_SFX_PREFIX,SFX_DRAG_MIME_TYPE,- isRemotionSfxUrl,parseSfxDragData,type SfxDragData,} from './sfx-drag-data';@@ -248,3 +246,4 @@ export {stringifySequenceExpandedRowKey,stringifySequenceSubscriptionKey,} from './stringify-sequence-subscription-key';+export {isUrl} from './url';diff --git a/packages/studio-shared/src/sfx-drag-data.ts b/packages/studio-shared/src/sfx-drag-data.tsindex 843a86115d..6b89798d16 100644--- a/packages/studio-shared/src/sfx-drag-data.ts+++ b/packages/studio-shared/src/sfx-drag-data.ts@@ -1,6 +1,6 @@-export const SFX_DRAG_MIME_TYPE = 'application/vnd.remotion.sfx+json';+import {isUrl} from './url';-export const REMOTION_MEDIA_SFX_PREFIX = 'https://remotion.media/';+export const SFX_DRAG_MIME_TYPE = 'application/vnd.remotion.sfx+json';export type SfxDragData = {type: 'remotion-sfx';@@ -15,20 +15,6 @@ const isRecord = (value: unknown): value is Record<string, unknown> => {return typeof value === 'object' && value !== null && !Array.isArray(value);};-export const isRemotionSfxUrl = (value: string): boolean => {- try {- const url = new URL(value);- return (- url.protocol === 'https:' &&- url.host === 'remotion.media' &&- url.href.startsWith(REMOTION_MEDIA_SFX_PREFIX) &&- url.pathname.length > 1- );- } catch {- return false;- }-};-export const parseSfxDragData = (value: string): SfxDragData | null => {try {const parsed: unknown = JSON.parse(value);@@ -49,7 +35,7 @@ export const parseSfxDragData = (value: string): SfxDragData | null => {typeof name !== 'string' ||name.length === 0 ||typeof url !== 'string' ||- !isRemotionSfxUrl(url)+ !isUrl(url)) {return null;}diff --git a/packages/studio-shared/src/test/required-package.test.ts b/packages/studio-shared/src/test/required-package.test.tsindex bb15517c71..366ecd59d2 100644--- a/packages/studio-shared/src/test/required-package.test.ts+++ b/packages/studio-shared/src/test/required-package.test.ts@@ -17,6 +17,7 @@ test('gets required package for insertable elements', () => {type: 'asset',assetType: 'image',src: 'image.png',+ srcType: 'static',dimensions: null,}),).toBe(null);@@ -25,6 +26,7 @@ test('gets required package for insertable elements', () => {type: 'asset',assetType: 'video',src: 'video.mp4',+ srcType: 'static',dimensions: null,}),).toBe('@remotion/media');@@ -33,6 +35,7 @@ test('gets required package for insertable elements', () => {type: 'asset',assetType: 'audio',src: 'audio.mp3',+ srcType: 'static',dimensions: null,}),).toBe('@remotion/media');@@ -41,6 +44,7 @@ test('gets required package for insertable elements', () => {type: 'asset',assetType: 'gif',src: 'animation.gif',+ srcType: 'static',dimensions: null,}),).toBe('@remotion/gif');diff --git a/packages/studio-shared/src/test/sfx-drag-data.test.ts b/packages/studio-shared/src/test/sfx-drag-data.test.tsindex 3271bc4894..463c88a2a2 100644--- a/packages/studio-shared/src/test/sfx-drag-data.test.ts+++ b/packages/studio-shared/src/test/sfx-drag-data.test.ts@@ -1,9 +1,6 @@import {expect, test} from 'bun:test';-import {- isRemotionSfxUrl,- parseSfxDragData,- type SfxDragData,-} from '../sfx-drag-data';+import {parseSfxDragData, type SfxDragData} from '../sfx-drag-data';+import {isUrl} from '../url';const validSfxDragData: SfxDragData = {type: 'remotion-sfx',@@ -20,10 +17,20 @@ test('parses SFX drag data', () => {);});-test('validates remotion.media SFX URLs', () => {- expect(isRemotionSfxUrl('https://remotion.media/whip.wav')).toBe(true);- expect(isRemotionSfxUrl('http://remotion.media/whip.wav')).toBe(false);- expect(isRemotionSfxUrl('https://example.com/whip.wav')).toBe(false);+test('accepts any URL in SFX drag data', () => {+ const nonRemotionUrlDragData: SfxDragData = {+ ...validSfxDragData,+ sfx: {+ ...validSfxDragData.sfx,+ url: 'https://example.com/whip.wav',+ },+ };+ expect(parseSfxDragData(JSON.stringify(nonRemotionUrlDragData))).toEqual(+ nonRemotionUrlDragData,+ );+ expect(isUrl('https://remotion.media/whip.wav')).toBe(true);+ expect(isUrl('https://example.com/whip.wav')).toBe(true);+ expect(isUrl('not-a-url')).toBe(false);});test('rejects invalid SFX drag data', () => {@@ -54,7 +61,7 @@ test('rejects invalid SFX drag data', () => {...validSfxDragData,sfx: {...validSfxDragData.sfx,- url: 'https://example.com/whip.wav',+ url: 'not-a-url',},}),),diff --git a/packages/studio-shared/src/url.ts b/packages/studio-shared/src/url.tsnew file mode 100644index 0000000000..25a41e8722--- /dev/null+++ b/packages/studio-shared/src/url.ts@@ -0,0 +1,8 @@+export const isUrl = (value: string): boolean => {+ try {+ const parsed = new URL(value);+ return parsed.href.length > 0;+ } catch {+ return false;+ }+};diff --git a/packages/studio/src/components/import-assets.ts b/packages/studio/src/components/import-assets.tsindex 92585fa5ba..42b8169cdc 100644--- a/packages/studio/src/components/import-assets.ts+++ b/packages/studio/src/components/import-assets.ts@@ -1,7 +1,7 @@import {detectFileType,getRequiredPackageForInsertableElement,- isRemotionSfxUrl,+ isUrl,type DownloadRemoteAssetResponse,type FileType,type InsertableCompositionElement,@@ -29,6 +29,7 @@ export const getAssetElement = ({type: 'asset',assetType: 'image',src,+ srcType: 'static',dimensions: fileType.dimensions,};}@@ -38,6 +39,7 @@ export const getAssetElement = ({type: 'asset',assetType: 'gif',src,+ srcType: 'static',dimensions: fileType.dimensions,};}@@ -52,6 +54,7 @@ export const getAssetElement = ({type: 'asset',assetType: 'video',src,+ srcType: 'static',dimensions: null,};}@@ -66,6 +69,7 @@ export const getAssetElement = ({type: 'asset',assetType: 'audio',src,+ srcType: 'static',dimensions: null,};}@@ -90,6 +94,7 @@ export const getAssetElementFromPath = (type: 'asset',assetType: 'image',src: assetPath,+ srcType: 'static',dimensions: null,};}@@ -99,6 +104,7 @@ export const getAssetElementFromPath = (type: 'asset',assetType: 'gif',src: assetPath,+ srcType: 'static',dimensions: null,};}@@ -108,6 +114,7 @@ export const getAssetElementFromPath = (type: 'asset',assetType: 'video',src: assetPath,+ srcType: 'static',dimensions: null,};}@@ -117,6 +124,7 @@ export const getAssetElementFromPath = (type: 'asset',assetType: 'audio',src: assetPath,+ srcType: 'static',dimensions: null,};}@@ -379,7 +387,7 @@ export const insertRemoteAudio = async ({compositionId: string;url: string;}) => {- if (!isRemotionSfxUrl(url)) {+ if (!isUrl(url)) {showNotification('Cannot add sound effect: Unsupported URL', 3000);return;}diff --git a/packages/studio/src/test/import-assets.test.ts b/packages/studio/src/test/import-assets.test.tsindex 923553e2db..c7c3f38674 100644--- a/packages/studio/src/test/import-assets.test.ts+++ b/packages/studio/src/test/import-assets.test.ts@@ -15,6 +15,7 @@ test('maps audio file types to Audio assets', () => {type: 'asset',assetType: 'audio',src: `sound.${type}`,+ srcType: 'static',dimensions: null,});}@@ -34,24 +35,28 @@ test('maps existing static file paths to insertable assets', () => {type: 'asset',assetType: 'image',src: 'nested/photo.JPG',+ srcType: 'static',dimensions: null,});expect(getAssetElementFromPath('movie.webm')).toEqual({type: 'asset',assetType: 'video',src: 'movie.webm',+ srcType: 'static',dimensions: null,});expect(getAssetElementFromPath('audio.flac')).toEqual({type: 'asset',assetType: 'audio',src: 'audio.flac',+ srcType: 'static',dimensions: null,});expect(getAssetElementFromPath('animation.gif')).toEqual({type: 'asset',assetType: 'gif',src: 'animation.gif',+ srcType: 'static',dimensions: null,});});