-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reorganize project according with responsibilities
- Loading branch information
Showing
63 changed files
with
131 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { MongoClient } from "mongodb"; | ||
|
||
const MONGODB_URI = process.env.MONGODB_URI; | ||
if (!MONGODB_URI) { | ||
throw new Error( | ||
"Please define the MONGODB_URI environment variable inside .env", | ||
); | ||
} | ||
|
||
const client = await MongoClient.connect(MONGODB_URI); | ||
|
||
export const db = client.db(MONGODB_URI.split("/").pop()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
packages/main/src/plugins/config.ts → packages/homeserver/src/plugins/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import Elysia from "elysia"; | ||
import type { InferContext } from "elysia"; | ||
import type { SigningKey } from "../keys"; | ||
|
||
import { config } from "../config"; | ||
export interface Config { | ||
path: string; | ||
signingKeyPath: string; | ||
port: number; | ||
signingKey: SigningKey[]; | ||
name: string; | ||
version: string; | ||
} | ||
|
||
export const routerWithConfig = new Elysia().decorate("config", config); | ||
export const routerWithConfig = new Elysia().decorate("config", {} as Config); | ||
|
||
export type Context = InferContext<typeof routerWithConfig>; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import Elysia from "elysia"; | ||
import type { InferContext } from "elysia"; | ||
import { type Db, MongoClient } from "mongodb"; | ||
|
||
import { NotFoundError } from "elysia"; | ||
import type { EventBase } from "../events/eventBase"; | ||
|
||
export const routerWithMongodb = (db: Db) => | ||
new Elysia().decorate("mongo", () => { | ||
const eventsCollection = db.collection<EventStore>("events"); | ||
|
||
const getLastEvent = async (roomId: string) => { | ||
const events = await eventsCollection | ||
.find({ "event.room_id": roomId }, { sort: { "event.depth": -1 } }) | ||
.toArray(); | ||
|
||
if (events.length === 0) { | ||
throw new NotFoundError(`No events found for room ${roomId}`); | ||
} | ||
|
||
return events[0]; | ||
}; | ||
|
||
const getAuthEvents = async (roomId: string) => { | ||
return eventsCollection | ||
.find( | ||
{ | ||
"event.room_id": roomId, | ||
$or: [ | ||
{ | ||
"event.type": { | ||
$in: [ | ||
"m.room.create", | ||
"m.room.power_levels", | ||
"m.room.join_rules", | ||
], | ||
}, | ||
}, | ||
{ | ||
// Lots of room members, when including the join ones it fails the auth check | ||
"event.type": "m.room.member", | ||
"event.content.membership": "invite", | ||
}, | ||
], | ||
}, | ||
{ | ||
projection: { | ||
_id: 1, | ||
}, | ||
}, | ||
) | ||
.toArray(); | ||
}; | ||
|
||
return { | ||
eventsCollection, | ||
getLastEvent, | ||
getAuthEvents, | ||
}; | ||
}); | ||
|
||
export type Context = InferContext<ReturnType<typeof routerWithMongodb>>; | ||
|
||
export type EventStore = { | ||
_id: string; | ||
event: EventBase; | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.