nuxt-og-image 2.0.5 → 2.0.6
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/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/{IconCSS.c66ac96c.js → IconCSS.acbfc761.js} +1 -1
- package/dist/client/_nuxt/{ImageLoader.eea58cf7.js → ImageLoader.45e71895.js} +1 -1
- package/dist/client/_nuxt/{entry.db904b01.js → entry.f886005d.js} +3 -3
- package/dist/client/_nuxt/{error-404.3fd437f7.js → error-404.0a0b8ce2.js} +1 -1
- package/dist/client/_nuxt/{error-500.48bc2fce.js → error-500.20847d33.js} +1 -1
- package/dist/client/_nuxt/{index.62ad0f4a.js → index.0cbeeabd.js} +1 -1
- package/dist/client/_nuxt/{options.8bd8132d.js → options.1070a0ba.js} +1 -1
- package/dist/client/_nuxt/{png.8fd55f17.js → png.e3b1ce6b.js} +1 -1
- package/dist/client/_nuxt/{shiki.eca11a4d.js → shiki.4671d705.js} +1 -1
- package/dist/client/_nuxt/{svg.6552a6ca.js → svg.26cfe41e.js} +1 -1
- package/dist/client/_nuxt/{vnodes.5bb613d8.js → vnodes.7d34f085.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/cache.d.ts +11 -0
- package/dist/runtime/cache.mjs +42 -0
- package/dist/runtime/composables/defineOgImage.mjs +2 -2
- package/dist/runtime/nitro/middleware/og.png.mjs +21 -23
- package/dist/runtime/nitro/middleware/playground.mjs +2 -2
- package/dist/runtime/nitro/routes/html.mjs +2 -2
- package/dist/runtime/nitro/routes/svg.mjs +2 -2
- package/dist/runtime/nitro/routes/vnode.mjs +2 -2
- package/dist/runtime/nitro/utils.d.ts +1 -0
- package/dist/runtime/nitro/utils.mjs +33 -34
- package/package.json +3 -3
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
2
2
|
import { withBase } from "ufo";
|
|
3
|
-
import {
|
|
3
|
+
import { fetchOptionsCached } from "../utils.mjs";
|
|
4
4
|
import { useProvider } from "#nuxt-og-image/provider";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
export default defineEventHandler(async (e) => {
|
|
7
7
|
const query = getQuery(e);
|
|
8
8
|
const path = withBase(query.path || "/", useRuntimeConfig().app.baseURL);
|
|
9
|
-
const options = await
|
|
9
|
+
const options = await fetchOptionsCached(e, path);
|
|
10
10
|
setHeader(e, "Content-Type", "application/json");
|
|
11
11
|
const provider = await useProvider(options.provider);
|
|
12
12
|
if (!provider) {
|
|
@@ -5,6 +5,7 @@ import type { RuntimeOgImageOptions } from '../types';
|
|
|
5
5
|
export declare function wasmLoader(asyncModuleLoad: Promise<any> | Buffer | string, fallback: string): {
|
|
6
6
|
load(options: RuntimeOgImageOptions): Promise<any>;
|
|
7
7
|
};
|
|
8
|
+
export declare function fetchOptionsCached(e: H3Event, path: string): Promise<RuntimeOgImageOptions>;
|
|
8
9
|
export declare function fetchOptions(e: H3Event, path: string): Promise<RuntimeOgImageOptions>;
|
|
9
10
|
export declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
|
|
10
11
|
export declare function readPublicAsset(file: string, encoding?: BufferEncoding): Promise<string | Buffer | undefined>;
|
|
@@ -2,9 +2,11 @@ import { existsSync, promises as fsp } from "node:fs";
|
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
import { getQuery } from "h3";
|
|
4
4
|
import { join } from "pathe";
|
|
5
|
-
import { prefixStorage } from "unstorage";
|
|
6
5
|
import sizeOf from "image-size";
|
|
7
|
-
import {
|
|
6
|
+
import { defu } from "defu";
|
|
7
|
+
import { withoutLeadingSlash } from "ufo";
|
|
8
|
+
import { useNitroCache } from "../cache.mjs";
|
|
9
|
+
import { useNitroOrigin, useRuntimeConfig } from "#imports";
|
|
8
10
|
export function wasmLoader(asyncModuleLoad, fallback) {
|
|
9
11
|
let promise;
|
|
10
12
|
let wasm;
|
|
@@ -36,40 +38,37 @@ export function wasmLoader(asyncModuleLoad, fallback) {
|
|
|
36
38
|
}
|
|
37
39
|
};
|
|
38
40
|
}
|
|
41
|
+
export async function fetchOptionsCached(e, path) {
|
|
42
|
+
const key = [
|
|
43
|
+
withoutLeadingSlash(path === "/" || !path ? "index" : path).replaceAll("/", "-"),
|
|
44
|
+
"options"
|
|
45
|
+
].join(":");
|
|
46
|
+
const { cachedItem, update } = await useNitroCache(e, "nuxt-og-image", {
|
|
47
|
+
key,
|
|
48
|
+
// allow internal requests to be cached
|
|
49
|
+
cacheTtl: 5 * 1e3,
|
|
50
|
+
cache: !process.dev,
|
|
51
|
+
headers: false
|
|
52
|
+
});
|
|
53
|
+
if (cachedItem)
|
|
54
|
+
return cachedItem;
|
|
55
|
+
const options = await fetchOptions(e, path);
|
|
56
|
+
await update(options);
|
|
57
|
+
return options;
|
|
58
|
+
}
|
|
39
59
|
export async function fetchOptions(e, path) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else
|
|
50
|
-
await cache.removeItem(key);
|
|
51
|
-
}
|
|
52
|
-
if (!options) {
|
|
53
|
-
options = await globalThis.$fetch("/api/og-image-options", {
|
|
54
|
-
query: {
|
|
55
|
-
path
|
|
56
|
-
},
|
|
57
|
-
responseType: "json"
|
|
58
|
-
});
|
|
59
|
-
if (cache) {
|
|
60
|
-
await cache.setItem(key, {
|
|
61
|
-
value: options,
|
|
62
|
-
// cache for 1 minute or 5 seconds, avoids subsequent internal fetches
|
|
63
|
-
expiresAt: Date.now() + (options.cache ? 60 * 1e3 : 5 * 1e3)
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
...options,
|
|
60
|
+
const options = await globalThis.$fetch("/api/og-image-options", {
|
|
61
|
+
query: {
|
|
62
|
+
path
|
|
63
|
+
},
|
|
64
|
+
responseType: "json"
|
|
65
|
+
});
|
|
66
|
+
return defu(
|
|
67
|
+
{ requestOrigin: useNitroOrigin(e) },
|
|
68
|
+
options,
|
|
69
69
|
// use query data
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
70
|
+
getQuery(e)
|
|
71
|
+
);
|
|
73
72
|
}
|
|
74
73
|
export function base64ToArrayBuffer(base64) {
|
|
75
74
|
const buffer = Buffer.from(base64, "base64");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-og-image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.6",
|
|
5
5
|
"packageManager": "pnpm@8.6.6",
|
|
6
6
|
"description": "Enlightened OG Image generation for Nuxt.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"image-size": "^1.0.2",
|
|
44
44
|
"inline-css": "^4.0.2",
|
|
45
45
|
"launch-editor": "^2.6.0",
|
|
46
|
-
"nuxt-site-config": "^1.0.
|
|
47
|
-
"nuxt-site-config-kit": "^1.0.
|
|
46
|
+
"nuxt-site-config": "^1.0.5",
|
|
47
|
+
"nuxt-site-config-kit": "^1.0.5",
|
|
48
48
|
"nypm": "^0.2.2",
|
|
49
49
|
"ofetch": "^1.1.1",
|
|
50
50
|
"ohash": "^1.1.2",
|