Skip to content

Commit

Permalink
feat: add maxage param
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo-ds committed Aug 1, 2023
1 parent 14122b8 commit 04d9cbe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
5 changes: 5 additions & 0 deletions routes/profile.svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 '<!-- Generated by afdian-connect -->\n' + renderSSR(SVG);
});
5 changes: 5 additions & 0 deletions routes/sponsor.svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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 '<!-- Generated by afdian-connect -->\n' + renderSSR(() => SVG);
});

0 comments on commit 04d9cbe

Please sign in to comment.