1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 02:12:40 +01:00

Merge pull request #1236 from dank074/patch/prettier

This commit is contained in:
Madeline 2024-11-20 12:00:26 +11:00 committed by GitHub
commit 43b342a152
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 157 additions and 128 deletions

View File

@ -11,10 +11,11 @@ const __dirname = path.dirname(__filename);
const compat = new FlatCompat({ const compat = new FlatCompat({
baseDirectory: __dirname, baseDirectory: __dirname,
recommendedConfig: js.configs.recommended, recommendedConfig: js.configs.recommended,
allConfig: js.configs.all allConfig: js.configs.all,
}); });
export default [{ export default [
{
ignores: [ ignores: [
"**/node_modules", "**/node_modules",
"**/dist", "**/dist",
@ -24,7 +25,12 @@ export default [{
"**/scripts/", "**/scripts/",
"**/assets", "**/assets",
], ],
}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), { },
...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
),
{
plugins: { plugins: {
"@typescript-eslint": typescriptEslint, "@typescript-eslint": typescriptEslint,
}, },
@ -44,4 +50,5 @@ export default [{
"@typescript-eslint/no-require-imports": "off", "@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "off",
}, },
}]; },
];

View File

@ -1,23 +1,23 @@
{ {
"folders": [ "folders": [
{ {
"path": "src" "path": "src",
}, },
{ {
"path": "assets" "path": "assets",
}, },
{ {
"path": "scripts" "path": "scripts",
}, },
{ {
"path": "." "path": ".",
} },
], ],
"settings": { "settings": {
"typescript.tsdk": "util\\node_modules\\typescript\\lib" "typescript.tsdk": "util\\node_modules\\typescript\\lib",
}, },
"launch": { "launch": {
"version": "0.2.0", "version": "0.2.0",
"configurations": [] "configurations": [],
} },
} }

View File

@ -100,8 +100,7 @@ export class SpacebarServer extends Server {
this.app.set("json replacer", JSONReplacer); this.app.set("json replacer", JSONReplacer);
const trustedProxies = Config.get().security.trustedProxies; const trustedProxies = Config.get().security.trustedProxies;
if(trustedProxies) if (trustedProxies) this.app.set("trust proxy", trustedProxies);
this.app.set("trust proxy", trustedProxies);
this.app.use(CORS); this.app.use(CORS);
this.app.use(BodyParser({ inflate: true, limit: "10mb" })); this.app.use(BodyParser({ inflate: true, limit: "10mb" }));

View File

@ -89,11 +89,13 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
} }
try { try {
return await Sentry.startSpan( // Emma [it/its]@Rory&: is this the right function to migrate to in v8? return await Sentry.startSpan(
// Emma [it/its]@Rory&: is this the right function to migrate to in v8?
{ {
op: "websocket.server", op: "websocket.server",
name: `GATEWAY ${OPCODES[data.op]}`, name: `GATEWAY ${OPCODES[data.op]}`,
attributes: { // this needs to be reworked :) attributes: {
// this needs to be reworked :)
...data.d, ...data.d,
token: data?.d?.token ? "[Redacted]" : undefined, token: data?.d?.token ? "[Redacted]" : undefined,
}, },

View File

@ -82,7 +82,7 @@ export async function setupListener(this: WebSocket) {
const opts: { const opts: {
acknowledge: boolean; acknowledge: boolean;
channel?: AMQChannel & { queues?: unknown, ch?: number }; channel?: AMQChannel & { queues?: unknown; ch?: number };
} = { } = {
acknowledge: true, acknowledge: true,
}; };
@ -91,10 +91,20 @@ export async function setupListener(this: WebSocket) {
console.log("[RabbitMQ] setupListener: open for ", this.user_id); console.log("[RabbitMQ] setupListener: open for ", this.user_id);
if (RabbitMQ.connection) { if (RabbitMQ.connection) {
console.log("[RabbitMQ] setupListener: opts.channel = ", typeof opts.channel, "with channel id", opts.channel?.ch); console.log(
"[RabbitMQ] setupListener: opts.channel = ",
typeof opts.channel,
"with channel id",
opts.channel?.ch,
);
opts.channel = await RabbitMQ.connection.createChannel(); opts.channel = await RabbitMQ.connection.createChannel();
opts.channel.queues = {}; opts.channel.queues = {};
console.log("[RabbitMQ] channel created: ", typeof opts.channel, "with channel id", opts.channel?.ch); console.log(
"[RabbitMQ] channel created: ",
typeof opts.channel,
"with channel id",
opts.channel?.ch,
);
} }
this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts); this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts);
@ -132,7 +142,14 @@ export async function setupListener(this: WebSocket) {
}); });
this.once("close", () => { this.once("close", () => {
console.log("[RabbitMQ] setupListener: close for", this.user_id, "=", typeof opts.channel, "with channel id", opts.channel?.ch); console.log(
"[RabbitMQ] setupListener: close for",
this.user_id,
"=",
typeof opts.channel,
"with channel id",
opts.channel?.ch,
);
if (opts.channel) opts.channel.close(); if (opts.channel) opts.channel.close();
else { else {
Object.values(this.events).forEach((x) => x?.()); Object.values(this.events).forEach((x) => x?.());

View File

@ -132,18 +132,22 @@ export class Permissions extends BitField {
init?: bigint, init?: bigint,
) { ) {
// TODO: do not deny any permissions if admin // TODO: do not deny any permissions if admin
return overwrites.reduce((permission, overwrite) => { return overwrites.reduce(
(permission, overwrite) => {
// apply disallowed permission // apply disallowed permission
// * permission: current calculated permission (e.g. 010) // * permission: current calculated permission (e.g. 010)
// * deny contains all denied permissions (e.g. 011) // * deny contains all denied permissions (e.g. 011)
// * allow contains all explicitly allowed permisions (e.g. 100) // * allow contains all explicitly allowed permisions (e.g. 100)
return ( return (
(permission & ~BigInt(overwrite.deny)) | BigInt(overwrite.allow) (permission & ~BigInt(overwrite.deny)) |
BigInt(overwrite.allow)
); );
// ~ operator inverts deny (e.g. 011 -> 100) // ~ operator inverts deny (e.g. 011 -> 100)
// & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000) // & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000)
// | operators adds both together (e.g. 000 + 100 -> 100) // | operators adds both together (e.g. 000 + 100 -> 100)
}, init || BigInt(0)); },
init || BigInt(0),
);
} }
static rolePermission(roles: Role[]) { static rolePermission(roles: Role[]) {