Skip to content

Commit

Permalink
Broadcast new files on reset (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia authored Mar 20, 2024
1 parent 819d63a commit abda2b0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,19 @@ export class Realtime implements DurableObject {
PUT: async (req: Request) => {
const fs = await req.json() as FileSystemNode;

const ts = Date.now();
this.timestamp = ts;
// clears filesystem before writting new files
await this.fs.clear();

await Promise.all(
Object.entries(fs).map(([path, value]) =>
this.fs.writeFile(path, value.content)
this.fs.writeFile(path, value.content).then(
() => {
// TODO (mcandeia) this is not notifying deleted files.
this.broadcast({ path, timestamp: ts });
},
)
),
);

Expand Down

0 comments on commit abda2b0

Please sign in to comment.