summaryrefslogtreecommitdiffhomepage
path: root/packages/function/src/api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/function/src/api.ts')
-rw-r--r--packages/function/src/api.ts21
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" },
+ })
+ }
},
}