ipx 1.0.0-2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +6 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{ipx.d1cfdfa2.mjs → ipx.5d237d4e.mjs} +75 -37
- package/dist/shared/{ipx.399255f0.cjs → ipx.b2d1c1dd.cjs} +89 -43
- package/package.json +25 -26
package/dist/cli.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const consola = require('consola');
|
|
4
4
|
const listhen = require('listhen');
|
|
5
|
-
const middleware = require('./shared/ipx.
|
|
5
|
+
const middleware = require('./shared/ipx.b2d1c1dd.cjs');
|
|
6
6
|
require('defu');
|
|
7
7
|
require('image-meta');
|
|
8
8
|
require('ufo');
|
|
@@ -15,6 +15,10 @@ require('destr');
|
|
|
15
15
|
require('etag');
|
|
16
16
|
require('xss');
|
|
17
17
|
|
|
18
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
19
|
+
|
|
20
|
+
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
|
21
|
+
|
|
18
22
|
async function main() {
|
|
19
23
|
const ipx = middleware.createIPX({});
|
|
20
24
|
const middleware$1 = middleware.createIPXMiddleware(ipx);
|
|
@@ -23,6 +27,6 @@ async function main() {
|
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
main().catch((error) => {
|
|
26
|
-
|
|
30
|
+
consola__default.error(error);
|
|
27
31
|
process.exit(1);
|
|
28
32
|
});
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import consola from 'consola';
|
|
2
2
|
import { listen } from 'listhen';
|
|
3
|
-
import { c as createIPX, a as createIPXMiddleware } from './shared/ipx.
|
|
3
|
+
import { c as createIPX, a as createIPXMiddleware } from './shared/ipx.5d237d4e.mjs';
|
|
4
4
|
import 'defu';
|
|
5
5
|
import 'image-meta';
|
|
6
6
|
import 'ufo';
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -12,38 +12,38 @@ import xss from 'xss';
|
|
|
12
12
|
|
|
13
13
|
const Handlers = {
|
|
14
14
|
__proto__: null,
|
|
15
|
-
get
|
|
16
|
-
get fit () { return fit; },
|
|
17
|
-
get position () { return position; },
|
|
15
|
+
get b () { return b; },
|
|
18
16
|
get background () { return background; },
|
|
17
|
+
get blur () { return blur; },
|
|
18
|
+
get crop () { return crop; },
|
|
19
19
|
get enlarge () { return enlarge; },
|
|
20
|
-
get width () { return width; },
|
|
21
|
-
get height () { return height; },
|
|
22
|
-
get resize () { return resize; },
|
|
23
|
-
get trim () { return trim; },
|
|
24
20
|
get extend () { return extend; },
|
|
25
21
|
get extract () { return extract; },
|
|
26
|
-
get
|
|
22
|
+
get fit () { return fit; },
|
|
23
|
+
get flatten () { return flatten; },
|
|
27
24
|
get flip () { return flip; },
|
|
28
25
|
get flop () { return flop; },
|
|
29
|
-
get sharpen () { return sharpen; },
|
|
30
|
-
get median () { return median; },
|
|
31
|
-
get blur () { return blur; },
|
|
32
|
-
get flatten () { return flatten; },
|
|
33
26
|
get gamma () { return gamma; },
|
|
27
|
+
get grayscale () { return grayscale; },
|
|
28
|
+
get h () { return h; },
|
|
29
|
+
get height () { return height; },
|
|
30
|
+
get median () { return median; },
|
|
31
|
+
get modulate () { return modulate; },
|
|
34
32
|
get negate () { return negate; },
|
|
35
33
|
get normalize () { return normalize; },
|
|
34
|
+
get pos () { return pos; },
|
|
35
|
+
get position () { return position; },
|
|
36
|
+
get q () { return q; },
|
|
37
|
+
get quality () { return quality; },
|
|
38
|
+
get resize () { return resize; },
|
|
39
|
+
get rotate () { return rotate; },
|
|
40
|
+
get s () { return s; },
|
|
41
|
+
get sharpen () { return sharpen; },
|
|
36
42
|
get threshold () { return threshold; },
|
|
37
|
-
get modulate () { return modulate; },
|
|
38
43
|
get tint () { return tint; },
|
|
39
|
-
get
|
|
40
|
-
get crop () { return crop; },
|
|
41
|
-
get q () { return q; },
|
|
42
|
-
get b () { return b; },
|
|
44
|
+
get trim () { return trim; },
|
|
43
45
|
get w () { return w; },
|
|
44
|
-
get
|
|
45
|
-
get s () { return s; },
|
|
46
|
-
get pos () { return pos; }
|
|
46
|
+
get width () { return width; }
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
function getEnv(name, defaultValue) {
|
|
@@ -111,12 +111,14 @@ const createHTTPSource = (options) => {
|
|
|
111
111
|
if (typeof _domains === "string") {
|
|
112
112
|
_domains = _domains.split(",").map((s) => s.trim());
|
|
113
113
|
}
|
|
114
|
-
const domains = new Set(
|
|
115
|
-
|
|
116
|
-
d
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
const domains = new Set(
|
|
115
|
+
_domains.map((d) => {
|
|
116
|
+
if (!HTTP_RE.test(d)) {
|
|
117
|
+
d = "http://" + d;
|
|
118
|
+
}
|
|
119
|
+
return new URL(d).hostname;
|
|
120
|
+
}).filter(Boolean)
|
|
121
|
+
);
|
|
120
122
|
return async (id, requestOptions) => {
|
|
121
123
|
const hostname = new URL(id).hostname;
|
|
122
124
|
if (!hostname) {
|
|
@@ -126,11 +128,16 @@ const createHTTPSource = (options) => {
|
|
|
126
128
|
throw createError("Forbidden host", 403, hostname);
|
|
127
129
|
}
|
|
128
130
|
const response = await fetch(id, {
|
|
131
|
+
// @ts-ignore
|
|
129
132
|
agent: id.startsWith("https") ? httpsAgent : httpAgent,
|
|
130
133
|
...options.fetchOptions
|
|
131
134
|
});
|
|
132
135
|
if (!response.ok) {
|
|
133
|
-
throw createError(
|
|
136
|
+
throw createError(
|
|
137
|
+
"Fetch error",
|
|
138
|
+
response.status || 500,
|
|
139
|
+
response.statusText
|
|
140
|
+
);
|
|
134
141
|
}
|
|
135
142
|
let maxAge = options.maxAge;
|
|
136
143
|
const _cacheControl = response.headers.get("cache-control");
|
|
@@ -148,7 +155,10 @@ const createHTTPSource = (options) => {
|
|
|
148
155
|
return {
|
|
149
156
|
mtime,
|
|
150
157
|
maxAge,
|
|
151
|
-
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
getData: cachedPromise(
|
|
160
|
+
() => response.arrayBuffer().then((ab) => Buffer.from(ab))
|
|
161
|
+
)
|
|
152
162
|
};
|
|
153
163
|
};
|
|
154
164
|
};
|
|
@@ -224,13 +234,17 @@ const enlarge = {
|
|
|
224
234
|
const width = {
|
|
225
235
|
args: [VArg],
|
|
226
236
|
apply: (context, pipe, width2) => {
|
|
227
|
-
return pipe.resize(width2, void 0, {
|
|
237
|
+
return pipe.resize(width2, void 0, {
|
|
238
|
+
withoutEnlargement: !context.enlarge
|
|
239
|
+
});
|
|
228
240
|
}
|
|
229
241
|
};
|
|
230
242
|
const height = {
|
|
231
243
|
args: [VArg],
|
|
232
244
|
apply: (context, pipe, height2) => {
|
|
233
|
-
return pipe.resize(void 0, height2, {
|
|
245
|
+
return pipe.resize(void 0, height2, {
|
|
246
|
+
withoutEnlargement: !context.enlarge
|
|
247
|
+
});
|
|
234
248
|
}
|
|
235
249
|
};
|
|
236
250
|
const resize = {
|
|
@@ -244,7 +258,10 @@ const resize = {
|
|
|
244
258
|
height2 = width2;
|
|
245
259
|
}
|
|
246
260
|
if (!context.enlarge) {
|
|
247
|
-
const clamped = clampDimensionsPreservingAspectRatio(context.meta, {
|
|
261
|
+
const clamped = clampDimensionsPreservingAspectRatio(context.meta, {
|
|
262
|
+
width: width2,
|
|
263
|
+
height: height2
|
|
264
|
+
});
|
|
248
265
|
width2 = clamped.width;
|
|
249
266
|
height2 = clamped.height;
|
|
250
267
|
}
|
|
@@ -385,7 +402,14 @@ const h = height;
|
|
|
385
402
|
const s = resize;
|
|
386
403
|
const pos = position;
|
|
387
404
|
|
|
388
|
-
const SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
|
|
405
|
+
const SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
|
|
406
|
+
"jpeg",
|
|
407
|
+
"png",
|
|
408
|
+
"webp",
|
|
409
|
+
"avif",
|
|
410
|
+
"tiff",
|
|
411
|
+
"gif"
|
|
412
|
+
]);
|
|
389
413
|
function createIPX(userOptions) {
|
|
390
414
|
const defaults = {
|
|
391
415
|
dir: getEnv("IPX_DIR", "."),
|
|
@@ -396,7 +420,9 @@ function createIPX(userOptions) {
|
|
|
396
420
|
sharp: {}
|
|
397
421
|
};
|
|
398
422
|
const options = defu(userOptions, defaults);
|
|
399
|
-
options.alias = Object.fromEntries(
|
|
423
|
+
options.alias = Object.fromEntries(
|
|
424
|
+
Object.entries(options.alias).map((e) => [withLeadingSlash(e[0]), e[1]])
|
|
425
|
+
);
|
|
400
426
|
const context = {
|
|
401
427
|
sources: {}
|
|
402
428
|
};
|
|
@@ -447,10 +473,16 @@ function createIPX(userOptions) {
|
|
|
447
473
|
};
|
|
448
474
|
}
|
|
449
475
|
const animated = modifiers.animated !== void 0 || modifiers.a !== void 0 || format === "gif";
|
|
450
|
-
const Sharp = await import('sharp').then(
|
|
476
|
+
const Sharp = await import('sharp').then(
|
|
477
|
+
(r) => r.default || r
|
|
478
|
+
);
|
|
451
479
|
let sharp = Sharp(data, { animated });
|
|
452
480
|
Object.assign(sharp.options, options.sharp);
|
|
453
|
-
const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({
|
|
481
|
+
const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({
|
|
482
|
+
handler: getHandler(name),
|
|
483
|
+
name,
|
|
484
|
+
args: arguments_
|
|
485
|
+
})).filter((h) => h.handler).sort((a, b) => {
|
|
454
486
|
const aKey = (a.handler.order || a.name || "").toString();
|
|
455
487
|
const bKey = (b.handler.order || b.name || "").toString();
|
|
456
488
|
return aKey.localeCompare(bKey);
|
|
@@ -488,7 +520,10 @@ async function _handleRequest(request, ipx) {
|
|
|
488
520
|
headers: {},
|
|
489
521
|
body: ""
|
|
490
522
|
};
|
|
491
|
-
const [modifiersString = "", ...idSegments] = request.url.slice(
|
|
523
|
+
const [modifiersString = "", ...idSegments] = request.url.slice(
|
|
524
|
+
1
|
|
525
|
+
/* leading slash */
|
|
526
|
+
).split("/");
|
|
492
527
|
const id = safeString(decode(idSegments.join("/")));
|
|
493
528
|
if (!modifiersString) {
|
|
494
529
|
throw createError("Modifiers are missing", 400, request.url);
|
|
@@ -546,7 +581,10 @@ function handleRequest(request, ipx) {
|
|
|
546
581
|
}
|
|
547
582
|
function createIPXMiddleware(ipx) {
|
|
548
583
|
return function IPXMiddleware(request, res) {
|
|
549
|
-
return handleRequest(
|
|
584
|
+
return handleRequest(
|
|
585
|
+
{ url: request.url, headers: request.headers },
|
|
586
|
+
ipx
|
|
587
|
+
).then((_res) => {
|
|
550
588
|
res.statusCode = _res.statusCode;
|
|
551
589
|
res.statusMessage = _res.statusMessage;
|
|
552
590
|
for (const name in _res.headers) {
|
|
@@ -12,44 +12,52 @@ const destr = require('destr');
|
|
|
12
12
|
const getEtag = require('etag');
|
|
13
13
|
const xss = require('xss');
|
|
14
14
|
|
|
15
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
16
|
+
|
|
17
|
+
const http__default = /*#__PURE__*/_interopDefaultCompat(http);
|
|
18
|
+
const https__default = /*#__PURE__*/_interopDefaultCompat(https);
|
|
19
|
+
const destr__default = /*#__PURE__*/_interopDefaultCompat(destr);
|
|
20
|
+
const getEtag__default = /*#__PURE__*/_interopDefaultCompat(getEtag);
|
|
21
|
+
const xss__default = /*#__PURE__*/_interopDefaultCompat(xss);
|
|
22
|
+
|
|
15
23
|
const Handlers = {
|
|
16
24
|
__proto__: null,
|
|
17
|
-
get
|
|
18
|
-
get fit () { return fit; },
|
|
19
|
-
get position () { return position; },
|
|
25
|
+
get b () { return b; },
|
|
20
26
|
get background () { return background; },
|
|
27
|
+
get blur () { return blur; },
|
|
28
|
+
get crop () { return crop; },
|
|
21
29
|
get enlarge () { return enlarge; },
|
|
22
|
-
get width () { return width; },
|
|
23
|
-
get height () { return height; },
|
|
24
|
-
get resize () { return resize; },
|
|
25
|
-
get trim () { return trim; },
|
|
26
30
|
get extend () { return extend; },
|
|
27
31
|
get extract () { return extract; },
|
|
28
|
-
get
|
|
32
|
+
get fit () { return fit; },
|
|
33
|
+
get flatten () { return flatten; },
|
|
29
34
|
get flip () { return flip; },
|
|
30
35
|
get flop () { return flop; },
|
|
31
|
-
get sharpen () { return sharpen; },
|
|
32
|
-
get median () { return median; },
|
|
33
|
-
get blur () { return blur; },
|
|
34
|
-
get flatten () { return flatten; },
|
|
35
36
|
get gamma () { return gamma; },
|
|
37
|
+
get grayscale () { return grayscale; },
|
|
38
|
+
get h () { return h; },
|
|
39
|
+
get height () { return height; },
|
|
40
|
+
get median () { return median; },
|
|
41
|
+
get modulate () { return modulate; },
|
|
36
42
|
get negate () { return negate; },
|
|
37
43
|
get normalize () { return normalize; },
|
|
44
|
+
get pos () { return pos; },
|
|
45
|
+
get position () { return position; },
|
|
46
|
+
get q () { return q; },
|
|
47
|
+
get quality () { return quality; },
|
|
48
|
+
get resize () { return resize; },
|
|
49
|
+
get rotate () { return rotate; },
|
|
50
|
+
get s () { return s; },
|
|
51
|
+
get sharpen () { return sharpen; },
|
|
38
52
|
get threshold () { return threshold; },
|
|
39
|
-
get modulate () { return modulate; },
|
|
40
53
|
get tint () { return tint; },
|
|
41
|
-
get
|
|
42
|
-
get crop () { return crop; },
|
|
43
|
-
get q () { return q; },
|
|
44
|
-
get b () { return b; },
|
|
54
|
+
get trim () { return trim; },
|
|
45
55
|
get w () { return w; },
|
|
46
|
-
get
|
|
47
|
-
get s () { return s; },
|
|
48
|
-
get pos () { return pos; }
|
|
56
|
+
get width () { return width; }
|
|
49
57
|
};
|
|
50
58
|
|
|
51
59
|
function getEnv(name, defaultValue) {
|
|
52
|
-
return
|
|
60
|
+
return destr__default(process.env[name]) ?? defaultValue;
|
|
53
61
|
}
|
|
54
62
|
function cachedPromise(function_) {
|
|
55
63
|
let p;
|
|
@@ -107,18 +115,20 @@ function isValidPath(fp) {
|
|
|
107
115
|
|
|
108
116
|
const HTTP_RE = /^https?:\/\//;
|
|
109
117
|
const createHTTPSource = (options) => {
|
|
110
|
-
const httpsAgent = new
|
|
111
|
-
const httpAgent = new
|
|
118
|
+
const httpsAgent = new https__default.Agent({ keepAlive: true });
|
|
119
|
+
const httpAgent = new http__default.Agent({ keepAlive: true });
|
|
112
120
|
let _domains = options.domains || [];
|
|
113
121
|
if (typeof _domains === "string") {
|
|
114
122
|
_domains = _domains.split(",").map((s) => s.trim());
|
|
115
123
|
}
|
|
116
|
-
const domains = new Set(
|
|
117
|
-
|
|
118
|
-
d
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
const domains = new Set(
|
|
125
|
+
_domains.map((d) => {
|
|
126
|
+
if (!HTTP_RE.test(d)) {
|
|
127
|
+
d = "http://" + d;
|
|
128
|
+
}
|
|
129
|
+
return new URL(d).hostname;
|
|
130
|
+
}).filter(Boolean)
|
|
131
|
+
);
|
|
122
132
|
return async (id, requestOptions) => {
|
|
123
133
|
const hostname = new URL(id).hostname;
|
|
124
134
|
if (!hostname) {
|
|
@@ -128,11 +138,16 @@ const createHTTPSource = (options) => {
|
|
|
128
138
|
throw createError("Forbidden host", 403, hostname);
|
|
129
139
|
}
|
|
130
140
|
const response = await nodeFetchNative.fetch(id, {
|
|
141
|
+
// @ts-ignore
|
|
131
142
|
agent: id.startsWith("https") ? httpsAgent : httpAgent,
|
|
132
143
|
...options.fetchOptions
|
|
133
144
|
});
|
|
134
145
|
if (!response.ok) {
|
|
135
|
-
throw createError(
|
|
146
|
+
throw createError(
|
|
147
|
+
"Fetch error",
|
|
148
|
+
response.status || 500,
|
|
149
|
+
response.statusText
|
|
150
|
+
);
|
|
136
151
|
}
|
|
137
152
|
let maxAge = options.maxAge;
|
|
138
153
|
const _cacheControl = response.headers.get("cache-control");
|
|
@@ -150,13 +165,16 @@ const createHTTPSource = (options) => {
|
|
|
150
165
|
return {
|
|
151
166
|
mtime,
|
|
152
167
|
maxAge,
|
|
153
|
-
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
getData: cachedPromise(
|
|
170
|
+
() => response.arrayBuffer().then((ab) => Buffer.from(ab))
|
|
171
|
+
)
|
|
154
172
|
};
|
|
155
173
|
};
|
|
156
174
|
};
|
|
157
175
|
|
|
158
176
|
function VArg(argument) {
|
|
159
|
-
return
|
|
177
|
+
return destr__default(argument);
|
|
160
178
|
}
|
|
161
179
|
function parseArgs(arguments_, mappers) {
|
|
162
180
|
const vargs = arguments_.split("_");
|
|
@@ -226,13 +244,17 @@ const enlarge = {
|
|
|
226
244
|
const width = {
|
|
227
245
|
args: [VArg],
|
|
228
246
|
apply: (context, pipe, width2) => {
|
|
229
|
-
return pipe.resize(width2, void 0, {
|
|
247
|
+
return pipe.resize(width2, void 0, {
|
|
248
|
+
withoutEnlargement: !context.enlarge
|
|
249
|
+
});
|
|
230
250
|
}
|
|
231
251
|
};
|
|
232
252
|
const height = {
|
|
233
253
|
args: [VArg],
|
|
234
254
|
apply: (context, pipe, height2) => {
|
|
235
|
-
return pipe.resize(void 0, height2, {
|
|
255
|
+
return pipe.resize(void 0, height2, {
|
|
256
|
+
withoutEnlargement: !context.enlarge
|
|
257
|
+
});
|
|
236
258
|
}
|
|
237
259
|
};
|
|
238
260
|
const resize = {
|
|
@@ -246,7 +268,10 @@ const resize = {
|
|
|
246
268
|
height2 = width2;
|
|
247
269
|
}
|
|
248
270
|
if (!context.enlarge) {
|
|
249
|
-
const clamped = clampDimensionsPreservingAspectRatio(context.meta, {
|
|
271
|
+
const clamped = clampDimensionsPreservingAspectRatio(context.meta, {
|
|
272
|
+
width: width2,
|
|
273
|
+
height: height2
|
|
274
|
+
});
|
|
250
275
|
width2 = clamped.width;
|
|
251
276
|
height2 = clamped.height;
|
|
252
277
|
}
|
|
@@ -387,7 +412,14 @@ const h = height;
|
|
|
387
412
|
const s = resize;
|
|
388
413
|
const pos = position;
|
|
389
414
|
|
|
390
|
-
const SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
|
|
415
|
+
const SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
|
|
416
|
+
"jpeg",
|
|
417
|
+
"png",
|
|
418
|
+
"webp",
|
|
419
|
+
"avif",
|
|
420
|
+
"tiff",
|
|
421
|
+
"gif"
|
|
422
|
+
]);
|
|
391
423
|
function createIPX(userOptions) {
|
|
392
424
|
const defaults = {
|
|
393
425
|
dir: getEnv("IPX_DIR", "."),
|
|
@@ -398,7 +430,9 @@ function createIPX(userOptions) {
|
|
|
398
430
|
sharp: {}
|
|
399
431
|
};
|
|
400
432
|
const options = defu.defu(userOptions, defaults);
|
|
401
|
-
options.alias = Object.fromEntries(
|
|
433
|
+
options.alias = Object.fromEntries(
|
|
434
|
+
Object.entries(options.alias).map((e) => [ufo.withLeadingSlash(e[0]), e[1]])
|
|
435
|
+
);
|
|
402
436
|
const context = {
|
|
403
437
|
sources: {}
|
|
404
438
|
};
|
|
@@ -449,10 +483,16 @@ function createIPX(userOptions) {
|
|
|
449
483
|
};
|
|
450
484
|
}
|
|
451
485
|
const animated = modifiers.animated !== void 0 || modifiers.a !== void 0 || format === "gif";
|
|
452
|
-
const Sharp = await import('sharp').then(
|
|
486
|
+
const Sharp = await import('sharp').then(
|
|
487
|
+
(r) => r.default || r
|
|
488
|
+
);
|
|
453
489
|
let sharp = Sharp(data, { animated });
|
|
454
490
|
Object.assign(sharp.options, options.sharp);
|
|
455
|
-
const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({
|
|
491
|
+
const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({
|
|
492
|
+
handler: getHandler(name),
|
|
493
|
+
name,
|
|
494
|
+
args: arguments_
|
|
495
|
+
})).filter((h) => h.handler).sort((a, b) => {
|
|
456
496
|
const aKey = (a.handler.order || a.name || "").toString();
|
|
457
497
|
const bKey = (b.handler.order || b.name || "").toString();
|
|
458
498
|
return aKey.localeCompare(bKey);
|
|
@@ -490,7 +530,10 @@ async function _handleRequest(request, ipx) {
|
|
|
490
530
|
headers: {},
|
|
491
531
|
body: ""
|
|
492
532
|
};
|
|
493
|
-
const [modifiersString = "", ...idSegments] = request.url.slice(
|
|
533
|
+
const [modifiersString = "", ...idSegments] = request.url.slice(
|
|
534
|
+
1
|
|
535
|
+
/* leading slash */
|
|
536
|
+
).split("/");
|
|
494
537
|
const id = safeString(ufo.decode(idSegments.join("/")));
|
|
495
538
|
if (!modifiersString) {
|
|
496
539
|
throw createError("Modifiers are missing", 400, request.url);
|
|
@@ -518,7 +561,7 @@ async function _handleRequest(request, ipx) {
|
|
|
518
561
|
res.headers["Cache-Control"] = `max-age=${+source.maxAge}, public, s-maxage=${+source.maxAge}`;
|
|
519
562
|
}
|
|
520
563
|
const { data, format } = await img.data();
|
|
521
|
-
const etag =
|
|
564
|
+
const etag = getEtag__default(data);
|
|
522
565
|
res.headers.ETag = etag;
|
|
523
566
|
if (etag && request.headers["if-none-match"] === etag) {
|
|
524
567
|
res.statusCode = 304;
|
|
@@ -548,7 +591,10 @@ function handleRequest(request, ipx) {
|
|
|
548
591
|
}
|
|
549
592
|
function createIPXMiddleware(ipx) {
|
|
550
593
|
return function IPXMiddleware(request, res) {
|
|
551
|
-
return handleRequest(
|
|
594
|
+
return handleRequest(
|
|
595
|
+
{ url: request.url, headers: request.headers },
|
|
596
|
+
ipx
|
|
597
|
+
).then((_res) => {
|
|
552
598
|
res.statusCode = _res.statusCode;
|
|
553
599
|
res.statusMessage = _res.statusMessage;
|
|
554
600
|
for (const name in _res.headers) {
|
|
@@ -563,7 +609,7 @@ function sanetizeReponse(res) {
|
|
|
563
609
|
statusCode: res.statusCode || 200,
|
|
564
610
|
statusMessage: res.statusMessage ? safeString(res.statusMessage) : "OK",
|
|
565
611
|
headers: safeStringObject(res.headers || {}),
|
|
566
|
-
body: typeof res.body === "string" ?
|
|
612
|
+
body: typeof res.body === "string" ? xss__default(safeString(res.body)) : res.body || ""
|
|
567
613
|
};
|
|
568
614
|
}
|
|
569
615
|
function safeString(input) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ipx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"repository": "unjs/ipx",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"exports": {
|
|
@@ -20,42 +20,41 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "unbuild",
|
|
22
22
|
"dev": "nodemon",
|
|
23
|
-
"lint": "eslint --ext .ts .",
|
|
23
|
+
"lint": "eslint --ext .ts . && prettier -c src test",
|
|
24
|
+
"lint:fix": "eslint --ext .ts . --fix && prettier -w src test",
|
|
24
25
|
"prepack": "pnpm build",
|
|
25
|
-
"release": "pnpm test &&
|
|
26
|
+
"release": "pnpm test && changelogen --release --push && npm publish",
|
|
26
27
|
"start": "node bin/ipx.js",
|
|
27
28
|
"test": "pnpm lint && vitest run --coverage"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"consola": "^
|
|
31
|
-
"defu": "^6.1.
|
|
32
|
-
"destr": "^1.2.
|
|
31
|
+
"consola": "^3.0.1",
|
|
32
|
+
"defu": "^6.1.2",
|
|
33
|
+
"destr": "^1.2.2",
|
|
33
34
|
"etag": "^1.8.1",
|
|
34
35
|
"image-meta": "^0.1.1",
|
|
35
|
-
"listhen": "^1.0.
|
|
36
|
-
"node-fetch-native": "^1.0
|
|
37
|
-
"pathe": "^1.
|
|
38
|
-
"sharp": "^0.
|
|
39
|
-
"ufo": "^1.
|
|
36
|
+
"listhen": "^1.0.4",
|
|
37
|
+
"node-fetch-native": "^1.1.0",
|
|
38
|
+
"pathe": "^1.1.0",
|
|
39
|
+
"sharp": "^0.32.0",
|
|
40
|
+
"ufo": "^1.1.1",
|
|
40
41
|
"xss": "^1.0.14"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@nuxtjs/eslint-config-typescript": "^12.0.0",
|
|
44
44
|
"@types/etag": "^1.8.1",
|
|
45
45
|
"@types/is-valid-path": "^0.1.0",
|
|
46
|
-
"@types/
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
46
|
+
"@types/sharp": "^0.31.1",
|
|
47
|
+
"@vitest/coverage-c8": "^0.30.1",
|
|
48
|
+
"changelogen": "^0.5.2",
|
|
49
|
+
"eslint": "^8.38.0",
|
|
50
|
+
"eslint-config-unjs": "^0.1.0",
|
|
51
|
+
"jiti": "^1.18.2",
|
|
52
|
+
"nodemon": "^2.0.22",
|
|
53
|
+
"prettier": "^2.8.7",
|
|
54
54
|
"serve-handler": "^6.1.5",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"vitest": "^0.25.3"
|
|
55
|
+
"typescript": "^5.0.4",
|
|
56
|
+
"unbuild": "^1.2.0",
|
|
57
|
+
"vitest": "^0.30.1"
|
|
59
58
|
},
|
|
60
|
-
"packageManager": "pnpm@
|
|
61
|
-
}
|
|
59
|
+
"packageManager": "pnpm@8.2.0"
|
|
60
|
+
}
|