summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe Arcane Brony <myrainbowdash949@gmail.com>2021-10-10 17:55:48 +0200
committerThe Arcane Brony <myrainbowdash949@gmail.com>2021-10-10 17:55:48 +0200
commit79aee5145b6b289a001caae516477c8ab641bb8f (patch)
tree9fa55053ec5da0483e1a9de0d97089aef4559068
parent:bug: fix null user in identify (diff)
downloadserver-79aee5145b6b289a001caae516477c8ab641bb8f.tar.xz
Fix duplicate key
-rw-r--r--api/assets/schemas.json2
-rw-r--r--api/src/routes/guilds/#guild_id/vanity-url.ts9
-rw-r--r--api/src/routes/invites/index.ts1
-rw-r--r--bundle/scripts/build.js27
-rw-r--r--util/src/entities/Guild.ts8
-rw-r--r--util/src/entities/Invite.ts3
6 files changed, 28 insertions, 22 deletions
diff --git a/api/assets/schemas.json b/api/assets/schemas.json
index 4f1ab9a8..a12925e0 100644
--- a/api/assets/schemas.json
+++ b/api/assets/schemas.json
@@ -4744,7 +4744,7 @@
                 "type": "string"
             },
             "permissions": {
-                "type": "bigint"
+                "type": "array"
             },
             "color": {
                 "type": "integer"
diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/api/src/routes/guilds/#guild_id/vanity-url.ts
index 7f2cea9e..061b317c 100644
--- a/api/src/routes/guilds/#guild_id/vanity-url.ts
+++ b/api/src/routes/guilds/#guild_id/vanity-url.ts
@@ -10,10 +10,10 @@ const InviteRegex = /\W/g;
 router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
 
-	const guild = await Guild.findOneOrFail({ where: { id: guild_id }, relations: ["vanity_url"] });
-	if (!guild.vanity_url) return res.json({ code: null });
+	const invite = await Invite.findOne({ where: {guild_id: guild_id, vanity_url: true} });
+	if (!invite) return res.json({ code: null });
 
-	return res.json({ code: guild.vanity_url_code, uses: guild.vanity_url.uses });
+	return res.json({ code: invite.code, uses: invite.uses });
 });
 
 export interface VanityUrlSchema {
@@ -33,12 +33,9 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" })
 	const invite = await Invite.findOne({ code });
 	if (invite) throw new HTTPError("Invite already exists");
 
-	const guild = await Guild.findOneOrFail({ id: guild_id });
 	const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
 
 	Promise.all([
-		Guild.update({ id: guild_id }, { vanity_url_code: code }),
-		Invite.delete({ code: guild.vanity_url_code }),
 		new Invite({
 			code: code,
 			uses: 0,
diff --git a/api/src/routes/invites/index.ts b/api/src/routes/invites/index.ts
index 0fcf7c86..185311bc 100644
--- a/api/src/routes/invites/index.ts
+++ b/api/src/routes/invites/index.ts
@@ -33,7 +33,6 @@ router.delete("/:code", route({}), async (req: Request, res: Response) => {
 
 	await Promise.all([
 		Invite.delete({ code }),
-		Guild.update({ vanity_url_code: code }, { vanity_url_code: undefined }),
 		emitEvent({
 			event: "INVITE_DELETE",
 			guild_id: guild_id,
diff --git a/bundle/scripts/build.js b/bundle/scripts/build.js
index 69111c88..a9798eff 100644
--- a/bundle/scripts/build.js
+++ b/bundle/scripts/build.js
@@ -1,6 +1,22 @@
 const { execSync } = require("child_process");
 const path = require("path");
 const fse = require("fs-extra");
+const { getSystemErrorMap } = require("util");
+const { argv } = require("process");
+
+const dirs = ["api", "util", "cdn", "gateway", "bundle"];
+
+const verbose = argv.includes("verbose") || argv.includes("v");
+
+if(argv.includes("clean")){
+	dirs.forEach(a=>{
+		var d = "../"+a+"/dist";
+		if(fse.existsSync(d)) {
+			fse.rmSync(d,{recursive: true});
+			if(verbose) console.log(`Deleted ${d}!`);
+		}
+	});
+}
 
 fse.copySync(path.join(__dirname, "..", "..", "api", "assets"), path.join(__dirname, "..", "dist", "api", "assets"));
 fse.copySync(
@@ -8,13 +24,12 @@ fse.copySync(
 	path.join(__dirname, "..", "dist", "api", "client_test")
 );
 fse.copySync(path.join(__dirname, "..", "..", "api", "locales"), path.join(__dirname, "..", "dist", "api", "locales"));
-fse.copySync(path.join(__dirname, "..", "..", "api", "src"), path.join(__dirname, "..", "dist", "api", "src"));
-fse.copySync(path.join(__dirname, "..", "..", "util", "src"), path.join(__dirname, "..", "dist", "util", "src"));
-fse.copySync(path.join(__dirname, "..", "..", "cdn", "src"), path.join(__dirname, "..", "dist", "cdn", "src"));
-fse.copySync(path.join(__dirname, "..", "..", "gateway", "src"), path.join(__dirname, "..", "dist", "gateway", "src"));
-fse.copySync(path.join(__dirname, "..", "..", "bundle", "src"), path.join(__dirname, "..", "dist", "bundle", "src"));
+dirs.forEach(a=>{
+	fse.copySync("../"+a+"/src", "dist/"+a+"/src");
+	if(verbose) console.log(`Copied ${"../"+a+"/dist"} -> ${"dist/"+a+"/src"}!`);
+});
 
-console.log("Copying   src files done");
+console.log("Copying src files done");
 console.log("Compiling src files ...");
 
 console.log(
diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts
index 35595191..157f0921 100644
--- a/util/src/entities/Guild.ts
+++ b/util/src/entities/Guild.ts
@@ -258,14 +258,6 @@ export class Guild extends BaseClass {
 	unavailable?: boolean;
 
 	@Column({ nullable: true })
-	@RelationId((guild: Guild) => guild.vanity_url)
-	vanity_url_code?: string;
-
-	@JoinColumn({ name: "vanity_url_code" })
-	@ManyToOne(() => Invite)
-	vanity_url?: Invite;
-
-	@Column({ nullable: true })
 	verification_level?: number;
 
 	@Column({ type: "simple-json" })
diff --git a/util/src/entities/Invite.ts b/util/src/entities/Invite.ts
index 82556fab..d6b8f2f8 100644
--- a/util/src/entities/Invite.ts
+++ b/util/src/entities/Invite.ts
@@ -71,6 +71,9 @@ export class Invite extends BaseClass {
 	@Column({ nullable: true })
 	target_user_type?: number;
 
+	@Column({ nullable: true})
+	vanity_url?: boolean;
+
 	static async joinGuild(user_id: string, code: string) {
 		const invite = await Invite.findOneOrFail({ code });
 		if (invite.uses++ >= invite.max_uses && invite.max_uses !== 0) await Invite.delete({ code });