Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: upload videos from Builder and MCP (#6189)
Oleg Isonen0760d6cfec3c
diff --git a/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.test.tsx b/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.test.tsxindex 8aec11e38d..cd408ccd94 100644--- a/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.test.tsx+++ b/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.test.tsx@@ -198,6 +198,34 @@ describe("AssetThumbnail", () => {);});+ test("falls back to a file preview when the browser cannot decode a video", () => {+ const container = renderer.render(+ <AssetThumbnail+ assetContainer={{+ status: "uploaded",+ asset: {+ id: "video-asset",+ projectId: "project",+ name: "sample.avi",+ format: "avi",+ size: 100,+ type: "video",+ meta: { width: 640, height: 360 },+ createdAt: "2026-01-01T00:00:00.000Z",+ },+ }}+ interactions={createInteractions()}+ />+ );+ const video = container.querySelector("video");+ expect(video).toBeInstanceOf(HTMLVideoElement);++ act(() => video?.dispatchEvent(new Event("error", { bubbles: true })));++ expect(container.querySelector("video")).toBeNull();+ expect(container.textContent).toContain("AVI");+ });+test("uses focus for folder selection and opens only on activation", () => {const onOpen = vi.fn();const onSelectionChange = vi.fn();diff --git a/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.tsx b/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.tsxindex 6da6c456b8..fa15518121 100644--- a/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.tsx+++ b/apps/builder/app/builder/shared/asset-manager/asset-thumbnail.tsx@@ -115,6 +115,31 @@ const GenericFilePreview = ({);};+const VideoPreview = ({+ src,+ ext,+ format,+}: {+ src: string;+ ext: string;+ format: string;+}) => {+ const [failedSrc, setFailedSrc] = useState<string>();++ if (failedSrc === src) {+ return <GenericFilePreview ext={ext} format={format} />;+ }++ return (+ <StyledWebstudioVideo+ src={src}+ preload="metadata"+ muted+ onError={() => setFailedSrc(src)}+ />+ );+};+type AssetThumbnailProps = {assetContainer: AssetContainer;interactions: AssetManagerThumbnailInteractions;@@ -258,12 +283,14 @@ export const AssetThumbnail = ({width={64}/>) : assetType === "video" ? (- <StyledWebstudioVideo+ <VideoPreviewsrc={assetContainer.status === "uploading"? assetContainer.objectURL: wsVideoLoader({ src: asset.name })}+ ext={ext}+ format={asset.format}/>) : (<GenericFilePreview ext={ext} format={asset.format} />diff --git a/apps/builder/app/builder/shared/assets/asset-upload.tsx b/apps/builder/app/builder/shared/assets/asset-upload.tsxindex 69e0d66177..a8a9178fff 100644--- a/apps/builder/app/builder/shared/assets/asset-upload.tsx+++ b/apps/builder/app/builder/shared/assets/asset-upload.tsx@@ -7,9 +7,12 @@ import {import { useStore } from "@nanostores/react";import { Button, Flex, Tooltip, toast } from "@webstudio-is/design-system";import { UploadIcon } from "@webstudio-is/icons";-import { IMAGE_MIME_TYPES, detectAssetType } from "@webstudio-is/sdk";+import {+ IMAGE_MIME_TYPES,+ detectAssetType,+ type AssetType,+} from "@webstudio-is/sdk";import { MAX_UPLOAD_SIZE, toBytes } from "@webstudio-is/asset-uploader";-import type { AssetType } from "@webstudio-is/asset-uploader";import { FONT_MIME_TYPES } from "@webstudio-is/fonts";import { uploadAssets } from "./upload-assets";import { $authPermit } from "~/shared/nano-states";diff --git a/apps/builder/app/builder/shared/assets/asset-utils.test.ts b/apps/builder/app/builder/shared/assets/asset-utils.test.tsindex fb3106317f..6b2e2f248b 100644--- a/apps/builder/app/builder/shared/assets/asset-utils.test.ts+++ b/apps/builder/app/builder/shared/assets/asset-utils.test.ts@@ -195,7 +195,11 @@ describe("uploadingFileDataToAsset", () => {id: "test-id",name: "video.mp4",format: "mp4",- type: "file",+ type: "video",+ meta: {+ width: Number.NaN,+ height: Number.NaN,+ },});});diff --git a/apps/builder/app/builder/shared/assets/asset-utils.ts b/apps/builder/app/builder/shared/assets/asset-utils.tsindex 953a79e81c..45a3a12d03 100644--- a/apps/builder/app/builder/shared/assets/asset-utils.ts+++ b/apps/builder/app/builder/shared/assets/asset-utils.ts@@ -2,6 +2,7 @@ import type {Asset,FontAsset,ImageAsset,+ VideoAsset,AllowedFileExtension,} from "@webstudio-is/sdk";import { nanoid } from "nanoid";@@ -147,7 +148,20 @@ export const uploadingFileDataToAsset = (return asset;}- // Videos and other non-image/font uploads use the generic file type.+ if (assetType === "video") {+ const asset: VideoAsset = {+ ...base,+ format,+ type: "video",+ meta: {+ width: Number.NaN,+ height: Number.NaN,+ },+ };++ return asset;+ }+const asset: Asset = {...base,format,diff --git a/apps/builder/app/builder/shared/assets/assets-shell.tsx b/apps/builder/app/builder/shared/assets/assets-shell.tsxindex 087abb94a8..dfde137443 100644--- a/apps/builder/app/builder/shared/assets/assets-shell.tsx+++ b/apps/builder/app/builder/shared/assets/assets-shell.tsx@@ -6,7 +6,6 @@ import {type JSX,type PointerEvent,} from "react";-import type { AssetType } from "@webstudio-is/asset-uploader";import {ContextMenu,ContextMenuTrigger,@@ -35,7 +34,7 @@ import {readDroppedAssetItems,} from "./directory-drop";import { $assetFolders } from "~/shared/sync/data-stores";-import { createAssetFolderHierarchy } from "@webstudio-is/sdk";+import { createAssetFolderHierarchy, type AssetType } from "@webstudio-is/sdk";import { executeRuntimeMutation } from "~/shared/instance-utils/data";import { onNextTransactionComplete } from "~/shared/sync/project-queue";import {diff --git a/apps/builder/app/builder/shared/assets/upload-assets.test.ts b/apps/builder/app/builder/shared/assets/upload-assets.test.tsindex e604f16ea2..51659ea858 100644--- a/apps/builder/app/builder/shared/assets/upload-assets.test.ts+++ b/apps/builder/app/builder/shared/assets/upload-assets.test.ts@@ -1,4 +1,5 @@import { beforeEach, describe, test, expect, vi } from "vitest";+import { assetType } from "@webstudio-is/sdk";import { __testing__ } from "./upload-assets";const {@@ -54,6 +55,30 @@ describe("upload-assets", () => {expect(init.headers.get("x-auth-token")).toBe("token");});+ test.each(assetType.options)(+ "reserves %s assets without changing their type",+ async (type) => {+ request.mockResolvedValue(+ Response.json({+ assetId: "server-asset-id",+ name: "upload-name",+ deduplicated: false,+ })+ );++ await createUploadTicket({+ authToken: "token",+ projectId: "project-id",+ fileOrUrl: new File(["content"], `asset.${type}`),+ assetType: type,+ request,+ });++ const [, init] = request.mock.calls[0] as [string, { body: FormData }];+ expect(init.body.get("type")).toBe(type);+ }+ );+test("keeps the display name separate from the sanitized storage name", async () => {request.mockResolvedValue(new Response(diff --git a/apps/builder/app/builder/shared/assets/upload-assets.tsx b/apps/builder/app/builder/shared/assets/upload-assets.tsxindex c1f04c4e4a..0e2b4f061e 100644--- a/apps/builder/app/builder/shared/assets/upload-assets.tsx+++ b/apps/builder/app/builder/shared/assets/upload-assets.tsx@@ -1,9 +1,13 @@import warnOnce from "warn-once";import invariant from "tiny-invariant";-import { getFileNameParts, type Asset } from "@webstudio-is/sdk";+import {+ getFileNameParts,+ type Asset,+ type AssetType,+} from "@webstudio-is/sdk";import { assetsUploadsApiUrl } from "@webstudio-is/sdk/runtime";import type { AssetUploadResult } from "@webstudio-is/protocol/asset-resource-api";-import type { AssetType, UploadTicket } from "@webstudio-is/asset-uploader";+import type { UploadTicket } from "@webstudio-is/asset-uploader";import { Box, toast, css, theme } from "@webstudio-is/design-system";import { sanitizeS3Key } from "@webstudio-is/asset-uploader";import { getImageAttributes, wsImageLoader } from "@webstudio-is/image";diff --git a/apps/builder/app/routes/rest.assets.uploads_.$name.tsx b/apps/builder/app/routes/rest.assets.uploads_.$name.tsxindex 53e82d0ce6..a7832650ac 100644--- a/apps/builder/app/routes/rest.assets.uploads_.$name.tsx+++ b/apps/builder/app/routes/rest.assets.uploads_.$name.tsx@@ -122,7 +122,7 @@ export const action = async (props: ActionFunctionArgs) => {}const assetInfoFallback = getAssetInfoFallback({format:- assetType === "image"+ assetType === "image" || assetType === "video"? (url.searchParams.get("format") ?? undefined): undefined,searchParams: url.searchParams,diff --git a/apps/builder/app/shared/db/canvas.server.test.ts b/apps/builder/app/shared/db/canvas.server.test.tsindex c6864f5e1a..eaebd430cf 100644--- a/apps/builder/app/shared/db/canvas.server.test.ts+++ b/apps/builder/app/shared/db/canvas.server.test.ts@@ -44,17 +44,24 @@ const createBundleBuild = (test("serializes dev builds into project bundles without requiring deployment", () => {const build = createBundleBuild();- const asset = createImageAssetFixture({ projectId: build.projectId });+ const imageAsset = createImageAssetFixture({ projectId: build.projectId });+ const videoAsset: Asset = {+ ...imageAsset,+ id: "video-asset",+ name: "video.mp4",+ type: "video",+ format: "mp4",+ };const bundle = serializeProjectBundle({build,- assets: [asset],+ assets: [imageAsset, videoAsset],});expect(bundle.build.id).toBe(build.id);expect(bundle.build.deployment).toBeUndefined();expect(bundle.page.path).toBe("");- expect(bundle.assets).toEqual([asset]);+ expect(bundle.assets).toEqual([imageAsset, videoAsset]);});test("keeps font assets referenced from nested style values", () => {diff --git a/apps/builder/app/shared/db/canvas.server.ts b/apps/builder/app/shared/db/canvas.server.tsindex f2f27f8b22..7da2d41da8 100644--- a/apps/builder/app/shared/db/canvas.server.ts+++ b/apps/builder/app/shared/db/canvas.server.ts@@ -60,6 +60,7 @@ const serializeProjectBundle = ({const usedAssets = assets.filter((asset) =>asset.type === "image" ||+ asset.type === "video" ||asset.type === "file" ||(asset.type === "font" && fontFamilies.has(asset.meta.family)));diff --git a/apps/builder/app/shared/nano-states/misc.ts b/apps/builder/app/shared/nano-states/misc.tsindex be9b0c5f20..30c36e9d40 100644--- a/apps/builder/app/shared/nano-states/misc.ts+++ b/apps/builder/app/shared/nano-states/misc.ts@@ -20,10 +20,10 @@ import type {Props,StyleDecl,StyleSource,+ AssetType,} from "@webstudio-is/sdk";import type { CssProperty, UnitValue } from "@webstudio-is/css-engine";import type { TokenPermissions } from "@webstudio-is/authorization-token";-import type { AssetType } from "@webstudio-is/asset-uploader";import type { DragStartPayload } from "~/canvas/shared/use-drag-drop";import { type InstanceSelector } from "@webstudio-is/project-build/runtime";import type { ChildrenOrientation } from "@webstudio-is/design-system";diff --git a/fixtures/react-router-cloudflare/.webstudio/data.json b/fixtures/react-router-cloudflare/.webstudio/data.jsonindex d5105eda9d..d8a3fdaf15 100644--- a/fixtures/react-router-cloudflare/.webstudio/data.json+++ b/fixtures/react-router-cloudflare/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "f565d527-32e7-4731-bc71-aca9e9574587","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",diff --git a/fixtures/react-router-docker/.webstudio/data.json b/fixtures/react-router-docker/.webstudio/data.jsonindex d5105eda9d..d8a3fdaf15 100644--- a/fixtures/react-router-docker/.webstudio/data.json+++ b/fixtures/react-router-docker/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "f565d527-32e7-4731-bc71-aca9e9574587","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",diff --git a/fixtures/react-router-netlify/.webstudio/data.json b/fixtures/react-router-netlify/.webstudio/data.jsonindex d5105eda9d..d8a3fdaf15 100644--- a/fixtures/react-router-netlify/.webstudio/data.json+++ b/fixtures/react-router-netlify/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "f565d527-32e7-4731-bc71-aca9e9574587","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",diff --git a/fixtures/react-router-vercel/.webstudio/data.json b/fixtures/react-router-vercel/.webstudio/data.jsonindex d5105eda9d..d8a3fdaf15 100644--- a/fixtures/react-router-vercel/.webstudio/data.json+++ b/fixtures/react-router-vercel/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "f565d527-32e7-4731-bc71-aca9e9574587","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",diff --git a/fixtures/ssg-cloudflare-pages/.webstudio/data.json b/fixtures/ssg-cloudflare-pages/.webstudio/data.jsonindex 6f72a667c2..c38a6130b1 100644--- a/fixtures/ssg-cloudflare-pages/.webstudio/data.json+++ b/fixtures/ssg-cloudflare-pages/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "a2e8de30-03d5-4514-a3a6-406b3266a3af","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",diff --git a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json b/fixtures/ssg-netlify-by-project-id/.webstudio/data.jsonindex 0fb364280a..9003c13232 100644--- a/fixtures/ssg-netlify-by-project-id/.webstudio/data.json+++ b/fixtures/ssg-netlify-by-project-id/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "8f0fdff2-e76b-4f86-9203-ea7df5f1143c","projectId": "8a7358b1-7de3-459d-b7b1-56dddfb6ce1e",diff --git a/fixtures/webstudio-cloudflare-template/.webstudio/data.json b/fixtures/webstudio-cloudflare-template/.webstudio/data.jsonindex 6f72a667c2..c38a6130b1 100644--- a/fixtures/webstudio-cloudflare-template/.webstudio/data.json+++ b/fixtures/webstudio-cloudflare-template/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "a2e8de30-03d5-4514-a3a6-406b3266a3af","projectId": "d845c167-ea07-4875-b08d-83e97c09dcce",diff --git a/fixtures/webstudio-features/.webstudio/data.json b/fixtures/webstudio-features/.webstudio/data.jsonindex 8d973bc83c..ba6fd459dd 100644--- a/fixtures/webstudio-features/.webstudio/data.json+++ b/fixtures/webstudio-features/.webstudio/data.json@@ -1,5 +1,5 @@{- "bundleVersion": "bundle-1pgeukw",+ "bundleVersion": "bundle-99lpzx","build": {"id": "1b66ee06-8ea5-4420-9a0e-e0d3a67aca32","projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",@@ -7261,8 +7261,11 @@"createdAt": "2026-01-14T02:59:19.806+00:00","updatedAt": "2026-01-14T02:59:19.806+00:00","format": "webm",- "meta": {},- "type": "file"+ "meta": {+ "width": 480,+ "height": 270+ },+ "type": "video"},{"id": "7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59",@@ -7300,8 +7303,11 @@"createdAt": "2026-01-14T02:59:28.168+00:00","updatedAt": "2026-01-14T02:59:28.168+00:00","format": "mp4",- "meta": {},- "type": "file"+ "meta": {+ "width": 202,+ "height": 360+ },+ "type": "video"},{"id": "cd939c56-bcdd-4e64-bd9c-567a9bccd3da",diff --git a/fixtures/webstudio-features/app/__generated__/$resources.asset-query-runtime.ts b/fixtures/webstudio-features/app/__generated__/$resources.asset-query-runtime.tsindex 9a63651a7c..8baf2fc468 100644--- a/fixtures/webstudio-features/app/__generated__/$resources.asset-query-runtime.ts+++ b/fixtures/webstudio-features/app/__generated__/$resources.asset-query-runtime.ts@@ -2,7 +2,7 @@ import { createGeneratedAssetResourceRuntime } from "./$resources.asset-query-veimport { assetQueryDatabase } from "./$resources.asset-query-manifest";const deploymentId = "1b66ee06-8ea5-4420-9a0e-e0d3a67aca32";-const runtimeAssets = {"2b151fc7b4b0324e6ab78c40f72c7f59273f81fb1be3d08b3f9976428601b95e":{"url":"/assets/e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3"},"42e55b0464790758b9352d675cf28fadfcf8a3259fc1e890100617d3e731be88":{"url":"/assets/cabinsketch-bold_TLCbytfxf8ENHwZ6ze3Jj.ttf","family":"CabinSketch","style":"normal","weight":700},"4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d":{"url":"/assets/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm"},"7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59":{"url":"/assets/cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png","width":790,"height":786},"9a8bc926-7804-4d3f-af81-69196b1d2ed8":{"url":"/assets/small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp","width":100,"height":100},"cbf6b1b052e52b256cef54a032a546bf43bf3f5441be4d1c5eeaabce26903d78":{"url":"/assets/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4"},"cd939c56-bcdd-4e64-bd9c-567a9bccd3da":{"url":"/assets/_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg","width":1024,"height":1024}};+const runtimeAssets = {"2b151fc7b4b0324e6ab78c40f72c7f59273f81fb1be3d08b3f9976428601b95e":{"url":"/assets/e-mail-39993_vrxyjxQv3j67Krs62Vz7Y.mp3"},"42e55b0464790758b9352d675cf28fadfcf8a3259fc1e890100617d3e731be88":{"url":"/assets/cabinsketch-bold_TLCbytfxf8ENHwZ6ze3Jj.ttf","family":"CabinSketch","style":"normal","weight":700},"4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d":{"url":"/assets/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm","width":480,"height":270},"7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59":{"url":"/assets/cat_silhouette_BDpTbUFSpVbfUWQZNxbBG.png","width":790,"height":786},"9a8bc926-7804-4d3f-af81-69196b1d2ed8":{"url":"/assets/small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp","width":100,"height":100},"cbf6b1b052e52b256cef54a032a546bf43bf3f5441be4d1c5eeaabce26903d78":{"url":"/assets/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4","width":202,"height":360},"cd939c56-bcdd-4e64-bd9c-567a9bccd3da":{"url":"/assets/_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg","width":1024,"height":1024}};const createRuntimeFetch = createGeneratedAssetResourceRuntime({deploymentId,artifact: assetQueryDatabase,diff --git a/fixtures/webstudio-features/app/__generated__/$resources.assets.ts b/fixtures/webstudio-features/app/__generated__/$resources.assets.tsindex aaac82aeb9..fffe5e5763 100644--- a/fixtures/webstudio-features/app/__generated__/$resources.assets.ts+++ b/fixtures/webstudio-features/app/__generated__/$resources.assets.ts@@ -13,6 +13,8 @@},"4afe692f78ec0530e355a551a3860302c4478037db7b25a3bdae82c32c78634d": {"url": "/assets/webm-example_2r_6VmRBjhAy3ldaqz0gk.webm",+ "width": 480,+ "height": 270,"contentRef": "webm-example_2r_6VmRBjhAy3ldaqz0gk.webm"},"7cf5892080fa66b5e6175ffd2d27c304ee6b09ce1f21847a95000225ad1afa59": {@@ -29,6 +31,8 @@},"cbf6b1b052e52b256cef54a032a546bf43bf3f5441be4d1c5eeaabce26903d78": {"url": "/assets/video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4",+ "width": 202,+ "height": 360,"contentRef": "video_QamtUWsD-ShifhzZLoNIv_ald_1xtyEb3uHhFb7nCQa.mp4"},"cd939c56-bcdd-4e64-bd9c-567a9bccd3da": {diff --git a/packages/asset-uploader/src/clients/fs/fs.ts b/packages/asset-uploader/src/clients/fs/fs.tsindex ab2b050f26..05611fb18a 100644--- a/packages/asset-uploader/src/clients/fs/fs.ts+++ b/packages/asset-uploader/src/clients/fs/fs.ts@@ -11,13 +11,14 @@ export const createFsAssetObjectStore = (options: FsClientOptions): AssetObjectStore => {return {- uploadFile: (name, type, data, _assetInfoFallback, assetDataOverride) =>+ uploadFile: (name, type, data, assetInfoFallback, assetDataOverride) =>uploadToFs({name,type,data,maxSize: options.maxUploadSize,fileDirectory: options.fileDirectory,+ assetInfoFallback,assetDataOverride,}),readFile: (name, range) =>diff --git a/packages/asset-uploader/src/clients/fs/upload.ts b/packages/asset-uploader/src/clients/fs/upload.tsindex 9c955e1cc5..4c26e69ede 100644--- a/packages/asset-uploader/src/clients/fs/upload.ts+++ b/packages/asset-uploader/src/clients/fs/upload.ts@@ -8,6 +8,7 @@ import {getAssetData,} from "../../utils/get-asset-data";import { createSizeLimiter } from "../../utils/size-limiter";+import type { AssetInfoFallback } from "../../client";export const uploadToFs = async ({name,@@ -15,6 +16,7 @@ export const uploadToFs = async ({data: dataStream,maxSize,fileDirectory,+ assetInfoFallback,assetDataOverride,}: {name: string;@@ -22,6 +24,7 @@ export const uploadToFs = async ({data: AsyncIterable<Uint8Array>;maxSize: number;fileDirectory: string;+ assetInfoFallback: AssetInfoFallback | undefined;assetDataOverride?: AssetDataOverride;}): Promise<AssetData> => {const filepath = resolve(fileDirectory, name);@@ -31,16 +34,25 @@ export const uploadToFs = async ({const data = await buffer(limitSize(dataStream));const assetData = applyAssetDataOverride(- await getAssetData({- type: type.startsWith("image")- ? "image"- : type === "font"- ? "font"- : "file",- size: data.byteLength,- data,- name,- }),+ type.startsWith("video") && assetInfoFallback !== undefined+ ? {+ size: data.byteLength,+ format: assetInfoFallback.format,+ meta: {+ width: assetInfoFallback.width,+ height: assetInfoFallback.height,+ },+ }+ : await getAssetData({+ type: type.startsWith("image")+ ? "image"+ : type === "font"+ ? "font"+ : "file",+ size: data.byteLength,+ data,+ name,+ }),assetDataOverride);diff --git a/packages/asset-uploader/src/types.ts b/packages/asset-uploader/src/types.tsindex 53466b3af6..6b7f796681 100644--- a/packages/asset-uploader/src/types.ts+++ b/packages/asset-uploader/src/types.ts@@ -1,7 +1,5 @@import type { Asset } from "@webstudio-is/sdk";-export type AssetType = "image" | "font" | "video" | "file";-type UploadTicketBase = {assetId: Asset["id"];name: string;diff --git a/packages/asset-uploader/src/utils/format-asset.test.ts b/packages/asset-uploader/src/utils/format-asset.test.tsindex 78d20e4fbd..7de079a269 100644--- a/packages/asset-uploader/src/utils/format-asset.test.ts+++ b/packages/asset-uploader/src/utils/format-asset.test.ts@@ -75,7 +75,7 @@ describe("formatAsset", () => {});});- test("formats video asset with width and height as file type", () => {+ test("formats video asset with width and height", () => {const result = formatAsset({...baseParams,file: {@@ -96,14 +96,14 @@ describe("formatAsset", () => {id: "test-asset-id",name: "video.mp4",projectId: "test-project-id",- type: "file",+ type: "video",format: "mp4",size: 5000000,- meta: {},+ meta: { width: 1920, height: 1080 },});});- test("formats webm video with width and height as file type", () => {+ test("formats webm video with width and height", () => {const result = formatAsset({...baseParams,file: {@@ -124,10 +124,10 @@ describe("formatAsset", () => {id: "test-asset-id",name: "video.webm",projectId: "test-project-id",- type: "file",+ type: "video",format: "webm",size: 3000000,- meta: {},+ meta: { width: 1280, height: 720 },});});@@ -222,4 +222,25 @@ describe("formatAsset", () => {meta: {},});});++ test("keeps legacy video without dimensions as file type", () => {+ const result = formatAsset({+ ...baseParams,+ file: {+ name: "video.mp4",+ format: "mp4",+ description: null,+ size: 50000,+ createdAt: "2024-01-01T00:00:00Z",+ updatedAt: "2024-01-02T00:00:00Z",+ meta: JSON.stringify({}),+ },+ });++ expect(result).toMatchObject({+ type: "file",+ format: "mp4",+ meta: {},+ });+ });});diff --git a/packages/asset-uploader/src/utils/format-asset.ts b/packages/asset-uploader/src/utils/format-asset.tsindex edd565b14f..97420db816 100644--- a/packages/asset-uploader/src/utils/format-asset.ts+++ b/packages/asset-uploader/src/utils/format-asset.ts@@ -1,5 +1,10 @@import { type FontFormat, fontMeta, FONT_FORMATS } from "@webstudio-is/fonts";-import { type Asset, imageMeta, detectAssetType } from "@webstudio-is/sdk";+import {+ type Asset,+ imageMeta,+ videoMeta,+ detectAssetType,+} from "@webstudio-is/sdk";export const formatAsset = ({assetId,@@ -57,6 +62,11 @@ export const formatAsset = ({parsedMeta &&typeof parsedMeta.width === "number" &&typeof parsedMeta.height === "number";+ const isVideo =+ detectedType === "video" &&+ parsedMeta &&+ typeof parsedMeta.width === "number" &&+ typeof parsedMeta.height === "number";if (isImage) {return {@@ -67,7 +77,16 @@ export const formatAsset = ({};}- // Default to file type for everything else (including videos)+ if (isVideo) {+ return {+ ...base,+ type: "video",+ format: file.format,+ meta: videoMeta.parse(parsedMeta),+ };+ }++ // Default to file type for everything elsereturn {...base,type: "file",diff --git a/packages/cli/src/commands/api-command.ts b/packages/cli/src/commands/api-command.tsindex dacecbc81d..5963d45205 100644--- a/packages/cli/src/commands/api-command.ts+++ b/packages/cli/src/commands/api-command.ts@@ -1,7 +1,7 @@import { readFile } from "node:fs/promises";import * as httpClient from "@webstudio-is/http-client";import type { MarketplaceProduct } from "@webstudio-is/project-build";-import type { PageRedirect } from "@webstudio-is/sdk";+import type { AssetType, PageRedirect } from "@webstudio-is/sdk";import { isFileExists } from "../fs-utils";import { HandledCliError } from "../errors";import {@@ -1408,7 +1408,7 @@ export type ApiCommandOptions = {withUsage?: boolean;includeSystem?: boolean;scopeInstance?: string;- type?: "image" | "font" | "file";+ type?: AssetType;sort?: "name" | "usage" | "size" | "createdAt";cursor?: string;limit?: number;diff --git a/packages/cli/src/commands/schema.test.ts b/packages/cli/src/commands/schema.test.tsindex 0ef2be5211..f4d1f5232b 100644--- a/packages/cli/src/commands/schema.test.ts+++ b/packages/cli/src/commands/schema.test.ts@@ -168,7 +168,7 @@ test("prints compact mcp tool summaries as json by default", () => {inputSchema,}));- expect(JSON.stringify(handshakePayload).length).toBeLessThan(200_000);+ expect(JSON.stringify(handshakePayload).length).toBeLessThan(201_000);expect(JSON.stringify(expectedTools.find(({ name }) => name === "insert-page-transfer-item")diff --git a/packages/http-client/src/index.test.ts b/packages/http-client/src/index.test.tsindex 4a801d174f..ee8a7d6bd0 100644--- a/packages/http-client/src/index.test.ts+++ b/packages/http-client/src/index.test.ts@@ -1490,6 +1490,19 @@ test("uploads project asset descriptors with local data readers", async () => {})).resolves.toEqual({ uploaded: [uploadedAsset] });+ await expect(+ uploadProjectAsset({+ ...apiParams,+ asset: {+ name: "video.mp4",+ type: "video",+ format: "mp4",+ meta: { width: 1920, height: 1080 },+ },+ readAssetData: async () => new Uint8Array([1, 2, 3]),+ })+ ).resolves.toEqual({ uploaded: [uploadedAsset] });+await expect(uploadProjectAssets({...apiParams,@@ -1516,6 +1529,10 @@ test("uploads project asset descriptors with local data readers", async () => {expect(new Headers(calls[0][1].headers).get("x-webstudio-asset-meta")).toBe(JSON.stringify({ width: 10, height: 20 }));+ const videoUrl = new URL(calls[1][0].toString());+ expect(videoUrl.searchParams.get("type")).toBe("video");+ expect(videoUrl.searchParams.get("width")).toBe("1920");+ expect(videoUrl.searchParams.get("height")).toBe("1080");});test("updates asset content through the stable asset revision endpoint", async () => {diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.tsindex 75011c096e..c07cd99946 100644--- a/packages/http-client/src/index.ts+++ b/packages/http-client/src/index.ts@@ -401,7 +401,7 @@ const getAssetUploadUrl = ({if (asset.folderId !== undefined) {url.searchParams.set("folderId", asset.folderId);}- if (asset.type === "image") {+ if (asset.type === "image" || asset.type === "video") {url.searchParams.set("width", String(asset.meta.width));url.searchParams.set("height", String(asset.meta.height));}@@ -550,7 +550,7 @@ const toUploadAsset = ({size: 0,createdAt: new Date().toISOString(),};- if (descriptor.type === "image") {+ if (descriptor.type === "image" || descriptor.type === "video") {const width = descriptor.meta?.width;const height = descriptor.meta?.height;if (@@ -559,12 +559,12 @@ const toUploadAsset = ({descriptor.format === undefined) {throw new Error(- `Image asset "${descriptor.name}" requires format, meta.width, and meta.height.`+ `${descriptor.type === "image" ? "Image" : "Video"} asset "${descriptor.name}" requires format, meta.width, and meta.height.`);}return {...base,- type: "image",+ type: descriptor.type,format: descriptor.format,meta: { width, height },};diff --git a/packages/project-build/src/contracts/__generated__/runtime-operation-contracts.ts b/packages/project-build/src/contracts/__generated__/runtime-operation-contracts.tsindex ae84761994..a8b6c0c925 100644--- a/packages/project-build/src/contracts/__generated__/runtime-operation-contracts.ts+++ b/packages/project-build/src/contracts/__generated__/runtime-operation-contracts.ts@@ -3864,6 +3864,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -6986,6 +7052,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -10119,6 +10251,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -13241,6 +13439,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -19077,6 +19341,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -22407,6 +22737,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -36969,6 +37365,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -40170,6 +40632,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -46478,6 +47006,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -52289,6 +52883,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {@@ -70287,7 +70947,7 @@ export const runtimeOperationContractData = [properties: {type: {type: "string",- enum: ["font", "image", "file"],+ enum: ["font", "image", "video", "file"],},sort: {type: "string",@@ -70334,7 +70994,7 @@ export const runtimeOperationContractData = [},type: {type: "string",- enum: ["font", "image", "file"],+ enum: ["font", "image", "video", "file"],},size: {type: "number",@@ -70377,7 +71037,7 @@ export const runtimeOperationContractData = [},type: {type: "string",- enum: ["font", "image", "file"],+ enum: ["font", "image", "video", "file"],},size: {type: "number",@@ -70515,7 +71175,7 @@ export const runtimeOperationContractData = [},type: {type: "string",- enum: ["font", "image", "file"],+ enum: ["font", "image", "video", "file"],},size: {type: "number",@@ -70965,7 +71625,7 @@ export const runtimeOperationContractData = [},],description:- "Type-specific metadata: family and style plus weight for static fonts or variationAxes for variable fonts, width/height for images, and no fields for generic files.",+ "Type-specific metadata: family and style plus weight for static fonts or variationAxes for variable fonts, width/height for images and videos, and no fields for generic files.",},},required: [],@@ -71279,6 +71939,72 @@ export const runtimeOperationContractData = ["type",],},+ {+ type: "object",+ properties: {+ id: {+ type: "string",+ },+ size: {+ type: "number",+ },+ name: {+ type: "string",+ },+ filename: {+ type: "string",+ },+ description: {+ anyOf: [+ {+ type: "string",+ },+ {+ type: "null",+ },+ ],+ },+ folderId: {+ type: "string",+ minLength: 1,+ maxLength: 256,+ },+ createdAt: {+ type: "string",+ },+ updatedAt: {+ type: "string",+ },+ format: {+ type: "string",+ },+ meta: {+ type: "object",+ properties: {+ width: {+ type: "number",+ },+ height: {+ type: "number",+ },+ },+ required: ["width", "height"],+ },+ type: {+ type: "string",+ const: "video",+ },+ },+ required: [+ "id",+ "size",+ "name",+ "createdAt",+ "format",+ "meta",+ "type",+ ],+ },{type: "object",properties: {diff --git a/packages/project-build/src/runtime/assets.test.ts b/packages/project-build/src/runtime/assets.test.tsindex 1e60545b2d..0a39a47775 100644--- a/packages/project-build/src/runtime/assets.test.ts+++ b/packages/project-build/src/runtime/assets.test.ts@@ -146,11 +146,11 @@ describe("asset upload helpers", () => {).toThrow('MIME type "script/*" is not allowed');});- test("accepts only stored asset types for API uploads", () => {+ test("accepts every asset type for API uploads", () => {expect(parseAssetType("image")).toBe("image");expect(parseAssetType("font")).toBe("font");expect(parseAssetType("file")).toBe("file");- expect(parseAssetType("video")).toBeUndefined();+ expect(parseAssetType("video")).toBe("video");expect(parseAssetType(null)).toBeUndefined();});diff --git a/packages/project-build/src/runtime/assets.ts b/packages/project-build/src/runtime/assets.tsindex 4e24397d39..8e5e482452 100644--- a/packages/project-build/src/runtime/assets.ts+++ b/packages/project-build/src/runtime/assets.ts@@ -25,6 +25,7 @@ import {fileAsset,fontAsset,imageAsset,+ videoAsset,} from "@webstudio-is/sdk";import {appendOptionalPropertyPatch,@@ -105,7 +106,7 @@ export const assetUpdateInput = z.object({folderId: z.union([z.string().min(1), z.null()]).optional(),meta: assetMetaUpdate.describe(- "Type-specific metadata: family and style plus weight for static fonts or variationAxes for variable fonts, width/height for images, and no fields for generic files."+ "Type-specific metadata: family and style plus weight for static fonts or variationAxes for variable fonts, width/height for images and videos, and no fields for generic files.").optional(),})@@ -174,6 +175,7 @@ export const imageDescriptionsSetInput = zconst addableAsset = z.union([fontAsset.omit({ projectId: true }),imageAsset.omit({ projectId: true }),+ videoAsset.omit({ projectId: true }),fileAsset.omit({ projectId: true }),]);diff --git a/packages/protocol/src/builder-api/local-operation-inputs.ts b/packages/protocol/src/builder-api/local-operation-inputs.tsindex 9728f3abda..e20b30295a 100644--- a/packages/protocol/src/builder-api/local-operation-inputs.ts+++ b/packages/protocol/src/builder-api/local-operation-inputs.ts@@ -1,11 +1,11 @@import { z } from "zod";import { getInputSchemaMetadata } from "@webstudio-is/project-build/contracts";-import type { InputJsonSchema } from "@webstudio-is/sdk";+import { assetType, type InputJsonSchema } from "@webstudio-is/sdk";import type { PublicApiOperationNamespace } from "./runtime-contracts";const assetUploadDescriptor = z.object({name: z.string(),- type: z.enum(["image", "font", "file"]),+ type: assetType,format: z.string().optional(),description: z.string().optional(),folderId: z.string().min(1).optional(),diff --git a/packages/protocol/src/builder-api/operations.test.ts b/packages/protocol/src/builder-api/operations.test.tsindex 6f684b49c5..ce69a957e5 100644--- a/packages/protocol/src/builder-api/operations.test.ts+++ b/packages/protocol/src/builder-api/operations.test.ts@@ -1,5 +1,5 @@import { describe, expect, test } from "vitest";-import { getInputJsonSchemaMetadata } from "@webstudio-is/sdk";+import { assetType, getInputJsonSchemaMetadata } from "@webstudio-is/sdk";import * as protocol from "../index";import {getPublicApiOperation,@@ -308,6 +308,20 @@ describe("public api operation catalog", () => {expect(JSON.stringify(uploadMany.inputSchema)).toContain('"force"');});+ test("exposes every supported upload type to MCP", () => {+ const uploadAssetSchema =+ getPublicApiOperation("upload-asset").inputSchema?.properties?.asset;+ const assetTypeSchema =+ uploadAssetSchema !== undefined &&+ typeof uploadAssetSchema === "object" &&+ uploadAssetSchema.properties?.type;++ expect(assetTypeSchema).toMatchObject({+ type: "string",+ enum: assetType.options,+ });+ });+test("keeps operation lookup and tRPC path lookup strict", () => {expect(getPublicApiOperation("list-pages").id).toBe("pages.list");expect(getPublicApiOperationPath("list-pages")).toBe("api.pages.list");diff --git a/packages/sdk/src/assets.test.ts b/packages/sdk/src/assets.test.tsindex 8b6852f641..a836a57f5e 100644--- a/packages/sdk/src/assets.test.ts+++ b/packages/sdk/src/assets.test.ts@@ -1,5 +1,6 @@import { describe, test, expect } from "vitest";import { fontMeta } from "@webstudio-is/fonts";+import { assetType } from "./schema/assets";import {ALLOWED_FILE_TYPES,getMimeTypeByExtension,@@ -460,6 +461,20 @@ describe("allowed-file-types", () => {});describe("detectAssetType", () => {+ test("detects only canonical asset types", () => {+ expect(assetType.options).toEqual(["font", "image", "video", "file"]);+ for (const filename of [+ "image.png",+ "font.woff2",+ "video.mp4",+ "document.pdf",+ ]) {+ expect(assetType.safeParse(detectAssetType(filename)).success).toBe(+ true+ );+ }+ });+test("detects image files", () => {expect(detectAssetType("photo.jpg")).toBe("image");expect(detectAssetType("image.png")).toBe("image");diff --git a/packages/sdk/src/assets.ts b/packages/sdk/src/assets.tsindex ea24cda642..901ef6cc7c 100644--- a/packages/sdk/src/assets.ts+++ b/packages/sdk/src/assets.ts@@ -1,5 +1,5 @@import warnOnce from "warn-once";-import type { Asset } from "./schema/assets";+import type { Asset, AssetType } from "./schema/assets";export const MIME_CATEGORIES = ["image",@@ -402,7 +402,7 @@ export const getAssetMime = ({type,format,}: {- type: "image" | "font" | "file";+ type: AssetType;format: string;}): string | undefined => {const lowerFormat = format.toLowerCase();@@ -493,9 +493,7 @@ export const validateFileName = (/*** Detect the asset type from a file based on its extension*/-export const detectAssetType = (- fileName: string-): "image" | "font" | "video" | "file" => {+export const detectAssetType = (fileName: string): AssetType => {const ext = getFileExtension(fileName)?.toLowerCase();if (!ext) {return "file";@@ -595,6 +593,18 @@ const extractFontMetadata = (asset: Asset): RuntimeMetadata => {return metadata;};+const extractVideoMetadata = (asset: Asset): RuntimeMetadata => {+ if (asset.type !== "video") {+ return;+ }+ if (asset.meta.width && asset.meta.height) {+ return {+ width: asset.meta.width,+ height: asset.meta.height,+ };+ }+};+const extractFileMetadata = (_asset: Asset): RuntimeMetadata => {// Generic files don't need additional metadata at runtimereturn;@@ -606,6 +616,7 @@ const metadataExtractors: Record<> = {image: extractImageMetadata,font: extractFontMetadata,+ video: extractVideoMetadata,file: extractFileMetadata,};diff --git a/packages/sdk/src/schema/assets.test.ts b/packages/sdk/src/schema/assets.test.tsindex 1e88b61824..b32d31fc51 100644--- a/packages/sdk/src/schema/assets.test.ts+++ b/packages/sdk/src/schema/assets.test.ts@@ -13,6 +13,9 @@ describe("mergeAssetMeta", () => {expect(mergeAssetMeta("image", { width: 100, height: 200 }, { width: 300 })).toEqual({ width: 300, height: 200 });+ expect(+ mergeAssetMeta("video", { width: 1920, height: 1080 }, { width: 1280 })+ ).toEqual({ width: 1280, height: 1080 });});test("rejects invalid and unsupported metadata", () => {diff --git a/packages/sdk/src/schema/assets.ts b/packages/sdk/src/schema/assets.tsindex b7c7c8bea4..62e04038af 100644--- a/packages/sdk/src/schema/assets.ts+++ b/packages/sdk/src/schema/assets.ts@@ -21,7 +21,7 @@ const baseAsset = {updatedAt: z.string().optional(),};-export const assetType = z.enum(["font", "image", "file"]);+export const assetType = z.enum(["font", "image", "video", "file"]);export type AssetType = z.infer<typeof assetType>;export const fontAsset = z.object({@@ -38,6 +38,12 @@ export const imageMeta = z.object({});export type ImageMeta = z.infer<typeof imageMeta>;+export const videoMeta = z.object({+ width: z.number(),+ height: z.number(),+});+export type VideoMeta = z.infer<typeof videoMeta>;+export const assetMetaUpdate = z.union([fontMetaUpdate,imageMeta.partial().strict(),@@ -52,6 +58,14 @@ export const imageAsset = z.object({});export type ImageAsset = z.infer<typeof imageAsset>;+export const videoAsset = z.object({+ ...baseAsset,+ format: z.string(),+ meta: videoMeta,+ type: z.literal(assetType.enum.video),+});+export type VideoAsset = z.infer<typeof videoAsset>;+export const fileAsset = z.object({...baseAsset,format: z.string(),@@ -60,11 +74,12 @@ export const fileAsset = z.object({});export type FileAsset = z.infer<typeof fileAsset>;-export const asset = z.union([fontAsset, imageAsset, fileAsset]);+export const asset = z.union([fontAsset, imageAsset, videoAsset, fileAsset]);export type Asset = z.infer<typeof asset>;const assetMetaSchemas = {image: imageMeta,+ video: videoMeta,file: z.object({}),} as const satisfies Record<Exclude<AssetType, "font">, z.ZodType>;