[READ-ONLY] Mirror of https://github.com/probablykasper/starchart. GitHub star history graph starchart.kasper.space
chart github github-api github-star graph history star star-history stargazers stars
0

Configure Feed

Select the types of activity you want to include in your feed.

Use cached stars server

Kasper (May 17, 2025, 1:53 AM +0200) fc59c85c b0c82390

+73 -6
+16 -5
package-lock.json
··· 27 27 "svelte-check": "^4.1.5", 28 28 "typescript": "^5.8.2", 29 29 "typescript-eslint": "^8.26.0", 30 - "vite": "^6.2.1" 30 + "vite": "^6.2.1", 31 + "zod": "^3.24.4" 31 32 } 32 33 }, 33 34 "node_modules/@ampproject/remapping": { ··· 3770 3771 "node": ">=0.4.0" 3771 3772 } 3772 3773 }, 3774 + "node_modules/miniflare/node_modules/zod": { 3775 + "version": "3.22.3", 3776 + "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.3.tgz", 3777 + "integrity": "sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==", 3778 + "dev": true, 3779 + "license": "MIT", 3780 + "peer": true, 3781 + "funding": { 3782 + "url": "https://github.com/sponsors/colinhacks" 3783 + } 3784 + }, 3773 3785 "node_modules/minimatch": { 3774 3786 "version": "3.1.2", 3775 3787 "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", ··· 6112 6124 "license": "MIT" 6113 6125 }, 6114 6126 "node_modules/zod": { 6115 - "version": "3.22.3", 6116 - "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.3.tgz", 6117 - "integrity": "sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==", 6127 + "version": "3.24.4", 6128 + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.4.tgz", 6129 + "integrity": "sha512-OdqJE9UDRPwWsrHjLN2F8bPxvwJBK22EHLWtanu0LSYr5YqzsaaW3RMgmjwr8Rypg5k+meEJdSPXJZXE/yqOMg==", 6118 6130 "dev": true, 6119 6131 "license": "MIT", 6120 - "peer": true, 6121 6132 "funding": { 6122 6133 "url": "https://github.com/sponsors/colinhacks" 6123 6134 }
+2 -1
package.json
··· 31 31 "svelte-check": "^4.1.5", 32 32 "typescript": "^5.8.2", 33 33 "typescript-eslint": "^8.26.0", 34 - "vite": "^6.2.1" 34 + "vite": "^6.2.1", 35 + "zod": "^3.24.4" 35 36 }, 36 37 "prettier": { 37 38 "useTabs": true,
+55
src/routes/+page.svelte
··· 9 9 import type { UTCTimestamp } from 'lightweight-charts' 10 10 import Tooltip from './Tooltip.svelte' 11 11 import html2canvas from 'html2canvas' 12 + import { z } from 'zod' 12 13 13 14 let [owner, repo] = ['', ''] 14 15 16 + async function cached_fetch(owner: string, repo: string) { 17 + try { 18 + const full_api_request = await ( 19 + await fetch(`https://emafuma.mywire.org:8090/allStars?repo=${owner}/${repo}`) 20 + ).json() 21 + 22 + const schema = z.object({ 23 + stars: z.array(z.tuple([z.string(), z.number().int(), z.number().int()])), 24 + }) 25 + 26 + const result = schema.parse(full_api_request) 27 + return { 28 + stars: result.stars 29 + .map(([t, _amount, accumulated]) => { 30 + if (!/\d{2}-\d{2}-\d{4}/.test(t)) { 31 + throw new Error('unexpected date: ' + t) 32 + } 33 + const date_components = t.split('-') 34 + const date = new Date(date_components.reverse().join('-')) 35 + if (date_components.length !== 3 || date_components[0].length) 36 + if (Number.isNaN(new Date(t).getTime() / 1000)) { 37 + console.log(t, new Date(t), new Date(t).getTime() / 1000) 38 + } 39 + return { 40 + t: (date.getTime() / 1000) as UTCTimestamp, 41 + v: accumulated, 42 + } 43 + }) 44 + .filter(({ v }) => v > 0) 45 + .sort((a, b) => a.t - b.t), 46 + } 47 + } catch (error) { 48 + console.error(error) 49 + return { 50 + stars: [] as { t: UTCTimestamp; v: number }[], 51 + } 52 + } 53 + } 54 + 15 55 let chart: Chart | undefined 16 56 async function get_stargazers(owner: string, repo: string) { 17 57 if (!chart || !$chart) { ··· 23 63 return // already added 24 64 } 25 65 } 66 + 67 + let cached_stars: Awaited<ReturnType<typeof cached_fetch>> | undefined 68 + cached_fetch(owner, repo).then((result) => { 69 + cached_stars = result 70 + }) 71 + 26 72 let repo_stars = new RepoStars(owner, repo) 27 73 let count = 0 28 74 const line = chart.addLine({ ··· 32 78 }) 33 79 let i = 0 34 80 do { 81 + if (cached_stars && cached_stars.stars.length > 0) { 82 + line.data = [] 83 + repo_stars.data_points = cached_stars.stars 84 + console.log('cached_stars', cached_stars.stars) 85 + chart.updateStargazers(line, repo_stars.data_points) 86 + chart.resetZoom() 87 + break 88 + } 35 89 if (line.deleted) { 36 90 return // abort 37 91 } ··· 41 95 chart.deleteLine(line) 42 96 return 43 97 } 98 + console.log('stargazers', stargazers) 44 99 45 100 chart.updateStargazers(line, repo_stars.data_points) 46 101 if (i === 1) {