Merge branch 'master' into pr/LoboMetalurgico/424

This commit is contained in:
Flam3rboy
2021-10-10 12:50:45 +02:00
48 changed files with 207 additions and 379 deletions
+2 -4
View File
@@ -1,19 +1,17 @@
import { OptionsJson } from "body-parser";
import "missing-native-js-functions";
import { Connection } from "mongoose";
import { Server, ServerOptions } from "lambert-server";
import { Authentication, CORS } from "./middlewares/";
import { Config, initDatabase, initEvent } from "@fosscord/util";
import { ErrorHandler } from "./middlewares/ErrorHandler";
import { BodyParser } from "./middlewares/BodyParser";
import { Router, Request, Response, NextFunction } from "express";
import mongoose from "mongoose";
import path from "path";
import { initRateLimits } from "./middlewares/RateLimit";
import TestClient from "./middlewares/TestClient";
import { initTranslation } from "./middlewares/Translation";
import morgan from "morgan";
import { initInstance } from "./util/Instance";
import { registerRoutes } from "@fosscord/util";
export interface FosscordServerOptions extends ServerOptions {}
@@ -75,7 +73,7 @@ export class FosscordServer extends Server {
await initRateLimits(api);
await initTranslation(api);
this.routes = await this.registerRoutes(path.join(__dirname, "routes", "/"));
this.routes = await registerRoutes(this, path.join(__dirname, "routes", "/"));
api.use("*", (error: any, req: Request, res: Response, next: NextFunction) => {
if (error) return next(error);
@@ -2,7 +2,7 @@ import { Router, Request, Response } from "express";
import { HTTPError } from "lambert-server";
import { route } from "@fosscord/api";
import { random } from "@fosscord/api";
import { getPermission, Channel, Invite, InviteCreateEvent, emitEvent, User, Guild, PublicInviteRelation } from "@fosscord/util";
import { Channel, Invite, InviteCreateEvent, emitEvent, User, Guild, PublicInviteRelation } from "@fosscord/util";
import { isTextChannel } from "./messages";
const router: Router = Router();
@@ -22,7 +22,7 @@ const router: Router = Router();
export default router;
function isTextChannel(type: ChannelType): boolean {
export function isTextChannel(type: ChannelType): boolean {
switch (type) {
case ChannelType.GUILD_STORE:
case ChannelType.GUILD_VOICE:
@@ -39,7 +39,6 @@ function isTextChannel(type: ChannelType): boolean {
return true;
}
}
module.exports.isTextChannel = isTextChannel;
export interface MessageCreateSchema {
content?: string;
@@ -44,8 +44,8 @@ router.put(
};
channel.permission_overwrites!.push(overwrite);
}
overwrite.allow = String(req.permission!.bitfield & (BigInt(body.allow) || 0n));
overwrite.deny = String(req.permission!.bitfield & (BigInt(body.deny) || 0n));
overwrite.allow = String(req.permission!.bitfield & (BigInt(body.allow) || BigInt("0")));
overwrite.deny = String(req.permission!.bitfield & (BigInt(body.deny) || BigInt("0")));
await Promise.all([
channel.save(),
+7 -2
View File
@@ -57,7 +57,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" })
...body,
guild_id: guild_id,
managed: false,
permissions: String(req.permission!.bitfield & (body.permissions || 0n)),
permissions: String(req.permission!.bitfield & (body.permissions || BigInt("0"))),
tags: undefined
});
@@ -105,7 +105,12 @@ router.patch("/:role_id", route({ body: "RoleModifySchema", permission: "MANAGE_
const { role_id, guild_id } = req.params;
const body = req.body as RoleModifySchema;
const role = new Role({ ...body, id: role_id, guild_id, permissions: String(req.permission!.bitfield & (body.permissions || 0n)) });
const role = new Role({
...body,
id: role_id,
guild_id,
permissions: String(req.permission!.bitfield & (body.permissions || BigInt("0")))
});
await Promise.all([
role.save(),
+1 -1
View File
@@ -47,7 +47,7 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req:
managed: true,
mentionable: true,
name: "@everyone",
permissions: 2251804225n,
permissions: BigInt("2251804225"),
position: 0,
tags: null
}).save()
-37
View File
@@ -1,37 +0,0 @@
const jwa = require("jwa");
var STR64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".split("");
function base64url(string: string, encoding: string) {
// @ts-ignore
return Buffer.from(string, encoding).toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
}
function to64String(input: number, current = ""): string {
if (input < 0 && current.length == 0) {
input = input * -1;
}
var modify = input % 64;
var remain = Math.floor(input / 64);
var result = STR64[modify] + current;
return remain <= 0 ? result : to64String(remain, result);
}
function to64Parse(input: string) {
var result = 0;
var toProc = input.split("");
var e;
for (e in toProc) {
result = result * 64 + STR64.indexOf(toProc[e]);
}
return result;
}
// @ts-ignore
const start = `${base64url("311129357362135041")}.${to64String(Date.now())}`;
const signature = jwa("HS256").sign(start, `test`);
const token = `${start}.${signature}`;
console.log(token);
// MzExMTI5MzU3MzYyMTM1MDQx.XdQb_rA.907VgF60kocnOTl32MSUWGSSzbAytQ0jbt36KjLaxuY
// MzExMTI5MzU3MzYyMTM1MDQx.XdQbaPy.4vGx4L7IuFJGsRe6IL3BeybLIvbx4Vauvx12pwNsy2U
-13
View File
@@ -1,13 +0,0 @@
import jwt from "jsonwebtoken";
const algorithm = "HS256";
const iat = Math.floor(Date.now() / 1000);
// @ts-ignore
const token = jwt.sign({ id: "311129357362135041" }, "secret", {
algorithm,
});
console.log(token);
const decoded = jwt.verify(token, "secret", { algorithms: [algorithm] });
console.log(decoded);
-12
View File
@@ -1,12 +0,0 @@
import { checkPassword } from "@fosscord/api";
console.log(checkPassword("123456789012345"));
// -> 0.25
console.log(checkPassword("ABCDEFGHIJKLMOPQ"));
// -> 0.25
console.log(checkPassword("ABC123___...123"));
// ->
console.log(checkPassword(""));
// ->
// console.log(checkPassword(""));
// // ->