nuxt-filer 0.0.9 → 0.0.11
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/module.json
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
message: string;
|
|
4
|
-
};
|
|
5
|
-
}>>;
|
|
1
|
+
import { type EventHandler } from 'h3';
|
|
2
|
+
declare const _default: EventHandler<import("h3").EventHandlerRequest, any>;
|
|
6
3
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineEventHandler } from "h3";
|
|
1
|
+
import { defineEventHandler, useBase } from "h3";
|
|
2
2
|
import { createIPX, createIPXH3Handler } from "ipx";
|
|
3
3
|
import { ipxRoute } from "#nuxt-filer-image";
|
|
4
4
|
import { useFileStorageProvider } from "../provider.js";
|
|
@@ -36,14 +36,8 @@ let _ipx = null;
|
|
|
36
36
|
function getHandler() {
|
|
37
37
|
if (!_handler) {
|
|
38
38
|
_ipx = createIPX({ storage: filerStorage });
|
|
39
|
-
_handler = createIPXH3Handler(_ipx);
|
|
39
|
+
_handler = useBase(ipxRoute, createIPXH3Handler(_ipx));
|
|
40
40
|
}
|
|
41
41
|
return _handler;
|
|
42
42
|
}
|
|
43
|
-
export default defineEventHandler((event) =>
|
|
44
|
-
const original = event.path;
|
|
45
|
-
let sub = original.startsWith(ipxRoute) ? original.slice(ipxRoute.length) : original;
|
|
46
|
-
if (!sub.startsWith("/")) sub = `/${sub}`;
|
|
47
|
-
event.path = sub;
|
|
48
|
-
return getHandler()(event);
|
|
49
|
-
});
|
|
43
|
+
export default defineEventHandler((event) => getHandler()(event));
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineEventHandler } from 'h3';
|
|
1
|
+
import { defineEventHandler, useBase, type EventHandler } from 'h3';
|
|
2
2
|
import { createIPX, createIPXH3Handler, type IPX, type IPXStorage } from 'ipx';
|
|
3
3
|
// @ts-expect-error virtual module injected by the module
|
|
4
4
|
import { ipxRoute } from '#nuxt-filer-image';
|
|
@@ -41,24 +41,20 @@ const filerStorage: IPXStorage = {
|
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
let _handler:
|
|
44
|
+
let _handler: EventHandler | null = null;
|
|
45
45
|
let _ipx: IPX | null = null;
|
|
46
|
-
function getHandler() {
|
|
46
|
+
function getHandler(): EventHandler {
|
|
47
47
|
if (!_handler) {
|
|
48
48
|
_ipx = createIPX({ storage: filerStorage });
|
|
49
|
-
|
|
49
|
+
// IPX expects to see `/<modifiers>/<groupId>/<fileId>`, so strip the
|
|
50
|
+
// configured base prefix first. We delegate to h3's `useBase` rather than
|
|
51
|
+
// assigning `event.path` — `event.path` is a getter-only accessor (it
|
|
52
|
+
// reads back `event._path || req.url`), so writing to it throws
|
|
53
|
+
// "Cannot set property path ... which has only a getter". `useBase`
|
|
54
|
+
// rewrites `_path`/`req.url` for the inner handler and restores them after.
|
|
55
|
+
_handler = useBase(ipxRoute, createIPXH3Handler(_ipx));
|
|
50
56
|
}
|
|
51
57
|
return _handler;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
export default defineEventHandler((event) =>
|
|
55
|
-
// Strip the configured base prefix so IPX sees the URL it expects:
|
|
56
|
-
// `/<modifiers>/<groupId>/<fileId>`.
|
|
57
|
-
const original = event.path;
|
|
58
|
-
let sub = original.startsWith(ipxRoute)
|
|
59
|
-
? original.slice((ipxRoute as string).length)
|
|
60
|
-
: original;
|
|
61
|
-
if (!sub.startsWith('/')) sub = `/${sub}`;
|
|
62
|
-
event.path = sub;
|
|
63
|
-
return getHandler()(event);
|
|
64
|
-
});
|
|
60
|
+
export default defineEventHandler((event) => getHandler()(event));
|