diff --git a/package-lock.json b/package-lock.json index 799036f..4da2f8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "azerothcore-armory", - "version": "0.13.1", + "version": "0.13.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "azerothcore-armory", - "version": "0.13.1", + "version": "0.13.2", "license": "MIT", "dependencies": { "@supercharge/promise-pool": "^2.1.0", diff --git a/package.json b/package.json index 6535785..93160c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azerothcore-armory", - "version": "0.13.1", + "version": "0.13.2", "description": "", "scripts": { "build": "tsc -p tsconfig.json", diff --git a/src/armory/Armory.ts b/src/armory/Armory.ts index 81c8697..33334ea 100644 --- a/src/armory/Armory.ts +++ b/src/armory/Armory.ts @@ -151,7 +151,7 @@ export class Armory { const guildsController = new GuildController(this); app.get("/guild/:realm/:name", this.wrapRoute(guildsController.guild.bind(guildsController))); - app.get("/guild/:realm/:name/members", this.wrapRoute(guildsController.members.bind(guildsController))); + app.get("/guild/:realm/:guild/members", this.wrapRoute(guildsController.members.bind(guildsController))); app.use((err, req: express.Request, res: express.Response, next: express.NextFunction) => { // Error handler diff --git a/src/armory/controllers/GuildController.ts b/src/armory/controllers/GuildController.ts index 8eb22d2..df92261 100644 --- a/src/armory/controllers/GuildController.ts +++ b/src/armory/controllers/GuildController.ts @@ -44,7 +44,7 @@ export class GuildController { public async members(req: express.Request, res: express.Response, next: express.NextFunction): Promise { const realmName = req.params.realm; - const guildName = req.params.name; + const guildId = parseInt(req.params.guild); const realm = this.armory.getRealm(realmName); if (realm === undefined) { @@ -52,8 +52,7 @@ export class GuildController { return next(404); } - const guildId = await this.getGuildId(realm, guildName); - if (guildId === null) { + if (isNaN(guildId) || !(await this.guildExists(realm, guildId))) { // Could not find guild return next(404); } @@ -155,6 +154,20 @@ export class GuildController { return rows[0].guildid; } + private async guildExists(realm: IRealmConfig, id: number): Promise { + const db = this.armory.getCharactersDb(realm.name); + const [rows, fields] = await db.query({ + sql: ` + SELECT guildid + FROM guild WHERE guildid + `, + values: [id], + timeout: this.armory.config.dbQueryTimeout, + }); + + return (rows as RowDataPacket[]).length !== 0; + } + private async getGuildRanks(realm: IRealmConfig, id: number): Promise { const db = this.armory.getCharactersDb(realm.name); const [rows, fields] = await db.query({ diff --git a/static/guild.hbs b/static/guild.hbs index 3ec4bc0..2342c28 100644 --- a/static/guild.hbs +++ b/static/guild.hbs @@ -66,7 +66,7 @@ serverSide: true, searchDelay: 800, ajax: { - url: `{{websiteRoot}}/guild/{{realm}}/{{name}}/members`, + url: `{{websiteRoot}}/guild/{{realm}}/{{id}}/members`, }, columnDefs: [ {