diff --git a/app/srv/ws/sync/user.ts b/app/srv/ws/sync/user.ts index 4472f7dc..53cd616e 100644 --- a/app/srv/ws/sync/user.ts +++ b/app/srv/ws/sync/user.ts @@ -1,5 +1,5 @@ import { dir } from "dir"; -import { open } from "lmdb"; +import { RootDatabase, open } from "lmdb"; import { g } from "utils/global"; const defaultConf = { @@ -8,33 +8,38 @@ const defaultConf = { }; export type UserConf = typeof defaultConf; -const db = open({ - name: "user-conf", - path: dir.path(`${g.datadir}/lmdb/user-conf.lmdb`), -}); - export const user = { conf: { + _db: null as null | RootDatabase, + get db() { + if (!this._db) { + this._db = open({ + name: "user-conf", + path: dir.path(`${g.datadir}/lmdb/user-conf.lmdb`), + }); + } + return this._db; + }, getOrCreate(user_id: string) { - let res = db.get(user_id); + let res = this.db.get(user_id); if (!res) { - db.put(user_id, structuredClone(defaultConf)); - res = db.get(user_id); + this.db.put(user_id, structuredClone(defaultConf)); + res = this.db.get(user_id); } return res as UserConf; }, get(user_id: string) { - return db.get(user_id); + return this.db.get(user_id); }, set(user_id: string, key: T, value: UserConf[T]) { let current = this.get(user_id); if (!current) { - db.put(user_id, structuredClone(defaultConf)); + this.db.put(user_id, structuredClone(defaultConf)); current = this.get(user_id); } if (current) { - db.put(user_id, { ...current, [key]: value }); + this.db.put(user_id, { ...current, [key]: value }); } }, }, diff --git a/app/web/src/base/page/all.tsx b/app/web/src/base/page/all.tsx index 1c838799..33844b5e 100644 --- a/app/web/src/base/page/all.tsx +++ b/app/web/src/base/page/all.tsx @@ -19,6 +19,8 @@ export default page({ } else if (arr.length === 3) { navigate(location.pathname + "/"); } + } else { + navigate("/editor/_/_"); } } else { navigate("/login"); diff --git a/undefined/lmdb/user-conf.lmdb b/undefined/lmdb/user-conf.lmdb index 1c020573..cba48a1e 100644 Binary files a/undefined/lmdb/user-conf.lmdb and b/undefined/lmdb/user-conf.lmdb differ diff --git a/undefined/lmdb/user-conf.lmdb-lock b/undefined/lmdb/user-conf.lmdb-lock index e0fb4523..def258c5 100644 Binary files a/undefined/lmdb/user-conf.lmdb-lock and b/undefined/lmdb/user-conf.lmdb-lock differ