Skip to content

Commit

Permalink
move-storage-responsibility
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Nov 2, 2024
1 parent d78b9d2 commit b74d64b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TaskHandler } from "./api.ts";
import type { Endpoint } from "./taskBouncer.ts";
import { makeKey, now, websocketInject } from "./websocket.ts";
import { now, websocketInject } from "./websocket.ts";

type ClientRequest = { from: string; text: string; token: string };

Expand All @@ -14,11 +14,11 @@ export const makeDatabaseHandler = (
bounce: true,
predicate: ({ url, method }) => url === path && method === "POST",
handler: async ({ from, text, token }: ClientRequest) => {
if (!await authenticate(token, from)) return;
await storer({ from, to: botName, key: makeKey(), text, time: now() });
return websocketInject(
(x) => storer({ ...x, time: now(), from: botName, to: from }),
from,
)(doTask)({ text });
if (await authenticate(token, from)) {
return websocketInject(
(x) => storer({ ...x, time: now(), from: botName, to: from }),
from,
)(doTask)({ text });
}
},
});
2 changes: 1 addition & 1 deletion src/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Manager = {
buffered: Record<string, WeboscketMessage[]>;
};

export const makeKey = () => crypto.randomUUID();
const makeKey = () => crypto.randomUUID();

export const now = () => Date.now();

Expand Down

0 comments on commit b74d64b

Please sign in to comment.