mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-09 22:14:29 +09:00
fix: omit raw format from direct image URLs
This commit is contained in:
1 parent
c44ef705cf
commit
86357c8474
5 files changed
+10
-18
No files matched your search
@@ -36,12 +36,8 @@ test("resolves asset IDs and relative paths in Markdown images and links", () =>
|
||||
origin: "https://builder.example",
|
||||
});
|
||||
|
||||
expect(html).toContain(
|
||||
'src="https://builder.example/cgi/image/image.png?format=raw"'
|
||||
);
|
||||
expect(html).toContain(
|
||||
'href="https://builder.example/cgi/image/image.png?format=raw"'
|
||||
);
|
||||
expect(html).toContain('src="https://builder.example/cgi/image/image.png"');
|
||||
expect(html).toContain('href="https://builder.example/cgi/image/image.png"');
|
||||
expect(html).toContain('src="https://example.com/image.png"');
|
||||
});
|
||||
|
||||
|
||||
@@ -136,9 +136,7 @@ test("downloads asset files when they are missing from the synced asset cache",
|
||||
await expect(readFile("public/assets/image.png", "utf8")).resolves.toBe(
|
||||
"downloaded"
|
||||
);
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
"https://example.com/cgi/image/image.png?format=raw"
|
||||
);
|
||||
expect(fetch).toHaveBeenCalledWith("https://example.com/cgi/image/image.png");
|
||||
});
|
||||
|
||||
test("retries asset download once after a server error", async () => {
|
||||
|
||||
@@ -2558,7 +2558,7 @@ describe("prebuild", () => {
|
||||
template: ["defaults"],
|
||||
});
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
"https://assets.example/cgi/image/image.png?format=raw"
|
||||
"https://assets.example/cgi/image/image.png"
|
||||
);
|
||||
expect(consoleWarn).not.toHaveBeenCalled();
|
||||
expect(consoleError).toHaveBeenCalledWith(
|
||||
|
||||
@@ -593,11 +593,9 @@ describe("allowed-file-types", () => {
|
||||
|
||||
test("generates correct URL for image assets", () => {
|
||||
const url = getAssetUrl(mockImageAsset, "https://example.com");
|
||||
expect(url.href).toBe(
|
||||
"https://example.com/cgi/image/photo.jpg?format=raw"
|
||||
);
|
||||
expect(url.href).toBe("https://example.com/cgi/image/photo.jpg");
|
||||
expect(url.pathname).toBe("/cgi/image/photo.jpg");
|
||||
expect(url.search).toBe("?format=raw");
|
||||
expect(url.search).toBe("");
|
||||
});
|
||||
|
||||
test.each(["bmp", "ico", "avif"])(
|
||||
@@ -1048,7 +1046,7 @@ describe("allowed-file-types", () => {
|
||||
test("converts image asset with all fields", () => {
|
||||
const result = toRuntimeAsset(mockImageAsset, "https://example.com");
|
||||
expect(result).toEqual({
|
||||
url: "/cgi/image/photo.jpg?format=raw",
|
||||
url: "/cgi/image/photo.jpg",
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
});
|
||||
@@ -1086,8 +1084,8 @@ describe("allowed-file-types", () => {
|
||||
const result1 = toRuntimeAsset(mockImageAsset, "https://cdn.example.com");
|
||||
const result2 = toRuntimeAsset(mockImageAsset, "http://localhost:3000");
|
||||
// Both should return the same relative URL
|
||||
expect(result1.url).toBe("/cgi/image/photo.jpg?format=raw");
|
||||
expect(result2.url).toBe("/cgi/image/photo.jpg?format=raw");
|
||||
expect(result1.url).toBe("/cgi/image/photo.jpg");
|
||||
expect(result2.url).toBe("/cgi/image/photo.jpg");
|
||||
});
|
||||
|
||||
test("handles image without dimensions", () => {
|
||||
|
||||
@@ -543,7 +543,7 @@ export const getAssetUrl = (
|
||||
origin: string
|
||||
): URL => {
|
||||
const path = isResizableImageFileName(asset.name)
|
||||
? `/cgi/image/${asset.name}?format=raw`
|
||||
? `/cgi/image/${asset.name}`
|
||||
: `/cgi/asset/${asset.name}?format=raw`;
|
||||
return new URL(path, origin);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user