1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-26 04:03:03 +01:00

comments and such

This commit is contained in:
Madeline 2022-12-17 19:00:40 +11:00
parent fa0ef52258
commit 64fd33cdc9
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
2 changed files with 9 additions and 47 deletions

View File

@ -54,12 +54,14 @@ async function main() {
Sentry.addGlobalEventProcessor((event, hint) => { Sentry.addGlobalEventProcessor((event, hint) => {
if (event.transaction) { if (event.transaction) {
// Rewrite things that look like IDs to `:id` for sentry
event.transaction = event.transaction event.transaction = event.transaction
.split("/") .split("/")
.map((x) => (!parseInt(x) ? x : ":id")) .map((x) => (!parseInt(x) ? x : ":id"))
.join("/"); .join("/");
} }
// TODO: does this even do anything?
delete event.request?.cookies; delete event.request?.cookies;
if (event.request?.headers) { if (event.request?.headers) {
delete event.request.headers["X-Real-Ip"]; delete event.request.headers["X-Real-Ip"];
@ -70,16 +72,11 @@ async function main() {
if (event.breadcrumbs) { if (event.breadcrumbs) {
event.breadcrumbs = event.breadcrumbs.filter((x) => { event.breadcrumbs = event.breadcrumbs.filter((x) => {
// Filter breadcrumbs that we don't care about
if (x.message?.includes("identified as")) return false; if (x.message?.includes("identified as")) return false;
if (x.message?.includes("[WebSocket] closed")) return false; if (x.message?.includes("[WebSocket] closed")) return false;
if ( if (x.message?.includes("Got Resume -> cancel not implemented")) return false;
x.message?.includes( if (x.message?.includes("[Gateway] New connection from")) return false;
"Got Resume -> cancel not implemented",
)
)
return false;
if (x.message?.includes("[Gateway] New connection from"))
return false;
return true; return true;
}); });

View File

@ -12,12 +12,14 @@ var dbConnection: DataSource | undefined;
let dbConnectionString = let dbConnectionString =
process.env.DATABASE || path.join(process.cwd(), "database.db"); process.env.DATABASE || path.join(process.cwd(), "database.db");
// Gets the existing database connection
export function getDatabase(): DataSource | null { export function getDatabase(): DataSource | null {
// if (!dbConnection) throw new Error("Tried to get database before it was initialised"); // if (!dbConnection) throw new Error("Tried to get database before it was initialised");
if (!dbConnection) return null; if (!dbConnection) return null;
return dbConnection; return dbConnection;
} }
// Called once on server start
export async function initDatabase(): Promise<DataSource> { export async function initDatabase(): Promise<DataSource> {
if (dbConnection) return dbConnection; if (dbConnection) return dbConnection;
@ -36,7 +38,7 @@ export async function initDatabase(): Promise<DataSource> {
} }
const dataSource = new DataSource({ const dataSource = new DataSource({
//@ts-ignore //@ts-ignore type 'string' is not 'mysql' | 'sqlite' | 'mariadb' | etc etc
type, type,
charset: "utf8mb4", charset: "utf8mb4",
url: isSqlite ? undefined : dbConnectionString, url: isSqlite ? undefined : dbConnectionString,
@ -47,49 +49,12 @@ export async function initDatabase(): Promise<DataSource> {
bigNumberStrings: false, bigNumberStrings: false,
supportBigNumbers: true, supportBigNumbers: true,
name: "default", name: "default",
// TODO migrations
// migrations: [path.join(__dirname, "..", "migrations", "*.js")], // migrations: [path.join(__dirname, "..", "migrations", "*.js")],
}); });
dbConnection = await dataSource.initialize(); dbConnection = await dataSource.initialize();
// // @ts-ignore
// promise = createConnection({
// type,
// charset: 'utf8mb4',
// url: isSqlite ? undefined : dbConnectionString,
// database: isSqlite ? dbConnectionString : undefined,
// // @ts-ignore
// entities: Object.values(Models).filter((x) => x?.constructor?.name !== "Object" && x?.name),
// synchronize: type !== "mongodb",
// logging: false,
// // cache: { // cache is used only by query builder and entity manager
// // duration: 1000 * 30,
// // type: "redis",
// // options: {
// // host: "localhost",
// // port: 6379,
// // },
// // },
// bigNumberStrings: false,
// supportBigNumbers: true,
// name: "default",
// migrations: [path.join(__dirname, "..", "migrations", "*.js")],
// });
// // run migrations, and if it is a new fresh database, set it to the last migration
// if (dbConnection.migrations.length) {
// if (!(await Migration.findOne({ }))) {
// let i = 0;
// await Migration.insert(
// dbConnection.migrations.map((x) => ({
// id: i++,
// name: x.name,
// timestamp: Date.now(),
// }))
// );
// }
// }
await dbConnection.runMigrations(); await dbConnection.runMigrations();
console.log(`[Database] ${green("connected")}`); console.log(`[Database] ${green("connected")}`);