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

@ -9,39 +9,46 @@ import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); 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: [ {
"**/node_modules", ignores: [
"**/dist", "**/node_modules",
"**/README.md", "**/dist",
"**/COPYING", "**/README.md",
"src/webrtc", "**/COPYING",
"**/scripts/", "src/webrtc",
"**/assets", "**/scripts/",
], "**/assets",
}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), { ],
plugins: { },
"@typescript-eslint": typescriptEslint, ...compat.extends(
}, "eslint:recommended",
"plugin:@typescript-eslint/recommended",
),
{
plugins: {
"@typescript-eslint": typescriptEslint,
},
languageOptions: { languageOptions: {
globals: { globals: {
...globals.node, ...globals.node,
}, },
parser: tsParser, parser: tsParser,
}, },
rules: { rules: {
"no-mixed-spaces-and-tabs": "off", "no-mixed-spaces-and-tabs": "off",
"@typescript-eslint/no-inferrable-types": "off", // Required by typeorm "@typescript-eslint/no-inferrable-types": "off", // Required by typeorm
"@typescript-eslint/no-var-requires": "off", // Sometimes requred by typeorm to resolve circular deps "@typescript-eslint/no-var-requires": "off", // Sometimes requred by typeorm to resolve circular deps
"@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,61 +1,61 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1731533236, "lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1731676054, "lastModified": 1731676054,
"narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "nixos",
"ref": "nixos-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
}, },
"systems": { "systems": {
"locked": { "locked": {
"lastModified": 1681028828, "lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems", "owner": "nix-systems",
"repo": "default", "repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-systems", "owner": "nix-systems",
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
} }
}, },
"root": "root", "root": "root",
"version": 7 "version": 7
} }

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

@ -72,7 +72,7 @@ router.get(
`${Config.get().general.frontPage}/register?token=${ `${Config.get().general.frontPage}/register?token=${
x.token x.token
}`, }`,
) )
: tokens.map((x) => x.token); : tokens.map((x) => x.token);
if (req.query.plain) return res.send(ret.join("\n")); if (req.query.plain) return res.send(ret.join("\n"));

View File

@ -417,7 +417,7 @@ router.post(
? Member.update( ? Member.update(
{ id: req.user_id, guild_id: message.guild_id }, { id: req.user_id, guild_id: message.guild_id },
{ last_message_id: message.id }, { last_message_id: message.id },
) )
: null, : null,
channel.save(), channel.save(),
]); ]);

View File

@ -54,7 +54,7 @@ router.post(
...member, ...member,
roles: member?.roles?.map((x) => x.id), roles: member?.roles?.map((x) => x.id),
}, },
} }
: null), : null),
channel_id, channel_id,
timestamp, timestamp,

View File

@ -42,24 +42,24 @@ router.get(
guilds = showAllGuilds guilds = showAllGuilds
? await Guild.find({ ? await Guild.find({
take: Math.abs(Number(limit || configLimit)), take: Math.abs(Number(limit || configLimit)),
}) })
: await Guild.find({ : await Guild.find({
where: { features: Like(`%DISCOVERABLE%`) }, where: { features: Like(`%DISCOVERABLE%`) },
take: Math.abs(Number(limit || configLimit)), take: Math.abs(Number(limit || configLimit)),
}); });
} else { } else {
guilds = showAllGuilds guilds = showAllGuilds
? await Guild.find({ ? await Guild.find({
where: { primary_category_id: categories.toString() }, where: { primary_category_id: categories.toString() },
take: Math.abs(Number(limit || configLimit)), take: Math.abs(Number(limit || configLimit)),
}) })
: await Guild.find({ : await Guild.find({
where: { where: {
primary_category_id: categories.toString(), primary_category_id: categories.toString(),
features: Like("%DISCOVERABLE%"), features: Like("%DISCOVERABLE%"),
}, },
take: Math.abs(Number(limit || configLimit)), take: Math.abs(Number(limit || configLimit)),
}); });
} }
const total = guilds ? guilds.length : undefined; const total = guilds ? guilds.length : undefined;

View File

@ -48,7 +48,7 @@ router.get(
: await Guild.find({ : await Guild.find({
where: { features: Like("%DISCOVERABLE%") }, where: { features: Like("%DISCOVERABLE%") },
take: Math.abs(Number(limit || 24)), take: Math.abs(Number(limit || 24)),
}); });
res.send({ res.send({
recommended_guilds: guilds, recommended_guilds: guilds,
load_id: `server_recs/${genLoadId(32)}`, load_id: `server_recs/${genLoadId(32)}`,

View File

@ -118,7 +118,7 @@ router.get(
guild: { guild: {
roles: x?.roles || [], roles: x?.roles || [],
}, },
}); });
return { return {
id: x.guild.id, id: x.guild.id,

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

@ -323,7 +323,7 @@ export class Channel extends BaseClass {
event: "CHANNEL_CREATE", event: "CHANNEL_CREATE",
data: channel, data: channel,
guild_id: channel.guild_id, guild_id: channel.guild_id,
} as ChannelCreateEvent) } as ChannelCreateEvent)
: Promise.resolve(), : Promise.resolve(),
Guild.insertChannelInOrder(guild.id, ret.id, position, guild), Guild.insertChannelInOrder(guild.id, ret.id, position, guild),
]); ]);

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(
// apply disallowed permission (permission, overwrite) => {
// * permission: current calculated permission (e.g. 010) // apply disallowed permission
// * deny contains all denied permissions (e.g. 011) // * permission: current calculated permission (e.g. 010)
// * allow contains all explicitly allowed permisions (e.g. 100) // * deny contains all denied permissions (e.g. 011)
return ( // * allow contains all explicitly allowed permisions (e.g. 100)
(permission & ~BigInt(overwrite.deny)) | BigInt(overwrite.allow) return (
); (permission & ~BigInt(overwrite.deny)) |
// ~ operator inverts deny (e.g. 011 -> 100) BigInt(overwrite.allow)
// & operator only allows 1 for both ~deny and permission (e.g. 010 & 100 -> 000) );
// | operators adds both together (e.g. 000 + 100 -> 100) // ~ operator inverts deny (e.g. 011 -> 100)
}, init || BigInt(0)); // & 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),
);
} }
static rolePermission(roles: Role[]) { static rolePermission(roles: Role[]) {