d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { env } from '@/lib/core/config/env'
|
|
|
|
const logger = createLogger('GitHubStars')
|
|
|
|
/**
|
|
* Floor shown only when the live GitHub count can't be fetched. Kept a touch
|
|
* below the real count (~28.9k as of 2026-06) so it never overstates, and
|
|
* bumped periodically.
|
|
*/
|
|
const FALLBACK_STAR_COUNT = 28900
|
|
|
|
/**
|
|
* Formats a raw star count for display (e.g. 28900 → "28.9k").
|
|
*/
|
|
export function formatStarCount(num: number): string {
|
|
if (num < 1000) return String(num)
|
|
const formatted = (Math.round(num / 100) / 10).toFixed(1)
|
|
return formatted.endsWith('.0') ? `${formatted.slice(0, -2)}k` : `${formatted}k`
|
|
}
|
|
|
|
/**
|
|
* Fetches the Sim repository's GitHub star count, formatted for display.
|
|
*
|
|
* Server-only. The upstream fetch is cached for 1 hour via Next.js fetch
|
|
* caching, so statically rendered pages (landing) and the `/api/stars`
|
|
* route share one cached value. Falls back to a static count on failure —
|
|
* never throws.
|
|
*/
|
|
export async function getGitHubStars(): Promise<string> {
|
|
try {
|
|
const token = env.GITHUB_TOKEN
|
|
const response = await fetch('https://api.github.com/repos/simstudioai/sim', {
|
|
headers: {
|
|
Accept: 'application/vnd.github+json',
|
|
'X-GitHub-Api-Version': '2022-11-28',
|
|
'User-Agent': 'Sim/1.0',
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
},
|
|
next: { revalidate: 3600 },
|
|
cache: 'force-cache',
|
|
})
|
|
|
|
if (!response.ok) {
|
|
logger.warn('GitHub API request failed:', response.status)
|
|
return formatStarCount(FALLBACK_STAR_COUNT)
|
|
}
|
|
|
|
const data = await response.json()
|
|
return formatStarCount(Number(data?.stargazers_count ?? FALLBACK_STAR_COUNT))
|
|
} catch (error) {
|
|
logger.warn('Error fetching GitHub stars:', error)
|
|
return formatStarCount(FALLBACK_STAR_COUNT)
|
|
}
|
|
}
|