This commit is contained in:
Rizky 2023-10-26 11:22:55 +07:00
parent 9752259b6f
commit 60f38c778c
3 changed files with 6 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import { validate } from "uuid";
import { SAction } from "../actions";
import { SyncConnection } from "../type";
import { actstore, broadcastActivity } from "../entity/actstore";
import { SyncConnection } from "../type";
export const activity: SAction["activity"] = async function (
this: SyncConnection,

View File

@ -21,6 +21,7 @@ export const syncHandler: WebSocketHandler<WSData> = {
const client_id = createId();
conns.set(client_id, {
user_id: "",
user: null,
client_id,
ws,
msg: { pending: {}, resolve: {} },
@ -58,7 +59,9 @@ export const syncHandler: WebSocketHandler<WSData> = {
const msg = packr.unpack(Buffer.from(raw));
if (msg.type === SyncType.UserID) {
const { user_id, page_id, site_id } = msg;
conn.user_id = user_id;
conn.user = await db.user.findFirst({ where: { id: user_id } });
let conf = await user.conf.getOrCreate(user_id);
if (site_id) {

View File

@ -1,6 +1,7 @@
import { ServerWebSocket } from "bun";
import { UserConf } from "./entity/user";
import { WSData } from "../../../../pkgs/core/server/create";
import { user } from "../../../db/db";
export enum SyncType {
ClientID,
@ -12,6 +13,7 @@ export enum SyncType {
export type SyncConnection = {
user_id: string;
user: null | user;
client_id: string;
conf?: UserConf & { toJSON: () => UserConf };
ws: ServerWebSocket<WSData>;