Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion apps/builder/app/shared/copy-paste/asset-upload.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from "vitest";
import { expect, test, vi } from "vitest";
import { $, AssetValue, renderTemplate } from "@webstudio-is/template";
import type { StyleDecl, WebstudioFragment } from "@webstudio-is/sdk";
import { denormalizeSrcProps } from "./asset-upload";
Expand Down Expand Up @@ -128,3 +128,25 @@ test("it works well with no background-images", async () => {

expect(denormalizedAssetIds).toEqual(inputUrls.map(src2AssetId));
});

test("upload raw inception images", async () => {
const data = renderTemplate(
<$.Body ws:id="boxA">
<$.Image
ws:id="imageA"
src="https://preview.webstudio.ai/cgi/image/dev/5036ed5c3dfce99eaac566a06bc3729620354a364357907a523f1feb2d6fb819.png?width=1024&height=1024&format=auto"
></$.Image>
</$.Body>
);
const uploadImages = vi.fn(async (srcs: string[]) => {
return new Map(srcs.map((src) => [src, src]));
});
await denormalizeSrcProps(
data,
uploadImages,
(instanceId, propName) => `${instanceId}:${propName}`
);
expect(uploadImages).toBeCalledWith([
"https://preview.webstudio.ai/cgi/image/dev/5036ed5c3dfce99eaac566a06bc3729620354a364357907a523f1feb2d6fb819.png?format=raw",
]);
});
8 changes: 7 additions & 1 deletion apps/builder/app/shared/copy-paste/asset-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ const extractSrcProps = (
imageComponentsSet.has(prop.instanceId)
) {
try {
srcProps.push([prop.id, new URL(prop.value).href]);
const url = new URL(prop.value);
// upload raw images from inception
if (url.hostname === "preview.webstudio.ai") {
url.search = "";
url.searchParams.set("format", "raw");
}
srcProps.push([prop.id, url.href]);
} catch {
// ignore when invalid url
}
Expand Down
Loading