diff --git a/.DS_Store b/.DS_Store index 348b5e54..7daf908b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 67045665..89c4f375 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,5 @@ dist # TernJS port file .tern-port + +.DS_STORE \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2b13235c..fb92cdea 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index 0e3eca53..6b70725e 100644 --- a/package.json +++ b/package.json @@ -1,31 +1,33 @@ { - "name": "discord-server-opensource", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Trenite/discord-server-opensource.git" - }, - "keywords": [], - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/Trenite/discord-server-opensource/issues" - }, - "homepage": "https://github.com/Trenite/discord-server-opensource#readme", - "devDependencies": { - "@types/node": "^14.14.10", - "typescript": "^4.1.2" - }, - "dependencies": { - "@types/express": "^4.17.9", - "@types/node-fetch": "^2.5.7", - "express": "^4.17.1", - "express-cache-middleware": "^1.0.1", - "node-fetch": "^2.6.1" - } + "name": "discord-server-opensource", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Trenite/discord-server-opensource.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/Trenite/discord-server-opensource/issues" + }, + "homepage": "https://github.com/Trenite/discord-server-opensource#readme", + "dependencies": { + "@types/express": "^4.17.9", + "@types/node-fetch": "^2.5.7", + "express": "^4.17.1", + "express-cache-middleware": "^1.0.1", + "lambert-db": "^1.0.3", + "missing-native-js-functions": "^1.0.8", + "node-fetch": "^2.6.1" + }, + "devDependencies": { + "@types/node": "^14.14.10", + "typescript": "^4.1.2" + } } diff --git a/src/Server.ts b/src/Server.ts index ca03e0d2..92c73a35 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -1,7 +1,6 @@ import express, { Application, Router } from "express"; import { traverseDirectory } from "./Utils"; import { Server as HTTPServer } from "http"; -import fetch from "node-fetch"; import fs from "fs/promises"; export type ServerOptions = { @@ -56,13 +55,13 @@ export class Server { var router = require(file); if (router.router) router = router.router; if (router.default) router = router.default; - if (!router || router.prototype.constructor.name !== "router") + if (!router || router?.prototype?.constructor?.name !== "router") throw `File doesn't export any default router`; this.app.use(path, router); console.log(`[Server] Route ${path} registerd`); return router; } catch (error) { - console.error(new Error(`[Server] Failed to register route ${file}: ${error}`)); + console.error(new Error(`[Server] Failed to register route ${path}: ${error}`)); } } diff --git a/src/Utils.ts b/src/Utils.ts index 09d8e8c6..291372c1 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,14 +1,5 @@ import fs from "fs/promises"; - -declare global { - interface Array { - flat(): T; - } -} - -Array.prototype.flat = function () { - return this.reduce((acc, val) => (Array.isArray(val) ? acc.concat(val.flat()) : acc.concat(val)), []); -}; +import "missing-native-js-functions"; export interface traverseDirectoryOptions { dirname: string; diff --git a/src/exampleFetch.ts b/src/exampleFetch.ts new file mode 100644 index 00000000..9c433e4b --- /dev/null +++ b/src/exampleFetch.ts @@ -0,0 +1,52 @@ +import fetch from "node-fetch"; + +fetch("https://discord.com/api/v8/auth/login", { + headers: { + authorization: "undefined", + "content-type": "application/json", + "x-fingerprint": "782364413927751692.ex9RorNkBsGynrJCe5Brxtc3Ytc", + "x-super-properties": + "eyJvcyI6Ik1hYyBPUyBYIiwiYnJvd3NlciI6IkNocm9tZSIsImRldmljZSI6IiIsImJyb3dzZXJfdXNlcl9hZ2VudCI6Ik1vemlsbGEvNS4wIChNYWNpbnRvc2g7IEludGVsIE1hYyBPUyBYIDEwXzE1XzcpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS84Ny4wLjQyODAuNjcgU2FmYXJpLzUzNy4zNiIsImJyb3dzZXJfdmVyc2lvbiI6Ijg3LjAuNDI4MC42NyIsIm9zX3ZlcnNpb24iOiIxMC4xNS43IiwicmVmZXJyZXIiOiIiLCJyZWZlcnJpbmdfZG9tYWluIjoiIiwicmVmZXJyZXJfY3VycmVudCI6IiIsInJlZmVycmluZ19kb21haW5fY3VycmVudCI6IiIsInJlbGVhc2VfY2hhbm5lbCI6InN0YWJsZSIsImNsaWVudF9idWlsZF9udW1iZXIiOjcyMzc2LCJjbGllbnRfZXZlbnRfc291cmNlIjpudWxsfQ==", + }, + body: JSON.stringify({ + login: "email@gmail.com", + password: "cleartextpassword", + undelete: false, + captcha_key: null, + login_source: null, + gift_code_sku_id: null, + }), + method: "POST", +}); +/** + * @returns {"token": null, "mfa": true, "sms": true, "ticket": "WzMxMTEyOTM1NzM2MjEzNTA0MSwibG9naW4iXQ.X8LHqg.vTwtZBaLu5W_XMMSvKad1OAaEoA"} + */ + +fetch("https://discord.com/api/v8/auth/mfa/totp", { + headers: { + authorization: "undefined", + "content-type": "application/json", + }, + body: JSON.stringify({ + code: "722608", + ticket: "WzMxMTEyOTM1NzM2MjEzNTA0MSwibG9naW4iXQ.X8LHqg.vTwtZBaLu5W_XMMSvKad1OAaEoA", + login_source: null, + gift_code_sku_id: null, + }), + method: "POST", +}); +/** + * @returns {"token": "mfa.-Rg2AwyP06YdTPmIDt0sqA92T8fBVITLTcXjP7zO_Uhgkg1FA0WERGjJXJyN_dyVDeBnxIWr0w3XiXW8YxVw", "user_settings": {"locale": "en-GB", "theme": "dark"}} + */ + +// token: mfa.-Rg2AwyP06YdTPmIDt0sqA92T8fBVITLTcXjP7zO_Uhgkg1FA0WERGjJXJyN_dyVDeBnxIWr0w3XiXW8YxVw + +fetch("https://discord.com/api/v8/gateway", { + headers: { + authorization: "token", + }, + method: "GET", +}); +/** + * @returns {"url": "wss://gateway.discord.gg"} + */ diff --git a/src/routes/api/v8/auth/login.ts b/src/routes/api/v8/auth/login.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/routes/api/v8/auth/register.ts b/src/routes/api/v8/auth/register.ts new file mode 100644 index 00000000..e69de29b