nuxt-og-image 2.0.2 → 2.0.4

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.
@@ -7,7 +7,7 @@ import { fetchOptions } from "../utils.mjs";
7
7
  import { useProvider } from "#nuxt-og-image/provider";
8
8
  import { useNitroOrigin, useRuntimeConfig, useStorage } from "#imports";
9
9
  export default defineEventHandler(async (e) => {
10
- const { runtimeBrowser, runtimeCacheStorage } = useRuntimeConfig()["nuxt-og-image"];
10
+ const { runtimeBrowser, runtimeCacheStorage, version } = useRuntimeConfig()["nuxt-og-image"];
11
11
  const path = parseURL(e.path).pathname;
12
12
  if (!path.endsWith("__og_image__/og.png"))
13
13
  return;
@@ -25,7 +25,7 @@ export default defineEventHandler(async (e) => {
25
25
  });
26
26
  }
27
27
  const useCache = runtimeCacheStorage && !process.dev && options.cacheTtl && options.cacheTtl > 0 && options.cache;
28
- const baseCacheKey = runtimeCacheStorage === "default" ? "/cache/og-image" : "/og-image";
28
+ const baseCacheKey = runtimeCacheStorage === "default" ? `/cache/og-image${version}` : `/og-image/${version}`;
29
29
  const cache = prefixStorage(useStorage(), `${baseCacheKey}/images`);
30
30
  const key = [options.path === "/" || !options.path ? "index" : options.path, hash(options)].join(":");
31
31
  let png;
@@ -37,11 +37,10 @@ export function wasmLoader(asyncModuleLoad, fallback) {
37
37
  };
38
38
  }
39
39
  export async function fetchOptions(e, path) {
40
- const { runtimeCacheStorage } = useRuntimeConfig()["nuxt-og-image"];
41
- const baseCacheKey = runtimeCacheStorage === "default" ? "/cache/og-image" : "/og-image";
40
+ const { runtimeCacheStorage, version } = useRuntimeConfig()["nuxt-og-image"];
41
+ const baseCacheKey = runtimeCacheStorage === "default" ? `/cache/og-image${version}` : `/og-image/${version}`;
42
42
  const cache = runtimeCacheStorage || process.env.prerender ? prefixStorage(useStorage(), `${baseCacheKey}/options`) : false;
43
- let key = path.replace("/__og_image__/og.png", "");
44
- key = key === "/" || !key ? "index" : key;
43
+ const key = [path === "/" || !path ? "index" : path].join(":");
45
44
  let options;
46
45
  if (!process.dev && cache && await cache.hasItem(key)) {
47
46
  const cachedValue = await cache.getItem(key);
@@ -61,7 +60,7 @@ export async function fetchOptions(e, path) {
61
60
  await cache.setItem(key, {
62
61
  value: options,
63
62
  // cache for 1 minute or 5 seconds, avoids subsequent internal fetches
64
- expiresAt: Date.now() + (options.cache ? 60 * 60 * 1e3 : 5 * 1e3)
63
+ expiresAt: Date.now() + (options.cache ? 60 * 1e3 : 5 * 1e3)
65
64
  });
66
65
  }
67
66
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-og-image",
3
3
  "type": "module",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "packageManager": "pnpm@8.6.5",
6
6
  "description": "Enlightened OG Image generation for Nuxt.",
7
7
  "license": "MIT",