Skip to content

Commit 514ad3c

Browse files
committed
Ignore other options when onlyPresets is true
1 parent 05a459a commit 514ad3c

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

src/methods/generateImageInfoUrl.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,20 @@ describe("generateImageInfoUrl", () => {
9898
)
9999
).toEqual("/test:test2/plain/https://example.com/host/pic.png");
100100
});
101+
102+
it("should ignore other options with `onlyPresets` setting", () => {
103+
expect(
104+
generateUrl(
105+
{ value: "https://example.com/host/pic.png", type: "plain" },
106+
{
107+
preset: ["test", "test2"],
108+
crop: {
109+
width: 100,
110+
height: 100,
111+
},
112+
},
113+
{ onlyPresets: true }
114+
)
115+
).toEqual("/test:test2/plain/https://example.com/host/pic.png");
116+
});
101117
});

src/methods/generateImageInfoUrl.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export type URLImageInfo = {
1414
type: "plain" | "base64" | "encrypted";
1515
};
1616

17+
const allModules = Object.values(optionModules);
18+
const presetOnlyModule = [optionModules.preset];
19+
1720
const generateImageInfoUrl = (
1821
url: URLImageInfo,
1922
options?: OptionsImageInfo,
@@ -29,7 +32,9 @@ const generateImageInfoUrl = (
2932

3033
let optsPart = "";
3134
if (options) {
32-
for (const [, optionModule] of Object.entries(optionModules)) {
35+
const modules = settings?.onlyPresets ? presetOnlyModule : allModules;
36+
37+
for (const optionModule of modules) {
3338
if (optionModule.test(options)) {
3439
optsPart += "/";
3540
optsPart += optionModule.build(options, settings);

src/methods/generateUrl.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,27 @@ describe("generateUrl", () => {
7070
"/bl:5/el:t/ex:t:nowe::5/f:webp/h:150/q:80/w:150/z:1.5/plain/https://example.com/host/pic.png"
7171
);
7272
});
73+
74+
it("should work with `onlyPresets` setting", () => {
75+
expect(
76+
generateUrl(
77+
{ value: "https://example.com/host/pic.png", type: "plain" },
78+
{
79+
preset: ["preset1", "preset2"],
80+
width: 150,
81+
height: 150,
82+
format: "webp",
83+
quality: 80,
84+
enlarge: "t",
85+
extend: {
86+
extend: 1,
87+
gravity: { type: "nowe", y_offset: 5 },
88+
},
89+
blur: 5,
90+
zoom: 1.5,
91+
},
92+
{ onlyPresets: true }
93+
)
94+
).toEqual("/preset1:preset2/plain/https://example.com/host/pic.png");
95+
});
7396
});

src/methods/generateUrl.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const correctUrlTypes = {
1010
encrypted: true,
1111
};
1212

13+
const allModules = Object.values(optionModules);
14+
const presetOnlyModule = [optionModules.preset];
15+
1316
const generateUrl = (
1417
url: URLImageInfo,
1518
options?: Options,
@@ -25,7 +28,9 @@ const generateUrl = (
2528

2629
let optsPart = "";
2730
if (options) {
28-
for (const [, optionModule] of Object.entries(optionModules)) {
31+
const modules = settings?.onlyPresets ? presetOnlyModule : allModules;
32+
33+
for (const optionModule of modules) {
2934
if (optionModule.test(options)) {
3035
optsPart += "/";
3136
optsPart += optionModule.build(options, settings);

0 commit comments

Comments
 (0)