Refactor Storages to get lazy-loaded only when they are used

This commit is contained in:
Alex Gleason
2024-05-01 14:56:47 -05:00
parent a6681a97d9
commit c190d2c8ce
27 changed files with 175 additions and 140 deletions

View File

@@ -1,16 +1,16 @@
import { AppMiddleware } from '@/app.ts';
import { UserStore } from '@/storages/UserStore.ts';
import { getAdminStore } from '@/storages/adminStore.ts';
import { Storages } from '@/storages.ts';
/** Store middleware. */
const storeMiddleware: AppMiddleware = async (c, next) => {
const pubkey = c.get('pubkey');
const adminStore = getAdminStore();
if (pubkey) {
const store = new UserStore(pubkey, adminStore);
const store = new UserStore(pubkey, Storages.admin);
c.set('store', store);
} else {
c.set('store', adminStore);
c.set('store', Storages.admin);
}
await next();
};