Просмотр исходного кода

Api: only return session messages

Frank 8 месяцев назад
Родитель
Сommit
e054454109
1 измененных файлов с 6 добавлено и 8 удалено
  1. 6 8
      packages/function/src/api.ts

+ 6 - 8
packages/function/src/api.ts

@@ -19,9 +19,9 @@ export class SyncServer extends DurableObject<Env> {
     this.ctx.acceptWebSocket(server)
 
     const data = await this.ctx.storage.list()
-    for (const [key, content] of data.entries()) {
-      server.send(JSON.stringify({ key, content }))
-    }
+    Array.from(data.entries())
+      .filter(([key, _]) => key.startsWith("session/"))
+      .map(([key, content]) => server.send(JSON.stringify({ key, content })))
 
     return new Response(null, {
       status: 101,
@@ -71,11 +71,9 @@ export class SyncServer extends DurableObject<Env> {
 
   public async getData() {
     const data = await this.ctx.storage.list()
-    const messages = []
-    for (const [key, content] of data.entries()) {
-      messages.push({ key, content })
-    }
-    return messages
+    return Array.from(data.entries())
+      .filter(([key, _]) => key.startsWith("session/"))
+      .map(([key, content]) => ({ key, content }))
   }
 
   private async getSecret() {