1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-21 18:02:33 +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({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
allConfig: js.configs.all,
});
export default [{
export default [
{
ignores: [
"**/node_modules",
"**/dist",
@ -24,7 +25,12 @@ export default [{
"**/scripts/",
"**/assets",
],
}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), {
},
...compat.extends(
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
),
{
plugins: {
"@typescript-eslint": typescriptEslint,
},
@ -44,4 +50,5 @@ export default [{
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-unused-vars": "off",
},
}];
},
];

View File

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

View File

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

View File

@ -89,11 +89,13 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
}
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",
name: `GATEWAY ${OPCODES[data.op]}`,
attributes: { // this needs to be reworked :)
attributes: {
// this needs to be reworked :)
...data.d,
token: data?.d?.token ? "[Redacted]" : undefined,
},

View File

@ -82,7 +82,7 @@ export async function setupListener(this: WebSocket) {
const opts: {
acknowledge: boolean;
channel?: AMQChannel & { queues?: unknown, ch?: number };
channel?: AMQChannel & { queues?: unknown; ch?: number };
} = {
acknowledge: true,
};
@ -91,10 +91,20 @@ export async function setupListener(this: WebSocket) {
console.log("[RabbitMQ] setupListener: open for ", this.user_id);
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.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);
@ -132,7 +142,14 @@ export async function setupListener(this: WebSocket) {
});
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();
else {
Object.values(this.events).forEach((x) => x?.());

View File

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