GeezerVison is showing github.com — Share: render url on frontend · klimkin/opencode@772e185
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/function/src/api.ts -22Lines changed: 0 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { DurableObject } from "cloudflare:workers" | 2 | 2 | import { randomUUID } from "node:crypto" | 3 | | -import { Base64 } from "js-base64" | 4 | 3 |
| 5 | 4 | type Env = { | 6 | 5 | SYNC_SERVER: DurableObjectNamespace<SyncServer> | @@ -184,9 +183,6 @@ export default { | 184 | 183 |
| 185 | 184 | let info | 186 | 185 | const messages: Record<string, any> = {} | 187 | | - let cost = 0 | 188 | | - const models: Set<string> = new Set() | 189 | | - const version = "v0.1.1" | 190 | 186 | data.forEach((d) => { | 191 | 187 | const [root, type, ...splits] = d.key.split("/") | 192 | 188 | if (root !== "session") return | @@ -197,31 +193,13 @@ export default { | 197 | 193 | if (type === "message") { | 198 | 194 | const [, messageID] = splits | 199 | 195 | 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 | | - } | 206 | 196 | } | 207 | 197 | }) | 208 | 198 |
| 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 | 199 | return new Response( | 221 | 200 | JSON.stringify({ | 222 | 201 | info, | 223 | 202 | messages, | 224 | | - ogImage: `https://social-cards.sst.dev/opencode-share/${encodedTitle}.png?cost=${encodedCost}&model=${Array.from(models).join(",")}&version=${version}&id=${id}`, | 225 | 203 | }), | 226 | 204 | { | 227 | 205 | headers: { "Content-Type": "application/json" }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/web/src/pages/s/[id].astro +25-3Lines changed: 25 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | --- | | 2 | +import { Base64 } from "js-base64"; | 2 | 3 | import config from "virtual:starlight/user-config"; | 3 | 4 |
| 4 | 5 | import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'; | @@ -10,14 +11,35 @@ const { id } = Astro.params; | 10 | 11 | const res = await fetch(`${apiUrl}/share_data?id=${id}`); | 11 | 12 | const data = await res.json(); | 12 | 13 |
| 13 | | -const title = data.info.title; | 14 | | -const ogImage = data.ogImage; | | 14 | +let cost = 0; | | 15 | +const models: Set<string> = new Set(); | | 16 | +const version = "v0.1.1"; | | 17 | +Object.values(data.messages).forEach((d) => { | | 18 | + const assistant = d.metadata?.assistant; | | 19 | + if (assistant) { | | 20 | + cost += assistant.cost; | | 21 | + models.add(assistant.modelID); | | 22 | + } | | 23 | +}); | | 24 | +
| | 25 | +const encodedTitle = encodeURIComponent( | | 26 | + Base64.encode( | | 27 | + // Convert to ASCII | | 28 | + encodeURIComponent( | | 29 | + // Truncate to fit S3's max key size | | 30 | + data.info.title.substring(0, 700), | | 31 | + ) | | 32 | + ) | | 33 | +); | | 34 | +const encodedCost = encodeURIComponent(`$${cost.toFixed(2)}`); | | 35 | +
| | 36 | +const ogImage = `https://social-cards.sst.dev/opencode-share/${encodedTitle}.png?cost=${encodedCost}&model=${Array.from(models).join(",")}&version=${version}&id=${id}`; | 15 | 37 |
| 16 | 38 | --- | 17 | 39 | <StarlightPage | 18 | 40 | hasSidebar={false} | 19 | 41 | frontmatter={{ | 20 | | - title: title, | | 42 | + title: data.info.title, | 21 | 43 | pagefind: false, | 22 | 44 | template: "splash", | 23 | 45 | tableOfContents: false, | |
|