diff --git a/README.md b/README.md index f413a45..ae0e1a2 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ - `hide_fans` - 是否隐藏月粉丝数, 默认为`false` - `width` - 宽度, 默认为`640` - `height` - 高度, 默认为`225` +- `maxage` - 浏览器缓存时间, 单位为秒, 默认为`7200` [![Gizmo's Profile](https://afdian-connect.deno.dev/profile.svg)](https://afdian.net/a/gizmo) @@ -66,5 +67,6 @@ 支持的选项: - `width` - 宽度, 默认为`800` +- `maxage` - 浏览器缓存时间, 单位为秒, 默认为`7200` -![打钱!](https://afdian-connect.deno.dev/sponsor.svg) +[![金主爸爸](https://afdian-connect.deno.dev/sponsor.svg)](https://afdian.net/a/gizmo) diff --git a/routes/profile.svg.tsx b/routes/profile.svg.tsx index 6d33d03..fd5e2e4 100644 --- a/routes/profile.svg.tsx +++ b/routes/profile.svg.tsx @@ -14,6 +14,7 @@ export default eventHandler(async e => { const hideFans = query.get('hide_fans') === 'true'; const width = parseInt(query.get('width') ?? '640'); const height = parseInt(query.get('height') ?? '225'); + const maxage = parseInt(query.get('maxage') ?? '7200'); const profile = await getProfileBySlug(slug); const user = profile.data.user; @@ -164,5 +165,9 @@ export default eventHandler(async e => { e.node.res.appendHeader('accept-encoding', 'br'); e.node.res.appendHeader('content-type', 'image/svg+xml'); + e.node.res.appendHeader( + 'cache-control', + `max-age=${maxage}, s-maxage=${maxage}` + ); return '\n' + renderSSR(SVG); }); diff --git a/routes/sponsor.svg.tsx b/routes/sponsor.svg.tsx index f525214..a4192ab 100644 --- a/routes/sponsor.svg.tsx +++ b/routes/sponsor.svg.tsx @@ -10,6 +10,7 @@ export default eventHandler(async e => { .searchParams; const width = parseInt(query.get('width') ?? '800'); + const maxage = parseInt(query.get('maxage') ?? '7200'); const { list, total_page } = (await querySponsor(1)).data; for (let i = 1; i < total_page; i++) @@ -143,5 +144,9 @@ export default eventHandler(async e => { e.node.res.appendHeader('accept-encoding', 'br'); e.node.res.appendHeader('content-type', 'image/svg+xml'); + e.node.res.appendHeader( + 'cache-control', + `max-age=${maxage}, s-maxage=${maxage}` + ); return '\n' + renderSSR(() => SVG); });