mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
Share: load server data on page load
This commit is contained in:
parent
879d02f86c
commit
1d782dc19a
3 changed files with 329 additions and 132 deletions
|
@ -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" },
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue