fix(APIRequest): group reaction requests into one route per channel (#4017)

* fix(APIRequest): group all reactions into the same route per channel

* refactor(APIRequest): make route a const
This commit is contained in:
SpaceEEC
2020-04-05 18:59:16 +02:00
committed by GitHub
parent de0cacdf32
commit 747d76de10

View File

@@ -15,13 +15,17 @@ class APIRequest {
} }
getRoute(url) { getRoute(url) {
let route = url.split('?')[0]; const route = url.split('?')[0].split('/');
if (route.includes('/channels/') || route.includes('/guilds/')) { const routeBucket = [];
const startInd = route.includes('/channels/') ? route.indexOf('/channels/') : route.indexOf('/guilds/'); for (let i = 0; i < route.length; i++) {
const majorID = route.substring(startInd).split('/')[2]; // Reactions routes and sub-routes all share the same bucket
route = route.replace(/(\d{8,})/g, ':id').replace(':id', majorID); if (route[i - 1] === 'reactions') break;
// Literal IDs should only be taken account if they are the Major ID (the Channel/Guild ID)
if (/\d{16,19}/g.test(route[i]) && !/channels|guilds/.test(route[i - 1])) routeBucket.push(':id');
// All other parts of the route should be considered as part of the bucket identifier
else routeBucket.push(route[i]);
} }
return route; return routeBucket.join('/');
} }
getAuth() { getAuth() {