From ce4e7512921c2935a3adec9d9b94848c0fac5ba1 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:03:04 +0200 Subject: :art: clean up dependencies --- bundle/package.json | 85 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 26 deletions(-) (limited to 'bundle/package.json') diff --git a/bundle/package.json b/bundle/package.json index a7f5358b..05cefaab 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -4,11 +4,10 @@ "description": "", "main": "src/start.js", "scripts": { - "setup": "cd ../util && npm --production=false i && cd ../api && npm --production=false i && cd ../cdn && npm --production=false i && cd ../gateway && npm --production=false i && cd ../bundle/ && npm --production=false i && npm run build", + "setup": "node scripts/install.js && npm install && ts-patch install -s && patch-package --patch-dir ../api/patches/ && npm run build", "build": "node scripts/build.js", - "build:bundle": "npx tsc -b .", - "start": "node scripts/build.js && node -r tsconfig-paths/register dist/start.js", - "start:bundle": "node -r tsconfig-paths/register dist/start.js", + "start": "node scripts/build.js && node dist/bundle/src/start.js", + "start:bundle": "node dist/bundle/src/start.js", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -23,42 +22,76 @@ }, "homepage": "https://fosscord.com", "devDependencies": { - "@swc/cli": "^0.1.51", - "@swc/core": "^1.2.93", + "@babel/core": "^7.15.5", + "@babel/preset-env": "^7.15.6", + "@babel/preset-typescript": "^7.15.0", "@types/amqplib": "^0.8.1", - "@types/async-exit-hook": "^2.0.0", "@types/bcrypt": "^5.0.0", - "@types/express": "^4.17.9", + "@types/body-parser": "^1.19.0", + "@types/btoa": "^1.2.3", + "@types/dotenv": "^8.2.0", + "@types/express": "^4.17.12", + "@types/fs-extra": "^9.0.12", "@types/i18next-node-fs-backend": "^2.1.0", + "@types/jest": "^27.0.1", + "@types/jest-expect-message": "^1.0.3", "@types/jsonwebtoken": "^8.5.0", - "@types/mongodb": "^3.6.9", - "@types/mongoose-autopopulate": "^0.10.1", - "@types/mongoose-lean-virtuals": "^0.5.1", - "@types/multer": "^1.4.5", - "@types/node": "^14.17.20", - "@types/node-fetch": "^2.5.7", + "@types/multer": "^1.4.7", + "@types/node": "^14.17.9", + "@types/node-fetch": "^2.5.12", "@types/node-os-utils": "^1.2.0", - "@types/uuid": "^8.3.0", + "@types/supertest": "^2.0.11", "@types/ws": "^7.4.0", "@zerollup/ts-transform-paths": "^1.7.18", - "esbuild": "^0.13.4", - "esbuild-plugin-tsc": "^0.3.0", - "ts-node": "^10.2.1", + "jest": "^27.0.6", + "jest-expect-message": "^1.0.2", + "jest-runtime": "^27.2.1", + "ts-node": "^9.1.1", + "ts-node-dev": "^1.1.6", "ts-patch": "^1.4.4", - "tsconfig-paths": "^3.11.0", - "typescript": "^4.4.3" + "typescript": "^4.2.3", + "typescript-json-schema": "0.50.1", + "@types/morgan": "^1.9.3" }, "dependencies": { - "@fosscord/api": "file:../api", - "@fosscord/cdn": "file:../cdn", - "@fosscord/gateway": "file:../gateway", - "@fosscord/util": "file:../util", + "ajv": "8.6.2", + "ajv-formats": "^2.1.1", + "amqplib": "^0.8.0", + "assert": "^1.5.0", "async-exit-hook": "^2.0.1", - "dotenv": "^10.0.0", + "bcrypt": "^5.0.1", + "body-parser": "^1.19.0", + "btoa": "^1.2.1", + "dotenv": "^8.2.0", + "exif-be-gone": "^1.2.0", "express": "^4.17.1", + "express-async-errors": "^3.1.1", + "file-type": "^16.5.0", + "form-data": "^3.0.0", + "fs-extra": "^10.0.0", + "i18next": "^19.9.2", + "i18next-http-middleware": "^3.1.3", + "i18next-node-fs-backend": "^2.1.3", + "image-size": "^1.0.0", + "jest": "^27.0.6", + "jsonwebtoken": "^8.5.1", + "lambert-db": "^1.2.3", + "lambert-server": "^1.2.11", "missing-native-js-functions": "^1.2.17", + "morgan": "^1.10.0", + "multer": "^1.4.2", "nanocolors": "^0.2.12", + "node-fetch": "^2.6.1", "node-os-utils": "^1.3.5", - "reflect-metadata": "^0.1.13" + "patch-package": "^6.4.7", + "pg": "^8.7.1", + "reflect-metadata": "^0.1.13", + "sqlite3": "^5.0.2", + "supertest": "^6.1.6", + "typeorm": "^0.2.37", + "typescript": "^4.1.2", + "typescript-json-schema": "^0.50.1", + "ws": "^7.4.2", + "cheerio": "^1.0.0-rc.10" } } -- cgit 1.5.1 From 57c9813f2fca9b8f4e02f09d71515bc7f59b4010 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:08:55 +0200 Subject: :bug: convert bigint literal to object --- api/src/routes/channels/#channel_id/permissions.ts | 4 ++-- api/src/routes/guilds/#guild_id/roles.ts | 9 +++++++-- api/src/routes/guilds/templates/index.ts | 2 +- bundle/package.json | 2 +- gateway/src/opcodes/Identify.ts | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) (limited to 'bundle/package.json') diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/api/src/routes/channels/#channel_id/permissions.ts index 6ebf721a..2eded853 100644 --- a/api/src/routes/channels/#channel_id/permissions.ts +++ b/api/src/routes/channels/#channel_id/permissions.ts @@ -44,8 +44,8 @@ router.put( }; channel.permission_overwrites!.push(overwrite); } - overwrite.allow = String(req.permission!.bitfield & (BigInt(body.allow) || 0n)); - overwrite.deny = String(req.permission!.bitfield & (BigInt(body.deny) || 0n)); + overwrite.allow = String(req.permission!.bitfield & (BigInt(body.allow) || BigInt("0"))); + overwrite.deny = String(req.permission!.bitfield & (BigInt(body.deny) || BigInt("0"))); await Promise.all([ channel.save(), diff --git a/api/src/routes/guilds/#guild_id/roles.ts b/api/src/routes/guilds/#guild_id/roles.ts index d1d60906..0a57c6a2 100644 --- a/api/src/routes/guilds/#guild_id/roles.ts +++ b/api/src/routes/guilds/#guild_id/roles.ts @@ -57,7 +57,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }) ...body, guild_id: guild_id, managed: false, - permissions: String(req.permission!.bitfield & (body.permissions || 0n)), + permissions: String(req.permission!.bitfield & (body.permissions || BigInt("0"))), tags: undefined }); @@ -105,7 +105,12 @@ router.patch("/:role_id", route({ body: "RoleModifySchema", permission: "MANAGE_ const { role_id, guild_id } = req.params; const body = req.body as RoleModifySchema; - const role = new Role({ ...body, id: role_id, guild_id, permissions: String(req.permission!.bitfield & (body.permissions || 0n)) }); + const role = new Role({ + ...body, + id: role_id, + guild_id, + permissions: String(req.permission!.bitfield & (body.permissions || BigInt("0"))) + }); await Promise.all([ role.save(), diff --git a/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts index b5e243e9..86316d23 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/api/src/routes/guilds/templates/index.ts @@ -47,7 +47,7 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: managed: true, mentionable: true, name: "@everyone", - permissions: 2251804225n, + permissions: BigInt("2251804225"), position: 0, tags: null }).save() diff --git a/bundle/package.json b/bundle/package.json index 05cefaab..3bed5b07 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -94,4 +94,4 @@ "ws": "^7.4.2", "cheerio": "^1.0.0-rc.10" } -} +} \ No newline at end of file diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index b81c7bf4..5d5b72d1 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -41,7 +41,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { return this.close(CLOSECODES.Authentication_failed); } this.user_id = decoded.id; - if (!identify.intents) identify.intents = 0b11111111111111n; + if (!identify.intents) identify.intents = BigInt("0b11111111111111"); this.intents = new Intents(identify.intents); if (identify.shard) { this.shard_id = identify.shard[0]; -- cgit 1.5.1 From 347943ffd4897f11bb2ec90a704905d6ad1d7125 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:21:24 +0200 Subject: :sparkles: migrate script --- bundle/package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bundle/package.json') diff --git a/bundle/package.json b/bundle/package.json index 3bed5b07..3d41f7c2 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -8,7 +8,8 @@ "build": "node scripts/build.js", "start": "node scripts/build.js && node dist/bundle/src/start.js", "start:bundle": "node dist/bundle/src/start.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "migrate": "node node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" }, "repository": { "type": "git", @@ -94,4 +95,4 @@ "ws": "^7.4.2", "cheerio": "^1.0.0-rc.10" } -} \ No newline at end of file +} -- cgit 1.5.1 From 82205520ed302aa5a91fc6a770e7ecf2b6ccc043 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:31:13 +0200 Subject: :bug: fix Emoji missing in identify --- bundle/package.json | 2 +- gateway/src/opcodes/Identify.ts | 1 + util/src/entities/User.ts | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) (limited to 'bundle/package.json') diff --git a/bundle/package.json b/bundle/package.json index 3d41f7c2..eedbdd8c 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -9,7 +9,7 @@ "start": "node scripts/build.js && node dist/bundle/src/start.js", "start:bundle": "node dist/bundle/src/start.js", "test": "echo \"Error: no test specified\" && exit 1", - "migrate": "node node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" + "migrate": "node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" }, "repository": { "type": "git", diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index 16ea1904..5950105a 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -65,6 +65,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { "guild", "guild.channels", "guild.emojis", + "guild.emojis.user", "guild.roles", "guild.stickers", "user", diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 662ab031..04f1e9cb 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -248,7 +248,6 @@ export class User extends BaseClass { fingerprints: [], }); - console.log(user); await user.save(); if (Config.get().guild.autoJoin.enabled) { -- cgit 1.5.1 From fd152e8b6df18c9d98d02fed9e446de9690650cd Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 18:28:50 +0200 Subject: added vanity db migration --- bundle/package.json | 2 +- util/src/migrations/1633881705509-VanityInvite.ts | 17 +++++++++++++++++ util/src/migrations/migrate_db_engine.ts | 21 ++++++++++----------- 3 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 util/src/migrations/1633881705509-VanityInvite.ts (limited to 'bundle/package.json') diff --git a/bundle/package.json b/bundle/package.json index eedbdd8c..404c6758 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -9,7 +9,7 @@ "start": "node scripts/build.js && node dist/bundle/src/start.js", "start:bundle": "node dist/bundle/src/start.js", "test": "echo \"Error: no test specified\" && exit 1", - "migrate": "node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" + "migrate": "cd ../util/ && npm i && node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" }, "repository": { "type": "git", diff --git a/util/src/migrations/1633881705509-VanityInvite.ts b/util/src/migrations/1633881705509-VanityInvite.ts new file mode 100644 index 00000000..af9b98ae --- /dev/null +++ b/util/src/migrations/1633881705509-VanityInvite.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class VanityInvite1633881705509 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + try { + await queryRunner.query(`ALTER TABLE "emojis" DROP COLUMN vanity_url_code`); + await queryRunner.query(`ALTER TABLE "emojis" DROP CONSTRAINT FK_c2c1809d79eb120ea0cb8d342ad`); + } catch (error) {} + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "emojis" ADD vanity_url_code varchar`); + await queryRunner.query( + `ALTER TABLE "emojis" ADD CONSTRAINT FK_c2c1809d79eb120ea0cb8d342ad FOREIGN KEY ("vanity_url_code") REFERENCES "invites"("code") ON DELETE NO ACTION ON UPDATE NO ACTION` + ); + } +} diff --git a/util/src/migrations/migrate_db_engine.ts b/util/src/migrations/migrate_db_engine.ts index 33024a8d..cd578fb2 100644 --- a/util/src/migrations/migrate_db_engine.ts +++ b/util/src/migrations/migrate_db_engine.ts @@ -1,6 +1,6 @@ import { config } from "dotenv"; config(); -import { BaseEntity, createConnection, EntityTarget } from "typeorm"; +import { createConnection, EntityTarget } from "typeorm"; import { initDatabase } from "../util/Database"; import "missing-native-js-functions"; import { @@ -15,7 +15,6 @@ import { Invite, Member, Message, - RateLimit, ReadState, Recipient, Relationship, @@ -30,9 +29,9 @@ import { } from ".."; async function main() { - if (!process.env.FROM) throw new Error("FROM database env connection string not set"); + if (!process.env.TO) throw new Error("TO database env connection string not set"); - // manually arrange them because of foreign key + // manually arrange them because of foreign keys const entities = [ User, Guild, @@ -57,12 +56,12 @@ async function main() { Attachment, ]; - const newDB = await initDatabase(); + const oldDB = await initDatabase(); // @ts-ignore - const oldDB = await createConnection({ - type: process.env.FROM.split(":")[0]?.replace("+srv", ""), - url: process.env.FROM, + const newDB = await createConnection({ + type: process.env.TO.split(":")[0]?.replace("+srv", ""), + url: process.env.TO, entities, name: "old", }); @@ -73,13 +72,12 @@ async function main() { const entity = e as EntityTarget; const entries = await oldDB.manager.find(entity); //@ts-ignore - console.log("migrated " + entries.length + " " + entity.name); + console.log("migrating " + entries.length + " " + entity.name + " ..."); for (const entry of entries) { console.log(i++); if (entry instanceof User) { - console.log("instance of User"); if (entry.bio == null) entry.bio = ""; if (entry.rights == null) entry.rights = "0"; if (entry.disabled == null) entry.disabled = false; @@ -115,8 +113,9 @@ async function main() { // await newDB.manager.update(entity, { id: entry.id }, entry); // } } + // @ts-ignore - console.log("migrated all " + entity.name); + console.log("migrating " + entries.length + " " + entity.name + " ..."); } } catch (error) { console.error((error as any).message); -- cgit 1.5.1