nuxt-media-library 0.0.53 → 0.0.55
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/README.md +18 -0
- package/dist/module.d.mts +10 -0
- package/dist/module.d.ts +10 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +49 -26
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,6 +52,9 @@ export default defineNuxtConfig({
|
|
|
52
52
|
baseURL: 'http://media-library.internal/v1',
|
|
53
53
|
// Only for direct browser uploads (proxyUploads: false): a public address.
|
|
54
54
|
// publicBaseURL: 'https://media.example.com/v1',
|
|
55
|
+
// false when your own server/api/media-library/[...].ts serves /manage
|
|
56
|
+
// (media grants, below). Default true: the module's /manage proxies.
|
|
57
|
+
// manageProxy: false,
|
|
55
58
|
// Uploads always go through Nuxt server (/api/media-library/uploads/*)
|
|
56
59
|
routes: {
|
|
57
60
|
createSession: '/uploads/sessions',
|
|
@@ -103,6 +106,18 @@ request is checked by your rules and sent upstream with a short-lived
|
|
|
103
106
|
endpoints, and no long-lived credential reaches the media library from the
|
|
104
107
|
browser.
|
|
105
108
|
|
|
109
|
+
Turn off the module's built-in `/manage` proxies so your handler gets the
|
|
110
|
+
requests. Their routes (`/api/media-library/manage/assets/**`…) are more
|
|
111
|
+
specific than a catch-all file and would otherwise answer first, without
|
|
112
|
+
`authorize` (the module warns at startup when it sees a shadowed catch-all):
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// nuxt.config.ts
|
|
116
|
+
export default defineNuxtConfig({
|
|
117
|
+
mediaLibrary: { manageProxy: false },
|
|
118
|
+
})
|
|
119
|
+
```
|
|
120
|
+
|
|
106
121
|
```ts
|
|
107
122
|
// server/api/media-library/[...].ts
|
|
108
123
|
import { createMLCatchAllProxy, specFromNeed } from '@fritill-team/nuxt-media-library/server'
|
|
@@ -139,6 +154,9 @@ export default createMLCatchAllProxy({
|
|
|
139
154
|
before they expire; an upload's parts, finalize and abort reuse the grant
|
|
140
155
|
that created the session.
|
|
141
156
|
- `/delivery` and the processing metadata routes are not affected.
|
|
157
|
+
- With `manageProxy: false` the module still serves `/api/media-library/delivery/**`
|
|
158
|
+
and, when `serviceUploads.proxy` is on, the service-upload pass-through.
|
|
159
|
+
Your catch-all handles everything else under `/api/media-library`.
|
|
142
160
|
|
|
143
161
|
### Showing assets of several services: read grants
|
|
144
162
|
|
package/dist/module.d.mts
CHANGED
|
@@ -52,6 +52,16 @@ interface ModuleOptions {
|
|
|
52
52
|
baseURL?: string;
|
|
53
53
|
backends?: Record<string, ServiceUploadBackend>;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* The built-in `/api/media-library/manage/**` proxies (default `true`).
|
|
57
|
+
* Set `false` when the app serves `/manage` itself, e.g. with
|
|
58
|
+
* `createMLCatchAllProxy({ authorize })` in
|
|
59
|
+
* `server/api/media-library/[...].ts`: the built-in routes are more
|
|
60
|
+
* specific than an app's catch-all and would otherwise answer first, so
|
|
61
|
+
* `authorize` would never run. `/delivery/**` and the service-upload
|
|
62
|
+
* pass-through are still registered.
|
|
63
|
+
*/
|
|
64
|
+
manageProxy?: boolean;
|
|
55
65
|
}
|
|
56
66
|
declare const SERVICE_UPLOADS_ROUTE = "/api/media-library/service-uploads";
|
|
57
67
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.d.ts
CHANGED
|
@@ -52,6 +52,16 @@ interface ModuleOptions {
|
|
|
52
52
|
baseURL?: string;
|
|
53
53
|
backends?: Record<string, ServiceUploadBackend>;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* The built-in `/api/media-library/manage/**` proxies (default `true`).
|
|
57
|
+
* Set `false` when the app serves `/manage` itself, e.g. with
|
|
58
|
+
* `createMLCatchAllProxy({ authorize })` in
|
|
59
|
+
* `server/api/media-library/[...].ts`: the built-in routes are more
|
|
60
|
+
* specific than an app's catch-all and would otherwise answer first, so
|
|
61
|
+
* `authorize` would never run. `/delivery/**` and the service-upload
|
|
62
|
+
* pass-through are still registered.
|
|
63
|
+
*/
|
|
64
|
+
manageProxy?: boolean;
|
|
55
65
|
}
|
|
56
66
|
declare const SERVICE_UPLOADS_ROUTE = "/api/media-library/service-uploads";
|
|
57
67
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
1
3
|
import { defineNuxtModule, createResolver, addImportsDir, addComponentsDir, addServerHandler, useLogger, addPlugin } from '@nuxt/kit';
|
|
2
4
|
export * from '../dist/runtime/types/resourcePolicy.js';
|
|
3
5
|
export * from '../dist/runtime/types/uploader.js';
|
|
@@ -37,6 +39,20 @@ function serviceBackends(backends, logger) {
|
|
|
37
39
|
}
|
|
38
40
|
return out;
|
|
39
41
|
}
|
|
42
|
+
function appCatchAlls(layers) {
|
|
43
|
+
const found = [];
|
|
44
|
+
for (const { config } of layers) {
|
|
45
|
+
const serverDir = config.serverDir ?? join(config.rootDir, "server");
|
|
46
|
+
for (const sub of ["api/media-library", "api/media-library/manage"]) {
|
|
47
|
+
const dir = join(serverDir, sub);
|
|
48
|
+
if (!existsSync(dir)) continue;
|
|
49
|
+
for (const name of readdirSync(dir)) {
|
|
50
|
+
if (name.startsWith("[...")) found.push(join(dir, name));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
40
56
|
const module$1 = defineNuxtModule({
|
|
41
57
|
meta: {
|
|
42
58
|
name: "media-library",
|
|
@@ -56,7 +72,8 @@ const module$1 = defineNuxtModule({
|
|
|
56
72
|
partSize: 8 * 1024 * 1024,
|
|
57
73
|
concurrency: 3,
|
|
58
74
|
checksum: { algorithm: "SHA-256", perPart: true, final: true },
|
|
59
|
-
headers: {}
|
|
75
|
+
headers: {},
|
|
76
|
+
manageProxy: true
|
|
60
77
|
},
|
|
61
78
|
async setup(options, nuxt) {
|
|
62
79
|
const resolver = createResolver(import.meta.url);
|
|
@@ -101,30 +118,37 @@ const module$1 = defineNuxtModule({
|
|
|
101
118
|
route: "/api/media-library/delivery/**",
|
|
102
119
|
handler: resolver.resolve("./runtime/server/delivery-proxy")
|
|
103
120
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
const logger = useLogger("media-library");
|
|
122
|
+
if (options.manageProxy !== false) {
|
|
123
|
+
addServerHandler({
|
|
124
|
+
route: "/api/media-library/manage/uploads/**",
|
|
125
|
+
handler: resolver.resolve("./runtime/server/uploads-proxy")
|
|
126
|
+
});
|
|
127
|
+
addServerHandler({
|
|
128
|
+
route: "/api/media-library/manage/resource-policies/**",
|
|
129
|
+
handler: resolver.resolve("./runtime/server/resource-policy-proxy")
|
|
130
|
+
});
|
|
131
|
+
addServerHandler({
|
|
132
|
+
route: "/api/media-library/manage/resource-policies",
|
|
133
|
+
handler: resolver.resolve("./runtime/server/resource-policy-proxy")
|
|
134
|
+
});
|
|
135
|
+
addServerHandler({
|
|
136
|
+
route: "/api/media-library/manage/assets/**",
|
|
137
|
+
handler: resolver.resolve("./runtime/server/assets-proxy")
|
|
138
|
+
});
|
|
139
|
+
addServerHandler({
|
|
140
|
+
route: "/api/media-library/manage/assets",
|
|
141
|
+
handler: resolver.resolve("./runtime/server/assets-proxy")
|
|
142
|
+
});
|
|
143
|
+
addServerHandler({
|
|
144
|
+
route: "/api/media-library/manage/processing/**",
|
|
145
|
+
handler: resolver.resolve("./runtime/server/processing-proxy")
|
|
146
|
+
});
|
|
147
|
+
const shadowed = appCatchAlls(nuxt.options._layers);
|
|
148
|
+
if (shadowed.length) {
|
|
149
|
+
logger.warn(`${shadowed.join(", ")} will not receive /api/media-library/manage requests: the module's own /manage routes answer first. Set mediaLibrary.manageProxy: false to serve /manage from your handler (e.g. createMLCatchAllProxy({ authorize })).`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
128
152
|
if (options.serviceUploads?.proxy) {
|
|
129
153
|
addServerHandler({
|
|
130
154
|
route: `${SERVICE_UPLOADS_ROUTE}/**`,
|
|
@@ -140,7 +164,6 @@ const module$1 = defineNuxtModule({
|
|
|
140
164
|
// grants). Declared so NUXT_MEDIA_LIBRARY_SERVICE_TOKEN applies.
|
|
141
165
|
serviceToken: existingPrivate.serviceToken ?? ""
|
|
142
166
|
};
|
|
143
|
-
const logger = useLogger("media-library");
|
|
144
167
|
const publicHeaders = browserHeaders(existingPublic.headers ?? options.headers);
|
|
145
168
|
if (publicHeaders.dropped.length) {
|
|
146
169
|
logger.warn(`mediaLibrary.headers: ${publicHeaders.dropped.join(", ")} kept server-side, not sent to browsers.`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-media-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.55",
|
|
4
4
|
"description": "Nuxt module for media library management — chunked uploads, asset previews, and resource policies",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"admin:dev": "yarn dev:prepare && yarn --cwd admin-playground dev",
|
|
42
42
|
"prepack": "nuxt-module-build build",
|
|
43
43
|
"lint": "eslint .",
|
|
44
|
-
"test": "yarn dev:prepare && nuxi prepare test/fixtures/basic && vitest run"
|
|
44
|
+
"test": "yarn dev:prepare && nuxi prepare test/fixtures/basic && nuxi prepare test/fixtures/manage-grants && vitest run"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@nuxt/ui": "^4.0.0",
|