Procházet zdrojové kódy

fix(stats): serve stats og image from banner

Adam před 2 měsíci
rodič
revize
d08fedaccc

+ 1 - 1
infra/stats.ts

@@ -165,7 +165,7 @@ export const app = new sst.cloudflare.x.SolidStart("Stats", {
   domain: `stats.${domain}`,
   link: [database, EMAILOCTOPUS_API_KEY],
   environment: {
-    PUBLIC_URL: `https://stats.${domain}/stats`,
+    PUBLIC_URL: `https://${domain}/stats`,
   },
 })
 

+ 1 - 1
packages/console/app/src/lib/stats-proxy.ts

@@ -8,7 +8,7 @@ export async function statsProxy(evt: APIEvent) {
   targetUrl.hostname = Resource.App.stage === "production" ? "stats.opencode.ai" : "stats.dev.opencode.ai"
   targetUrl.port = ""
 
-  if (targetUrl.pathname.startsWith("/stats/_build/")) {
+  if (targetUrl.pathname.startsWith("/stats/_build/") || targetUrl.pathname === "/stats/banner.png") {
     targetUrl.pathname = targetUrl.pathname.slice("/stats".length)
   }
 

binární
packages/stats/app/public/banner.png


binární
packages/stats/app/src/asset/unfurl-rankings.png


+ 12 - 5
packages/stats/app/src/routes/index.tsx

@@ -11,7 +11,6 @@ import ibmPlexMonoMediumLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/I
 import ibmPlexMonoSemiBoldLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/IBMPlexMono-SemiBold-Latin1.woff2?url"
 import ibmPlexMonoBoldLatin1 from "@ibm/plex/IBM-Plex-Mono/fonts/split/woff2/IBMPlexMono-Bold-Latin1.woff2?url"
 import opencodeWordmarkDark from "../asset/logo-ornate-dark.svg"
-import statsUnfurlRankings from "../asset/unfurl-rankings.png?url"
 import {
   getStatsHomeData,
   type CacheRatioEntry,
@@ -42,7 +41,8 @@ const rangeLabels: Record<UsageRange, string> = {
 }
 const statsHomeTitle = "OpenCode Stats"
 const statsHomeDescription = "OpenCode usage, market share, token cost, and session cost stats."
-const statsHomeFallbackUrl = "https://stats.opencode.ai"
+const statsHomeFallbackUrl = "https://opencode.ai/stats/"
+const statsUnfurlPath = "banner.png"
 const statsUnfurlAlt = "OpenCode Stats wordmark on a dark patterned background"
 const headerLinks = [
   { href: "#top-models", label: "Top Models" },
@@ -147,11 +147,11 @@ const getGitHubStars = query(async () => {
 export default function StatsHome() {
   const event = getRequestEvent()
   event?.response.headers.set("Cache-Control", "public, max-age=60, s-maxage=300, stale-while-revalidate=86400")
-  const statsHomeUrl = new URL(
+  const statsHomeUrl = getStatsHomeUrl(
     import.meta.env.BASE_URL,
     event?.request.url ?? (typeof window === "undefined" ? statsHomeFallbackUrl : window.location.href),
-  ).toString()
-  const statsUnfurlUrl = new URL(statsUnfurlRankings, statsHomeUrl).toString()
+  )
+  const statsUnfurlUrl = new URL(statsUnfurlPath, statsHomeUrl).toString()
   const data = createAsync(() => getData())
   const githubStars = createAsync(() => getGitHubStars())
   const [themePreference, setThemePreference] = createSignal<ThemePreference>("system")
@@ -217,6 +217,13 @@ export default function StatsHome() {
   )
 }
 
+function getStatsHomeUrl(base: string, requestUrl: string) {
+  const url = new URL(base, requestUrl)
+  if (url.hostname === "stats.opencode.ai") return "https://opencode.ai/stats/"
+  if (url.hostname === "stats.dev.opencode.ai") return "https://dev.opencode.ai/stats/"
+  return url.toString()
+}
+
 function isThemePreference(value: string | null): value is ThemePreference {
   return value === "dark" || value === "light" || value === "system"
 }