mikser-io 7.6.0 → 7.6.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/package.json +1 -1
- package/src/plugins/api.js +3 -30
- package/src/plugins/preview.js +1 -1
- package/src/utils.js +34 -0
package/package.json
CHANGED
package/src/plugins/api.js
CHANGED
|
@@ -5,6 +5,7 @@ import _ from 'lodash'
|
|
|
5
5
|
import sift from 'sift'
|
|
6
6
|
import { z } from 'zod'
|
|
7
7
|
import { useRenderer, useCollection } from '../api.js'
|
|
8
|
+
import { mimeForEntity } from '../utils.js'
|
|
8
9
|
|
|
9
10
|
// Mongo-style operators recognised in URL query params as `<path>.$<op>=...`.
|
|
10
11
|
// $in / $nin take comma-separated values; $exists takes a truthy/falsy
|
|
@@ -202,36 +203,8 @@ async function clearEndpointCache({ outputFolder, base, name, logger }) {
|
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
// (assigned by the layouts plugin), so we use it as the source of truth.
|
|
208
|
-
const MIME_BY_EXT = {
|
|
209
|
-
pdf: 'application/pdf',
|
|
210
|
-
html: 'text/html; charset=utf-8',
|
|
211
|
-
xml: 'application/xml; charset=utf-8',
|
|
212
|
-
xhtml: 'application/xhtml+xml; charset=utf-8',
|
|
213
|
-
rss: 'application/rss+xml; charset=utf-8',
|
|
214
|
-
atom: 'application/atom+xml; charset=utf-8',
|
|
215
|
-
json: 'application/json; charset=utf-8',
|
|
216
|
-
css: 'text/css; charset=utf-8',
|
|
217
|
-
js: 'application/javascript; charset=utf-8',
|
|
218
|
-
svg: 'image/svg+xml',
|
|
219
|
-
png: 'image/png',
|
|
220
|
-
jpg: 'image/jpeg',
|
|
221
|
-
jpeg: 'image/jpeg',
|
|
222
|
-
webp: 'image/webp',
|
|
223
|
-
gif: 'image/gif',
|
|
224
|
-
mp4: 'video/mp4',
|
|
225
|
-
webm: 'video/webm',
|
|
226
|
-
txt: 'text/plain; charset=utf-8',
|
|
227
|
-
md: 'text/markdown; charset=utf-8',
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function mimeForEntity(entity) {
|
|
231
|
-
if (!entity?.destination) return null
|
|
232
|
-
const ext = path.extname(entity.destination).toLowerCase().replace(/^\./, '')
|
|
233
|
-
return MIME_BY_EXT[ext] ?? null
|
|
234
|
-
}
|
|
206
|
+
// mimeForEntity lives in ../utils.js (pure helper, shared by several
|
|
207
|
+
// plugins). Imported at top of file.
|
|
235
208
|
|
|
236
209
|
// Decide how to send the render output over HTTP. Exported (and pure-ish)
|
|
237
210
|
// so tests can exercise the branching without spinning up a real server.
|
package/src/plugins/preview.js
CHANGED
|
@@ -27,7 +27,7 @@ import path from 'node:path'
|
|
|
27
27
|
import { randomUUID } from 'node:crypto'
|
|
28
28
|
import { z } from 'zod'
|
|
29
29
|
import { useRenderer } from '../api.js'
|
|
30
|
-
import { mimeForEntity } from '
|
|
30
|
+
import { mimeForEntity } from '../utils.js'
|
|
31
31
|
|
|
32
32
|
export default ({
|
|
33
33
|
runtime,
|
package/src/utils.js
CHANGED
|
@@ -6,6 +6,40 @@ import _ from 'lodash'
|
|
|
6
6
|
import { minimatch } from 'minimatch'
|
|
7
7
|
import path from 'path'
|
|
8
8
|
|
|
9
|
+
// Extension → mime type lookup for rendered outputs. Used anywhere an
|
|
10
|
+
// entity's destination is being served over HTTP (the api plugin's
|
|
11
|
+
// /render endpoint, the preview plugin's /preview route, anywhere
|
|
12
|
+
// else that produces Content-Type from an entity). Pure function; no
|
|
13
|
+
// engine state — lives here rather than inside one plugin so other
|
|
14
|
+
// plugins don't have to reach across the plugin folder for it.
|
|
15
|
+
const MIME_BY_EXT = {
|
|
16
|
+
pdf: 'application/pdf',
|
|
17
|
+
html: 'text/html; charset=utf-8',
|
|
18
|
+
xml: 'application/xml; charset=utf-8',
|
|
19
|
+
xhtml: 'application/xhtml+xml; charset=utf-8',
|
|
20
|
+
rss: 'application/rss+xml; charset=utf-8',
|
|
21
|
+
atom: 'application/atom+xml; charset=utf-8',
|
|
22
|
+
json: 'application/json; charset=utf-8',
|
|
23
|
+
css: 'text/css; charset=utf-8',
|
|
24
|
+
js: 'application/javascript; charset=utf-8',
|
|
25
|
+
svg: 'image/svg+xml',
|
|
26
|
+
png: 'image/png',
|
|
27
|
+
jpg: 'image/jpeg',
|
|
28
|
+
jpeg: 'image/jpeg',
|
|
29
|
+
webp: 'image/webp',
|
|
30
|
+
gif: 'image/gif',
|
|
31
|
+
mp4: 'video/mp4',
|
|
32
|
+
webm: 'video/webm',
|
|
33
|
+
txt: 'text/plain; charset=utf-8',
|
|
34
|
+
md: 'text/markdown; charset=utf-8',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function mimeForEntity(entity) {
|
|
38
|
+
if (!entity?.destination) return null
|
|
39
|
+
const ext = path.extname(entity.destination).toLowerCase().replace(/^\./, '')
|
|
40
|
+
return MIME_BY_EXT[ext] ?? null
|
|
41
|
+
}
|
|
42
|
+
|
|
9
43
|
export class AbortError extends Error {
|
|
10
44
|
constructor(message) {
|
|
11
45
|
super();
|