GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Temporarily add admin unshare api · klimkin/opencode@4a5a93b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/function/src
    • api.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/function/src/api.ts‎

Copy file name to clipboardExpand all lines: packages/function/src/api.ts
+28-10Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export class SyncServer extends DurableObject<Env> {
3535
ws.close(code, "Durable Object is closing WebSocket")
3636
}
3737

38-
async publish(secret: string, key: string, content: any) {
39-
if (secret !== (await this.getSecret())) throw new Error("Invalid secret")
38+
async publish(key: string, content: any) {
4039
const sessionID = await this.getSessionID()
4140
if (
4241
!key.startsWith(`session/info/${sessionID}`) &&
@@ -76,6 +75,10 @@ export class SyncServer extends DurableObject<Env> {
7675
.map(([key, content]) => ({ key, content }))
7776
}
7877

78+
public async assertSecret(secret: string) {
79+
if (secret !== (await this.getSecret())) throw new Error("Invalid secret")
80+
}
81+
7982
private async getSecret() {
8083
return this.ctx.storage.get<string>("secret")
8184
}
@@ -84,15 +87,19 @@ export class SyncServer extends DurableObject<Env> {
8487
return this.ctx.storage.get<string>("sessionID")
8588
}
8689

87-
async clear(secret: string) {
88-
await this.assertSecret(secret)
90+
async clear() {
91+
const sessionID = await this.getSessionID()
92+
const list = await this.env.Bucket.list({
93+
prefix: `session/message/${sessionID}/`,
94+
limit: 1000,
95+
})
96+
for (const item of list.objects) {
97+
await this.env.Bucket.delete(item.key)
98+
}
99+
await this.env.Bucket.delete(`session/info/${sessionID}`)
89100
await this.ctx.storage.deleteAll()
90101
}
91102

92-
private async assertSecret(secret: string) {
93-
if (secret !== (await this.getSecret())) throw new Error("Invalid secret")
94-
}
95-
96103
static shortName(id: string) {
97104
return id.substring(id.length - 8)
98105
}
@@ -134,7 +141,17 @@ export default {
134141
const secret = body.secret
135142
const id = env.SYNC_SERVER.idFromName(SyncServer.shortName(sessionID))
136143
const stub = env.SYNC_SERVER.get(id)
137-
await stub.clear(secret)
144+
await stub.assertSecret(secret)
145+
await stub.clear()
146+
return new Response(JSON.stringify({}), {
147+
headers: { "Content-Type": "application/json" },
148+
})
149+
}
150+
151+
if (request.method === "POST" && method === "share_delete_admin") {
152+
const id = env.SYNC_SERVER.idFromName("oVF8Rsiv")
153+
const stub = env.SYNC_SERVER.get(id)
154+
await stub.clear()
138155
return new Response(JSON.stringify({}), {
139156
headers: { "Content-Type": "application/json" },
140157
})
@@ -150,7 +167,8 @@ export default {
150167
const name = SyncServer.shortName(body.sessionID)
151168
const id = env.SYNC_SERVER.idFromName(name)
152169
const stub = env.SYNC_SERVER.get(id)
153-
await stub.publish(body.secret, body.key, body.content)
170+
await stub.assertSecret(body.secret)
171+
await stub.publish(body.key, body.content)
154172
return new Response(JSON.stringify({}), {
155173
headers: { "Content-Type": "application/json" },
156174
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.