summaryrefslogtreecommitdiffhomepage
path: root/packages/function/src
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-07-01 18:57:08 -0400
committerFrank <[email protected]>2025-07-01 18:57:08 -0400
commit4a5a93b3f87b3ed786927648073fb7c60c01d596 (patch)
tree913febf102bd4c4ca1f213634e80c49d06fc236f /packages/function/src
parente99bdcefac44db9251ac08b515a6b1f5af42610c (diff)
downloadopencode-4a5a93b3f87b3ed786927648073fb7c60c01d596.tar.gz
opencode-4a5a93b3f87b3ed786927648073fb7c60c01d596.zip
Temporarily add admin unshare api
Diffstat (limited to 'packages/function/src')
-rw-r--r--packages/function/src/api.ts38
1 files changed, 28 insertions, 10 deletions
diff --git a/packages/function/src/api.ts b/packages/function/src/api.ts
index 1d0e2cd07..0d5e44df1 100644
--- a/packages/function/src/api.ts
+++ b/packages/function/src/api.ts
@@ -35,8 +35,7 @@ export class SyncServer extends DurableObject<Env> {
ws.close(code, "Durable Object is closing WebSocket")
}
- async publish(secret: string, key: string, content: any) {
- if (secret !== (await this.getSecret())) throw new Error("Invalid secret")
+ async publish(key: string, content: any) {
const sessionID = await this.getSessionID()
if (
!key.startsWith(`session/info/${sessionID}`) &&
@@ -76,6 +75,10 @@ export class SyncServer extends DurableObject<Env> {
.map(([key, content]) => ({ key, content }))
}
+ public async assertSecret(secret: string) {
+ if (secret !== (await this.getSecret())) throw new Error("Invalid secret")
+ }
+
private async getSecret() {
return this.ctx.storage.get<string>("secret")
}
@@ -84,15 +87,19 @@ export class SyncServer extends DurableObject<Env> {
return this.ctx.storage.get<string>("sessionID")
}
- async clear(secret: string) {
- await this.assertSecret(secret)
+ async clear() {
+ const sessionID = await this.getSessionID()
+ const list = await this.env.Bucket.list({
+ prefix: `session/message/${sessionID}/`,
+ limit: 1000,
+ })
+ for (const item of list.objects) {
+ await this.env.Bucket.delete(item.key)
+ }
+ await this.env.Bucket.delete(`session/info/${sessionID}`)
await this.ctx.storage.deleteAll()
}
- private async assertSecret(secret: string) {
- if (secret !== (await this.getSecret())) throw new Error("Invalid secret")
- }
-
static shortName(id: string) {
return id.substring(id.length - 8)
}
@@ -134,7 +141,17 @@ export default {
const secret = body.secret
const id = env.SYNC_SERVER.idFromName(SyncServer.shortName(sessionID))
const stub = env.SYNC_SERVER.get(id)
- await stub.clear(secret)
+ await stub.assertSecret(secret)
+ await stub.clear()
+ return new Response(JSON.stringify({}), {
+ headers: { "Content-Type": "application/json" },
+ })
+ }
+
+ if (request.method === "POST" && method === "share_delete_admin") {
+ const id = env.SYNC_SERVER.idFromName("oVF8Rsiv")
+ const stub = env.SYNC_SERVER.get(id)
+ await stub.clear()
return new Response(JSON.stringify({}), {
headers: { "Content-Type": "application/json" },
})
@@ -150,7 +167,8 @@ export default {
const name = SyncServer.shortName(body.sessionID)
const id = env.SYNC_SERVER.idFromName(name)
const stub = env.SYNC_SERVER.get(id)
- await stub.publish(body.secret, body.key, body.content)
+ await stub.assertSecret(body.secret)
+ await stub.publish(body.key, body.content)
return new Response(JSON.stringify({}), {
headers: { "Content-Type": "application/json" },
})