Skip to content

Commit

Permalink
Add additional endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake authored and MaddyUnderStars committed Jul 7, 2024
1 parent a408002 commit a60e7ac
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
31 changes: 31 additions & 0 deletions missing.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,36 @@
"/webhooks/:id",
"/webhooks/:id/:id",
"webapp:///billing/premium/subscribe/login-handoff?handoff_key=:id&handoff_token=:id&destination=:id"
],
"additional": [
"/-/healthz",
"/-/readyz",
"/applications/{id}/bot",
"/applications/{id}/bot/reset",
"/applications/{id}/delete",
"/auth/generate-registration-tokens",
"/auth/mfa/totp",
"/auth/mfa/webauthn",
"/channels/{channel_id}/messages/bulk-delete",
"/channels/{channel_id}/messages/{message_id}/ack",
"/channels/{channel_id}/messages/{message_id}/crosspost",
"/channels/{channel_id}/messages/{message_id}/reactions",
"/channels/{channel_id}/purge",
"/connections/{connection_name}/{connection_id}/refresh",
"/guilds/{guild_id}/members/{member_id}/nick",
"/guilds/{guild_id}/roles/{role_id}/member-ids",
"/oauth2/applications/@me",
"/ping",
"/policies/instance",
"/policies/instance/domains",
"/policies/instance/limits",
"/policies/stats",
"/scheduled-maintenances/upcoming_json/scheduled-maintenances/upcoming.json",
"/store/published-listings/applications/{id}/subscription-plans",
"/track",
"/updates",
"/users/@me/connections/{connection_name}/{connection_id}/access-token",
"/users/{id}/delete",
"/voice/regions"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/index.js",
"scripts": {
"build": "tsc -b",
"watch": "tsc -b -w",
"start": "node dist/index.js"
},
"author": "",
Expand Down
28 changes: 24 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import fetch from "node-fetch";

const JAVASCRIPT_ENVIRONMENT = fs.readFileSync("./src/template.js").toString();

const ignoredAdditional = new Set([
// Not used in the client
"/gateway",
"/gateway/bot",
"/guilds/{guild_id}/widget.json",
"/guilds/{guild_id}/widget.png",
]);

const getClientSource = async () => {
const index = await fetch("https://canary.discord.com/app").then(x => x.text());
const script = [...index.matchAll(/web.[A-Fa-f0-9]{20}.js/g)].reverse()[0];
Expand Down Expand Up @@ -73,30 +81,41 @@ const getSbOpenAPI = async () => {
"https://raw.githubusercontent.com/spacebarchat/server/master/assets/openapi.json"
)
.then((x) => x.json())
.then((x: any) => Object.keys(x.paths));
.then((x: any) => Object.keys(x.paths).map((y) => y.replace(/\/$/, "")));
};

const compare = (discord: string[], spacebar: string[]) => {
const missing = [];
const additional = [];

for (const route of discord) {
const regex = route.replaceAll("/", "\\/").replaceAll(":id", "{.*}");

const found = spacebar.find((x) => x.match(regex));
const found = spacebar.some((x) => x.match(regex));

if (!found) {
missing.push(route);
}
}

return missing;
for (const route of spacebar) {
const regex = route.replaceAll("/", "\\/").replace(/{.*}/g, ":id");

const found = discord.some((x) => x.match(regex));

if (!found && !ignoredAdditional.has(route)) {
additional.push(route);
}
}

return [missing, additional];
};

(async () => {
const source = await getClientSource();
const dcRoutes = findClientRoutes(source);
const sbRoutes = await getSbOpenAPI();
const missing = compare(dcRoutes, sbRoutes);
const [missing, additional] = compare(dcRoutes, sbRoutes);

console.log(`Spacebar is missing ${missing.length}`);
console.log(`Spacebar implements ${sbRoutes.length}`);
Expand All @@ -107,5 +126,6 @@ const compare = (discord: string[], spacebar: string[]) => {
spacebar: sbRoutes.length,
discord: dcRoutes.length,
routes: missing.sort(),
additional: additional.sort(),
}, null, 2));
})();

0 comments on commit a60e7ac

Please sign in to comment.