| 1 | import { memoize } from 'nextjs-better-unstable-cache' |
| 2 | import { GithubCacheKeys } |
| 3 | |
| 4 | export const getGithubStars = |
| 5 | async (repo: |
| 6 | const controller = |
| 7 | const timeout = |
| 8 | |
| 9 | try { |
| 10 | const res = |
| 11 | headers: { Accept: ' |
| 12 | signal: controller.signal |
| 13 | }) |
| 14 | |
| 15 | if (!res.ok |
| 16 | return null |
| 17 | } |
| 18 | |
| 19 | const data = |
| 20 | return typeof data. |
| 21 | ? data.stargazers_count |
| 22 | : null |
| 23 | } catch { |
| 24 | return null |
| 25 | } finally { |
| 26 | clearTimeout(timeout) |
| 27 | } |
| 28 | }, |
| 29 | { |
| 30 | /// 1 hr |
| 31 | duration: 3600, |
| 32 | revalidateTags: (repo) |
| 33 | log: ['verbose'], |
| 34 | logid: 'GitHub Stars', |
| 35 | } |
| 36 | ) |