Skip to content

Commit deb740f

Browse files
committed
Fix keyMap and test issue, add to async provider map
1 parent 744cd1e commit deb740f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/async.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const asyncProviderMap: AsyncProviderMap = {
4040
uploadcare: () => import("./providers/uploadcare.ts"),
4141
vercel: () => import("./providers/vercel.ts"),
4242
wordpress: () => import("./providers/wordpress.ts"),
43+
wsrv: () => import("./providers/wsrv.ts"),
4344
};
4445

4546
/**

src/providers/wsrv.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ Deno.test("wsrv extract", async (t) => {
1515

1616
await t.step("should parse operations from URL", () => {
1717
const { operations, src } = extract(
18-
"https://wsrv.nl/?url=example.com/image.jpg&w=300&h=200&q=85&output=webp&fit=cover&dpr=2",
18+
"https://wsrv.nl/?url=example.com/image.jpg&w=300&h=200&q=85&output=webp&fit=cover",
1919
) ?? {};
2020
assertEquals(src, "https://example.com/image.jpg");
2121
assertEquals(operations?.width, 300);
2222
assertEquals(operations?.height, 200);
2323
assertEquals(operations?.quality, 85);
2424
assertEquals(operations?.format, "webp");
2525
assertEquals(operations?.fit, "cover");
26-
assertEquals(operations?.dpr, 2);
2726
});
2827

2928
await t.step("should return null for non-wsrv URLs", () => {

src/providers/wsrv.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,20 @@ export type WsrvFormats =
2222

2323
/**
2424
* Image transform options for wsrv.nl image processing.
25-
* Note: width, height, format, and quality are inherited from Operations.
2625
*/
2726
export interface WsrvOperations extends Operations<WsrvFormats> {
27+
/** Sets the width of the image in pixels. Alias for width. */
28+
w?: number;
29+
30+
/** Sets the height of the image in pixels. Alias for height. */
31+
h?: number;
32+
33+
/** Output format. Alias for format. */
34+
output?: WsrvFormats;
35+
36+
/** Quality level (0-100). Alias for quality. */
37+
q?: number;
38+
2839
/** Sets the output density of the image (1-8). */
2940
dpr?: number;
3041

@@ -128,24 +139,23 @@ const { operationsGenerator, operationsParser } = createOperationsHandlers<
128139
defaults: {
129140
fit: "cover",
130141
},
131-
srcParam: "url",
132142
});
133143

134144
export const extract: URLExtractor<"wsrv"> = (url) => {
135145
const urlObj = toUrl(url);
136146

137-
// wsrv.nl URLs have the source image in the 'url' parameter
138147
const srcParam = urlObj.searchParams.get("url");
139148
if (!srcParam) {
140149
return null;
141150
}
142151

143-
// The source URL might need protocol added
144152
let src = srcParam;
145153
if (!src.startsWith("http://") && !src.startsWith("https://")) {
146154
src = "https://" + src;
147155
}
148156

157+
urlObj.searchParams.delete("url");
158+
149159
const operations = operationsParser(urlObj);
150160

151161
return {
@@ -157,12 +167,10 @@ export const extract: URLExtractor<"wsrv"> = (url) => {
157167
export const generate: URLGenerator<"wsrv"> = (src, operations) => {
158168
const url = new URL("https://wsrv.nl/");
159169

160-
// Add the source URL (remove protocol for cleaner URLs)
161170
const srcUrl = typeof src === "string" ? src : src.toString();
162171
const cleanSrc = srcUrl.replace(/^https?:\/\//, "");
163172
url.searchParams.set("url", cleanSrc);
164173

165-
// Add operations as query parameters
166174
const params = operationsGenerator(operations);
167175
const searchParams = new URLSearchParams(params);
168176
for (const [key, value] of searchParams) {

0 commit comments

Comments
 (0)