| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 177875f commit edd459e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | import { DurableObject } from "cloudflare:workers" | |
| 2 | 2 | import { randomUUID } from "node:crypto" | |
| 3 | + import { Base64 } from "js-base64" | ||
| 3 | 4 | ||
| 4 | 5 | type Env = { | |
| 5 | 6 | SYNC_SERVER: DurableObjectNamespace<SyncServer> | |
@@ -180,8 +181,12 @@ export default { | |||
| 180 | 181 | return new Response("Error: Share ID is required", { status: 400 }) | |
| 181 | 182 | const stub = env.SYNC_SERVER.get(env.SYNC_SERVER.idFromName(id)) | |
| 182 | 183 | const data = await stub.getData() | |
| 184 | + | ||
| 183 | 185 | let info | |
| 184 | - const messages = {} | ||
| 186 | + const messages: Record<string, any> = {} | ||
| 187 | + let cost = 0 | ||
| 188 | + const models: Set<string> = new Set() | ||
| 189 | + const version = "v0.1.1" | ||
| 185 | 190 | data.forEach((d) => { | |
| 186 | 191 | const [root, type, ...splits] = d.key.split("/") | |
| 187 | 192 | if (root !== "session") return | |
@@ -192,12 +197,36 @@ export default { | |||
| 192 | 197 | if (type === "message") { | |
| 193 | 198 | const [, messageID] = splits | |
| 194 | 199 | messages[messageID] = d.content | |
| 200 | + | ||
| 201 | + const assistant = d.content.metadata?.assistant | ||
| 202 | + if (assistant) { | ||
| 203 | + cost += assistant.cost | ||
| 204 | + models.add(assistant.modelID) | ||
| 205 | + } | ||
| 195 | 206 | } | |
| 196 | 207 | }) | |
| 197 | 208 | ||
| 198 | - return new Response(JSON.stringify({ info, messages }), { | ||
| 199 | - headers: { "Content-Type": "application/json" }, | ||
| 200 | - }) | ||
| 209 | + const encodedTitle = encodeURIComponent( | ||
| 210 | + Base64.encode( | ||
| 211 | + // Convert to ASCII | ||
| 212 | + encodeURIComponent( | ||
| 213 | + // Truncate to fit S3's max key size | ||
| 214 | + info.title.substring(0, 700), | ||
| 215 | + ), | ||
| 216 | + ), | ||
| 217 | + ) | ||
| 218 | + const encodedCost = encodeURIComponent(`$${cost.toFixed(2)}`) | ||
| 219 | + | ||
| 220 | + return new Response( | ||
| 221 | + JSON.stringify({ | ||
| 222 | + info, | ||
| 223 | + messages, | ||
| 224 | + ogImage: `https://social-cards.sst.dev/opencode-share/${encodedTitle}.png?cost=${encodedCost}&model=${Array.from(models).join(",")}&version=${version}&id=${id}`, | ||
| 225 | + }), | ||
| 226 | + { | ||
| 227 | + headers: { "Content-Type": "application/json" }, | ||
| 228 | + }, | ||
| 229 | + ) | ||
| 201 | 230 | } | |
| 202 | 231 | }, | |
| 203 | 232 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,4 @@ | |||
| 1 | 1 | --- | |
| 2 | - import { Base64 } from "js-base64"; | ||
| 3 | 2 | import config from "virtual:starlight/user-config"; | |
| 4 | 3 | ||
| 5 | 4 | import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; | |
@@ -12,23 +11,7 @@ const res = await fetch(`${apiUrl}/share_data?id=${id}`); | |||
| 12 | 11 | const data = await res.json(); | |
| 13 | 12 | ||
| 14 | 13 | const title = data.info.title; | |
| 15 | - | ||
| 16 | - const encodedTitle = encodeURIComponent( | ||
| 17 | - Base64.encode( | ||
| 18 | - // Convert to ASCII | ||
| 19 | - encodeURIComponent( | ||
| 20 | - // Truncate to fit S3's max key size | ||
| 21 | - title.substring(0, 700) | ||
| 22 | - ) | ||
| 23 | - ) | ||
| 24 | - ) | ||
| 25 | - | ||
| 26 | - const cardService = "https://social-cards.sst.dev"; | ||
| 27 | - const cost = "$0.12"; | ||
| 28 | - const model = "claude-sonnet-4-20250514,claude-opus-4-20250514"; | ||
| 29 | - const version = "v0.1.1"; | ||
| 30 | - // ?cost=$0.12&model=claude-sonnet-4-20250514,claude-opus-4-20250514&version=v0.1.1&id=43120e6b | ||
| 31 | - const ogImageUrl = `${cardService}/opencode-share/${encodedTitle}.png?cost=${cost}&model=${model}&version=${version}&id=${id}`; | ||
| 14 | + const ogImage = data.ogImage; | ||
| 32 | 15 | ||
| 33 | 16 | --- | |
| 34 | 17 | <StarlightPage | |
@@ -43,14 +26,14 @@ const ogImageUrl = `${cardService}/opencode-share/${encodedTitle}.png?cost=${cos | |||
| 43 | 26 | tag: "meta", | |
| 44 | 27 | attrs: { | |
| 45 | 28 | property: "og:image", | |
| 46 | - content: ogImageUrl, | ||
| 29 | + content: ogImage, | ||
| 47 | 30 | }, | |
| 48 | 31 | }, | |
| 49 | 32 | { | |
| 50 | 33 | tag: "meta", | |
| 51 | 34 | attrs: { | |
| 52 | 35 | name: "twitter:image", | |
| 53 | - content: ogImageUrl, | ||
| 36 | + content: ogImage, | ||
| 54 | 37 | }, | |
| 55 | 38 | }, | |
| 56 | 39 | ], | |
| Back | FazBrowse Home | New Git URL |
0 commit comments