rename req.userid -> req.user_id

This commit is contained in:
Flam3rboy 2021-03-08 18:40:37 +01:00
parent 56c9e43777
commit 6a1e0594dc
15 changed files with 309 additions and 78 deletions

224
package-lock.json generated
View File

@ -25,6 +25,7 @@
"missing-native-js-functions": "^1.2.4",
"mongodb": "^3.6.4",
"mongoose-long": "^0.3.2",
"multer": "^1.4.2",
"patch-package": "^6.2.2"
},
"devDependencies": {
@ -32,6 +33,7 @@
"@types/express": "^4.17.9",
"@types/i18next-node-fs-backend": "^2.1.0",
"@types/jsonwebtoken": "^8.5.0",
"@types/multer": "^1.4.5",
"@types/node": "^14.14.22",
"@types/node-fetch": "^2.5.7",
"0x": "^4.10.2",
@ -137,6 +139,15 @@
"@types/node": "*"
}
},
"node_modules/@types/multer": {
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.5.tgz",
"integrity": "sha512-9b/0a8JyrR0r2nQhL73JR86obWL7cogfX12augvlrvcpciCo/hkvEsgu80Z4S2g2DHGVXHr8pUIi1VhqFJ8Ufw==",
"dev": true,
"dependencies": {
"@types/express": "*"
}
},
"node_modules/@types/node": {
"version": "14.14.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.22.tgz",
@ -390,6 +401,11 @@
"integrity": "sha1-vgiVmQl7dKXJxKhKDNvNtivYeu8=",
"dev": true
},
"node_modules/append-field": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
"integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY="
},
"node_modules/aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
@ -925,8 +941,7 @@
"node_modules/buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
"dev": true
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"node_modules/buffer-xor": {
"version": "1.0.3",
@ -940,6 +955,39 @@
"integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=",
"dev": true
},
"node_modules/busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
"dependencies": {
"dicer": "0.2.5",
"readable-stream": "1.1.x"
},
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/busboy/node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"node_modules/busboy/node_modules/readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"node_modules/busboy/node_modules/string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"node_modules/bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@ -1199,7 +1247,6 @@
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
"dev": true,
"engines": [
"node >= 0.8"
],
@ -1676,6 +1723,39 @@
"node": ">=0.8.0"
}
},
"node_modules/dicer": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
"dependencies": {
"readable-stream": "1.1.x",
"streamsearch": "0.1.2"
},
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/dicer/node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"node_modules/dicer/node_modules/readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"node_modules/dicer/node_modules/string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"node_modules/diff": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
@ -3775,6 +3855,24 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"node_modules/multer": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/multer/-/multer-1.4.2.tgz",
"integrity": "sha512-xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg==",
"dependencies": {
"append-field": "^1.0.0",
"busboy": "^0.2.11",
"concat-stream": "^1.5.2",
"mkdirp": "^0.5.1",
"object-assign": "^4.1.1",
"on-finished": "^2.3.0",
"type-is": "^1.6.4",
"xtend": "^4.0.0"
},
"engines": {
"node": ">= 0.10.0"
}
},
"node_modules/mutexify": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/mutexify/-/mutexify-1.3.1.tgz",
@ -5548,6 +5646,14 @@
"readable-stream": "^2.0.2"
}
},
"node_modules/streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=",
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
@ -5881,8 +5987,7 @@
"node_modules/typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
"dev": true
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"node_modules/typescript": {
"version": "4.1.3",
@ -6153,7 +6258,6 @@
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"dev": true,
"engines": {
"node": ">=0.4"
}
@ -6280,6 +6384,15 @@
"@types/node": "*"
}
},
"@types/multer": {
"version": "1.4.5",
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.5.tgz",
"integrity": "sha512-9b/0a8JyrR0r2nQhL73JR86obWL7cogfX12augvlrvcpciCo/hkvEsgu80Z4S2g2DHGVXHr8pUIi1VhqFJ8Ufw==",
"dev": true,
"requires": {
"@types/express": "*"
}
},
"@types/node": {
"version": "14.14.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.22.tgz",
@ -6489,6 +6602,11 @@
"integrity": "sha1-vgiVmQl7dKXJxKhKDNvNtivYeu8=",
"dev": true
},
"append-field": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
"integrity": "sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY="
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
@ -6963,8 +7081,7 @@
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
"dev": true
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"buffer-xor": {
"version": "1.0.3",
@ -6978,6 +7095,38 @@
"integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=",
"dev": true
},
"busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
"requires": {
"dicer": "0.2.5",
"readable-stream": "1.1.x"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}
}
},
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@ -7197,7 +7346,6 @@
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
"dev": true,
"requires": {
"buffer-from": "^1.0.0",
"inherits": "^2.0.3",
@ -7626,6 +7774,38 @@
"minimist": "^1.1.1"
}
},
"dicer": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
"requires": {
"readable-stream": "1.1.x",
"streamsearch": "0.1.2"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}
}
},
"diff": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
@ -9392,6 +9572,21 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
},
"multer": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/multer/-/multer-1.4.2.tgz",
"integrity": "sha512-xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg==",
"requires": {
"append-field": "^1.0.0",
"busboy": "^0.2.11",
"concat-stream": "^1.5.2",
"mkdirp": "^0.5.1",
"object-assign": "^4.1.1",
"on-finished": "^2.3.0",
"type-is": "^1.6.4",
"xtend": "^4.0.0"
}
},
"mutexify": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/mutexify/-/mutexify-1.3.1.tgz",
@ -10871,6 +11066,11 @@
"readable-stream": "^2.0.2"
}
},
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
@ -11138,8 +11338,7 @@
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
"dev": true
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"typescript": {
"version": "4.1.3",
@ -11359,8 +11558,7 @@
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"dev": true
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
},
"yallist": {
"version": "3.1.1",

View File

@ -36,6 +36,7 @@
"missing-native-js-functions": "^1.2.4",
"mongodb": "^3.6.4",
"mongoose-long": "^0.3.2",
"multer": "^1.4.2",
"patch-package": "^6.2.2"
},
"devDependencies": {
@ -43,6 +44,7 @@
"@types/express": "^4.17.9",
"@types/i18next-node-fs-backend": "^2.1.0",
"@types/jsonwebtoken": "^8.5.0",
"@types/multer": "^1.4.5",
"@types/node": "^14.14.22",
"@types/node-fetch": "^2.5.7",
"0x": "^4.10.2",

View File

@ -7,7 +7,7 @@ export const NO_AUTHORIZATION_ROUTES = ["/api/v8/auth/login", "/api/v8/auth/regi
declare global {
namespace Express {
interface Request {
userid: any;
user_id: any;
token: any;
}
}
@ -22,7 +22,7 @@ export async function Authentication(req: Request, res: Response, next: NextFunc
const decoded: any = await checkToken(req.headers.authorization);
req.token = decoded;
req.userid = BigInt(decoded.id);
req.user_id = BigInt(decoded.id);
return next();
} catch (error) {
return next(new HTTPError(error.toString(), 400));

View File

@ -8,7 +8,7 @@ export function RateLimit({ count = 10, timespan = 1000 * 5, name = "/" }) {
// TODO: use new db mongoose models
/*
let id = req.userid || getIpAdress(req);
let id = req.user_id || getIpAdress(req);
const limit: { count: number; start: number } = (await db.data.ratelimit.routes[name][id].get()) || {
count: 0,

View File

@ -170,7 +170,7 @@ router.post(
// @ts-ignore
const user: User = {
id: Snowflake.generate(),
created_at: Date.now(),
created_at: new Date(),
username: adjusted_username,
discriminator,
avatar: null,
@ -182,7 +182,7 @@ router.post(
flags: 0n, // TODO: generate default flags
hash: adjusted_password,
guilds: [],
valid_tokens_since: Date.now(),
valid_tokens_since: new Date(),
user_settings: {
afk_timeout: 300,
allow_accessibility_detection: true,

View File

@ -12,7 +12,7 @@ import { getPermission, ChannelModel, InviteModel, InviteCreateEvent } from "fos
const router: Router = Router();
router.post("/", check(InviteCreateSchema), async (req: Request, res: Response) => {
const usID = req.userid;
const usID = req.user_id;
const chID = BigInt(req.params.channel_id);
const channel = await ChannelModel.findOne({ id: chID }).exec();
@ -33,7 +33,7 @@ router.post("/", check(InviteCreateSchema), async (req: Request, res: Response)
uses: 0,
max_uses: req.body.max_uses,
max_age: req.body.max_age,
created_at: Date.now(),
created_at: new Date(),
guild_id: guID,
channel_id: chID,
inviter_id: usID,

View File

@ -29,14 +29,14 @@ router.get("/:user", async (req: Request, res: Response) => {
return res.json(ban);
});
router.post("/:userid", check(BanCreateSchema), async (req: Request, res: Response) => {
router.post("/:user_id", check(BanCreateSchema), async (req: Request, res: Response) => {
const guild_id = BigInt(req.params.id);
const banned_user_id = BigInt(req.params.userid);
const banned_user_id = BigInt(req.params.user_id);
const banned_user = await getPublicUser(banned_user_id);
const perms = await getPermission(req.userid, guild_id);
const perms = await getPermission(req.user_id, guild_id);
if (!perms.has("BAN_MEMBERS")) throw new HTTPError("You don't have the permission to ban members", 403);
if (req.userid === banned_user_id) throw new HTTPError("You can't ban yourself", 400);
if (req.user_id === banned_user_id) throw new HTTPError("You can't ban yourself", 400);
await removeMember(banned_user_id, guild_id);
@ -44,7 +44,7 @@ router.post("/:userid", check(BanCreateSchema), async (req: Request, res: Respon
user_id: banned_user_id,
guild_id: guild_id,
ip: getIpAdress(req),
executor_id: req.userid,
executor_id: req.user_id,
reason: req.body.reason, // || otherwise empty
}).save();
@ -60,15 +60,15 @@ router.post("/:userid", check(BanCreateSchema), async (req: Request, res: Respon
return res.json(ban).send();
});
router.delete("/:userid", async (req: Request, res: Response) => {
router.delete("/:user_id", async (req: Request, res: Response) => {
var guild_id = BigInt(req.params.id);
var banned_user_id = BigInt(req.params.userid);
var banned_user_id = BigInt(req.params.user_id);
const banned_user = await getPublicUser(banned_user_id);
const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec();
if (!guild) throw new HTTPError("Guild not found", 404);
const perms = await getPermission(req.userid, guild.id);
const perms = await getPermission(req.user_id, guild.id);
if (!perms.has("BAN_MEMBERS")) {
throw new HTTPError("No permissions", 403);
}

View File

@ -24,7 +24,7 @@ router.get("/", async (req: Request, res: Response) => {
const guild = await GuildModel.findOne({ id: guild_id }).exec();
if (!guild) throw new HTTPError("Guild does not exist", 404);
const member = await MemberModel.findOne({ guild_id: guild_id, id: req.userid }, "id").exec();
const member = await MemberModel.findOne({ guild_id: guild_id, id: req.user_id }, "id").exec();
if (!member) throw new HTTPError("You are not a member of the guild you are trying to access", 401);
return res.json(guild);
@ -37,7 +37,7 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response)
const guild = await GuildModel.findOne({ id: guild_id }).exec();
if (!guild) throw new HTTPError("This guild does not exist", 404);
const perms = await getPermission(req.userid, guild_id);
const perms = await getPermission(req.user_id, guild_id);
if (!perms.has("MANAGE_GUILD")) throw new HTTPError("You do not have the MANAGE_GUILD permission", 401);
await GuildModel.updateOne({ id: guild_id }, body).exec();
@ -49,7 +49,7 @@ router.delete("/", async (req: Request, res: Response) => {
const guild = await GuildModel.findOne({ id: guild_id }, "owner_id").exec();
if (!guild) throw new HTTPError("This guild does not exist", 404);
if (guild.owner_id !== req.userid) throw new HTTPError("You are not the owner of this guild", 401);
if (guild.owner_id !== req.user_id) throw new HTTPError("You are not the owner of this guild", 401);
await emitEvent({
event: "GUILD_DELETE",

View File

@ -13,7 +13,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
const body = req.body as GuildCreateSchema;
const { maxGuilds } = Config.get().limits.user;
const user = await getPublicUser(req.userid, { guilds: true });
const user = await getPublicUser(req.user_id, { guilds: true });
if (user.guilds.length >= maxGuilds) {
throw new HTTPError(`Maximum number of guilds reached ${maxGuilds}`, 403);
@ -23,7 +23,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
const guild: Guild = {
name: body.name,
region: body.region || "en-US",
owner_id: req.userid,
owner_id: req.user_id,
icon: undefined,
afk_channel_id: undefined,
afk_timeout: 300,
@ -73,7 +73,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
tags: null,
}).save(),
]);
await addMember(req.userid, guild_id, { guild });
await addMember(req.user_id, guild_id, { guild });
res.status(201).json({ id: guild.id });
});

View File

@ -7,7 +7,7 @@ import { getPublicUser } from "../../../../../util/User";
const router: Router = Router();
router.get("/", async (req: Request, res: Response) => {
const user = await UserModel.findOne({ id: req.userid }, { guilds: true }).exec();
const user = await UserModel.findOne({ id: req.user_id }, { guilds: true }).exec();
if (!user) throw new HTTPError("User not found", 404);
var guildIDs = user.guilds || [];
@ -21,18 +21,18 @@ router.delete("/:id", async (req: Request, res: Response) => {
const guild = await GuildModel.findOne({ id: guildID }).exec();
if (!guild) throw new HTTPError("Guild doesn't exist", 404);
if (guild.owner_id === req.userid) throw new HTTPError("You can't leave your own guild", 400);
if (guild.owner_id === req.user_id) throw new HTTPError("You can't leave your own guild", 400);
await MemberModel.deleteOne({ id: req.userid, guild_id: guildID }).exec();
await UserModel.updateOne({ id: req.userid }, { $pull: { guilds: guildID } }).exec();
const user = await getPublicUser(req.userid);
await MemberModel.deleteOne({ id: req.user_id, guild_id: guildID }).exec();
await UserModel.updateOne({ id: req.user_id }, { $pull: { guilds: guildID } }).exec();
const user = await getPublicUser(req.user_id);
await emitEvent({
event: "GUILD_DELETE",
data: {
id: guildID,
},
user_id: req.userid,
user_id: req.user_id,
} as GuildDeleteEvent);
await emitEvent({

View File

@ -6,7 +6,7 @@ const router: Router = Router();
router.get("/", async (req: Request, res: Response) => {
// TODO: user projection
const user = await UserModel.findOne({ id: req.userid }).exec();
const user = await UserModel.findOne({ id: req.user_id }).exec();
if (!user) throw new HTTPError("User not found", 404);
res.json(user);

View File

@ -1,27 +1,69 @@
import { Embed, EmbedImage } from "fosscord-server-util";
import { Length } from "../util/instanceOf";
export const MessageCreateSchema = {
content: String,
nonce: Number,
tts: Boolean,
embed: {},
allowed_mentions: [],
message_reference: {
$content: new Length(String, 0, 2000),
$nonce: String,
$tts: Boolean,
$embed: {
$title: new Length(String, 0, 256), //title of embed
$type: String, // type of embed (always "rich" for webhook embeds)
$description: new Length(String, 0, 2048), // description of embed
$url: String, // url of embed
$timestamp: String, // ISO8601 timestamp
$color: Number, // color code of the embed
$footer: {
text: new Length(String, 0, 2048),
icon_url: String,
proxy_icon_url: String,
}, // footer object footer information
$image: EmbedImage, // image object image information
$thumbnail: EmbedImage, // thumbnail object thumbnail information
$video: EmbedImage, // video object video information
$provider: {
name: String,
url: String,
}, // provider object provider information
$author: {
name: new Length(String, 0, 256),
url: String,
icon_url: String,
proxy_icon_url: String,
}, // author object author information
$fields: new Length(
[
{
name: new Length(String, 0, 256),
value: new Length(String, 0, 1024),
$inline: Boolean,
},
],
0,
25
),
},
$allowed_mentions: [],
$message_reference: {
message_id: BigInt,
channel_id: BigInt,
guild_id: BigInt,
fail_if_not_exists: Boolean,
$guild_id: BigInt,
$fail_if_not_exists: Boolean,
},
$payload_json: String,
$file: Object,
};
export interface MessageCreateSchema {
content: string;
nonce: number;
tts: boolean;
embed: {};
allowed_mentions: [];
message_reference: {
content?: string;
nonce?: string;
tts?: boolean;
embed?: Embed & { timestamp: string };
allowed_mentions?: [];
message_reference?: {
message_id: bigint;
channel_id: bigint;
guild_id: bigint;
guild_id?: bigint;
fail_if_not_exists: boolean;
};
payload_json?: string;
}

View File

@ -32,9 +32,9 @@ export const Endpoints = {
Emoji: (emojiID: string, format = "png") => `${root}/emojis/${emojiID}.${format}`,
Asset: (name: string) => `${root}/assets/${name}`,
DefaultAvatar: (discriminator: string) => `${root}/embed/avatars/${discriminator}.png`,
Avatar: (userID: string, hash: string, format = "webp", size: number, dynamic = false) => {
Avatar: (user_id: string, hash: string, format = "webp", size: number, dynamic = false) => {
if (dynamic) format = hash.startsWith("a_") ? "gif" : format;
return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size });
return makeImageUrl(`${root}/avatars/${user_id}/${hash}`, { format, size });
},
Banner: (guildID: string, hash: string, format = "webp", size: number) =>
makeImageUrl(`${root}/banners/${guildID}/${hash}`, { format, size }),
@ -42,27 +42,18 @@ export const Endpoints = {
if (dynamic) format = hash.startsWith("a_") ? "gif" : format;
return makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size });
},
AppIcon: (
clientID: string,
hash: string,
{ format = "webp", size }: { format?: string; size?: number } = {}
) => makeImageUrl(`${root}/app-icons/${clientID}/${hash}`, { size, format }),
AppAsset: (
clientID: string,
hash: string,
{ format = "webp", size }: { format?: string; size?: number } = {}
) => makeImageUrl(`${root}/app-assets/${clientID}/${hash}`, { size, format }),
AppIcon: (clientID: string, hash: string, { format = "webp", size }: { format?: string; size?: number } = {}) =>
makeImageUrl(`${root}/app-icons/${clientID}/${hash}`, { size, format }),
AppAsset: (clientID: string, hash: string, { format = "webp", size }: { format?: string; size?: number } = {}) =>
makeImageUrl(`${root}/app-assets/${clientID}/${hash}`, { size, format }),
GDMIcon: (channelID: string, hash: string, format = "webp", size: number) =>
makeImageUrl(`${root}/channel-icons/${channelID}/${hash}`, { size, format }),
Splash: (guildID: string, hash: string, format = "webp", size: number) =>
makeImageUrl(`${root}/splashes/${guildID}/${hash}`, { size, format }),
DiscoverySplash: (guildID: string, hash: string, format = "webp", size: number) =>
makeImageUrl(`${root}/discovery-splashes/${guildID}/${hash}`, { size, format }),
TeamIcon: (
teamID: string,
hash: string,
{ format = "webp", size }: { format?: string; size?: number } = {}
) => makeImageUrl(`${root}/team-icons/${teamID}/${hash}`, { size, format }),
TeamIcon: (teamID: string, hash: string, { format = "webp", size }: { format?: string; size?: number } = {}) =>
makeImageUrl(`${root}/team-icons/${teamID}/${hash}`, { size, format }),
};
},
invite: (root: string, code: string) => `${root}/${code}`,
@ -346,9 +337,7 @@ export const MessageTypes = [
* * REPLY
* @typedef {string} SystemMessageType
*/
export const SystemMessageTypes = MessageTypes.filter(
(type: string | null) => type && type !== "DEFAULT" && type !== "REPLY"
);
export const SystemMessageTypes = MessageTypes.filter((type: string | null) => type && type !== "DEFAULT" && type !== "REPLY");
/**
* <info>Bots cannot set a `CUSTOM_STATUS`, it is only for custom statuses received from users</info>

View File

@ -43,7 +43,7 @@ export async function addMember(user_id: bigint, guild_id: bigint, cache?: { gui
guild_id: guild_id,
nick: undefined,
roles: [guild_id], // @everyone role
joined_at: Date.now(),
joined_at: new Date(),
premium_since: undefined,
deaf: false,
mute: false,

View File

@ -51,7 +51,7 @@ export class Length {
constructor(public type: any, public min: number, public max: number) {}
check(value: string) {
if (typeof value === "string") return value.length >= this.min && value.length <= this.max;
if (typeof value === "string" || Array.isArray(value)) return value.length >= this.min && value.length <= this.max;
if (typeof value === "number" || typeof value === "bigint") return value >= this.min && value <= this.max;
return false;
}