mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat: create user store middleware
This commit is contained in:
parent
606ab58c0a
commit
7b864482bf
1 changed files with 22 additions and 0 deletions
22
src/middleware/userStore.ts
Normal file
22
src/middleware/userStore.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { AppMiddleware } from '@/app.ts';
|
||||
import { UserStore } from '@/storages/UserStore.ts';
|
||||
import { eventsDB } from '@/storages.ts';
|
||||
import { HTTPException } from 'hono';
|
||||
|
||||
/** User Store middleware.
|
||||
* Throw a 500 if can't set the `userStore` */
|
||||
const setUserStore: AppMiddleware = async (c, next) => {
|
||||
const pubkey = c.get('pubkey') as string;
|
||||
|
||||
try {
|
||||
const store = new UserStore(pubkey, eventsDB);
|
||||
c.set('userStore', store);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
throw new HTTPException(500);
|
||||
}
|
||||
|
||||
await next();
|
||||
};
|
||||
|
||||
export { setUserStore };
|
||||
Loading…
Add table
Reference in a new issue