summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/fetchGhStars.ts
diff options
context:
space:
mode:
authorPulkit Garg <pulkitgargbnl@gmail.com>2025-06-24 10:49:15 +0530
committerGitHub <noreply@github.com>2025-06-24 10:49:15 +0530
commitf0e305cfe6e0f519f9e12246bf0816d246b5fbf7 (patch)
treea0e3c402e2f5ddd4c9b63785878ad73a205a1326 /apps/web/src/lib/fetchGhStars.ts
parente664ea0271a9c34bb7290447823367ba6fffac7d (diff)
parentaa6d42c517a3732a9fbd7ddb81de120ba0e4b545 (diff)
downloadopencut-f0e305cfe6e0f519f9e12246bf0816d246b5fbf7.tar.gz
Merge branch 'main' into main
Diffstat (limited to 'apps/web/src/lib/fetchGhStars.ts')
-rw-r--r--apps/web/src/lib/fetchGhStars.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/apps/web/src/lib/fetchGhStars.ts b/apps/web/src/lib/fetchGhStars.ts
new file mode 100644
index 00000000..e0236840
--- /dev/null
+++ b/apps/web/src/lib/fetchGhStars.ts
@@ -0,0 +1,29 @@
+export async function getStars(): Promise<string> {
+ try {
+ const res = await fetch(
+ "https://api.github.com/repos/OpenCut-app/OpenCut",
+ {
+ next: { revalidate: 3600 },
+ }
+ );
+
+ if (!res.ok) {
+ throw new Error(`GitHub API error: ${res.status} ${res.statusText}`);
+ }
+ const data = await res.json();
+ const count = data.stargazers_count;
+
+ if (typeof count !== "number") {
+ throw new Error("Invalid stargazers_count from GitHub API");
+ }
+
+ if (count >= 1_000_000)
+ return (count / 1_000_000).toFixed(1).replace(/\.0$/, "") + "M";
+ if (count >= 1_000)
+ return (count / 1_000).toFixed(1).replace(/\.0$/, "") + "k";
+ return count.toString();
+ } catch (error) {
+ console.error("Failed to fetch GitHub stars:", error);
+ return "1.5k";
+ }
+}