Skip to content

Commit a9f838a

Browse files
authored
fix: upload unoptimized inception images (#5419)
This fixes the issue with uploading avif which is not supported as image source.
1 parent 6501763 commit a9f838a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

apps/builder/app/shared/copy-paste/asset-upload.test.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from "vitest";
1+
import { expect, test, vi } from "vitest";
22
import { $, AssetValue, renderTemplate } from "@webstudio-is/template";
33
import type { StyleDecl, WebstudioFragment } from "@webstudio-is/sdk";
44
import { denormalizeSrcProps } from "./asset-upload";
@@ -128,3 +128,25 @@ test("it works well with no background-images", async () => {
128128

129129
expect(denormalizedAssetIds).toEqual(inputUrls.map(src2AssetId));
130130
});
131+
132+
test("upload raw inception images", async () => {
133+
const data = renderTemplate(
134+
<$.Body ws:id="boxA">
135+
<$.Image
136+
ws:id="imageA"
137+
src="https://preview.webstudio.ai/cgi/image/dev/5036ed5c3dfce99eaac566a06bc3729620354a364357907a523f1feb2d6fb819.png?width=1024&height=1024&format=auto"
138+
></$.Image>
139+
</$.Body>
140+
);
141+
const uploadImages = vi.fn(async (srcs: string[]) => {
142+
return new Map(srcs.map((src) => [src, src]));
143+
});
144+
await denormalizeSrcProps(
145+
data,
146+
uploadImages,
147+
(instanceId, propName) => `${instanceId}:${propName}`
148+
);
149+
expect(uploadImages).toBeCalledWith([
150+
"https://preview.webstudio.ai/cgi/image/dev/5036ed5c3dfce99eaac566a06bc3729620354a364357907a523f1feb2d6fb819.png?format=raw",
151+
]);
152+
});

apps/builder/app/shared/copy-paste/asset-upload.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ const extractSrcProps = (
2424
imageComponentsSet.has(prop.instanceId)
2525
) {
2626
try {
27-
srcProps.push([prop.id, new URL(prop.value).href]);
27+
const url = new URL(prop.value);
28+
// upload raw images from inception
29+
if (url.hostname === "preview.webstudio.ai") {
30+
url.search = "";
31+
url.searchParams.set("format", "raw");
32+
}
33+
srcProps.push([prop.id, url.href]);
2834
} catch {
2935
// ignore when invalid url
3036
}

0 commit comments

Comments
 (0)