diff options
| author | Frank <[email protected]> | 2025-06-08 01:17:54 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-06-08 01:17:54 -0400 |
| commit | 1d782dc19aa523a8ae81a6c589036291124e8bd9 (patch) | |
| tree | 05d9bf73f1bd4b7c2fe44db3533882ff86cdafab /packages/function/src/api.ts | |
| parent | 879d02f86c2c45860f064611b643ed1d2af4de0a (diff) | |
| download | opencode-1d782dc19aa523a8ae81a6c589036291124e8bd9.tar.gz opencode-1d782dc19aa523a8ae81a6c589036291124e8bd9.zip | |
Share: load server data on page load
Diffstat (limited to 'packages/function/src/api.ts')
| -rw-r--r-- | packages/function/src/api.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/function/src/api.ts b/packages/function/src/api.ts index 3e2ce9eca..b058321c0 100644 --- a/packages/function/src/api.ts +++ b/packages/function/src/api.ts @@ -69,6 +69,15 @@ export class SyncServer extends DurableObject<Env> { return secret } + public async messages() { + const data = await this.ctx.storage.list() + const messages = [] + for (const [key, content] of data.entries()) { + messages.push({ key, content }) + } + return messages + } + private async getSecret() { return this.ctx.storage.get<string>("secret") } @@ -163,5 +172,17 @@ export default { const stub = env.SYNC_SERVER.get(env.SYNC_SERVER.idFromName(id)) return stub.fetch(request) } + + if (request.method === "GET" && method === "share_messages") { + const id = url.searchParams.get("id") + console.log("share_messages", id) + if (!id) + return new Response("Error: Share ID is required", { status: 400 }) + const stub = env.SYNC_SERVER.get(env.SYNC_SERVER.idFromName(id)) + const messages = await stub.messages() + return new Response(JSON.stringify({ messages }), { + headers: { "Content-Type": "application/json" }, + }) + } }, } |
