mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-24 14:35:27 +00:00
Merge branch 'master' into pr/Thesourtimes/430
This commit is contained in:
+314
-37
@@ -2887,47 +2887,324 @@
|
||||
},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||
},
|
||||
"EmojiListResponse": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"animated": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"available": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"EmojiCreateSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"image": {
|
||||
"type": "string"
|
||||
},
|
||||
"require_colons": {
|
||||
"type": [
|
||||
"null",
|
||||
"boolean"
|
||||
]
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"managed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"require_colons": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"guild_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"image"
|
||||
],
|
||||
"definitions": {
|
||||
"ChannelPermissionOverwriteType": {
|
||||
"enum": [
|
||||
0,
|
||||
1
|
||||
],
|
||||
"type": "number"
|
||||
},
|
||||
"Embed": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"article",
|
||||
"gifv",
|
||||
"image",
|
||||
"link",
|
||||
"rich",
|
||||
"video"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"color": {
|
||||
"type": "integer"
|
||||
},
|
||||
"footer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy_icon_url": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"text"
|
||||
]
|
||||
},
|
||||
"image": {
|
||||
"$ref": "#/definitions/EmbedImage"
|
||||
},
|
||||
"thumbnail": {
|
||||
"$ref": "#/definitions/EmbedImage"
|
||||
},
|
||||
"video": {
|
||||
"$ref": "#/definitions/EmbedImage"
|
||||
},
|
||||
"provider": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"author": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy_icon_url": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fields": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
},
|
||||
"inline": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"value"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"animated",
|
||||
"available",
|
||||
"id",
|
||||
"managed",
|
||||
"name",
|
||||
"require_colons"
|
||||
]
|
||||
"EmbedImage": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"height": {
|
||||
"type": "integer"
|
||||
},
|
||||
"width": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ChannelModifySchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"maxLength": 100,
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
0,
|
||||
1,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6
|
||||
],
|
||||
"type": "number"
|
||||
},
|
||||
"topic": {
|
||||
"type": "string"
|
||||
},
|
||||
"icon": {
|
||||
"type": [
|
||||
"null",
|
||||
"string"
|
||||
]
|
||||
},
|
||||
"bitrate": {
|
||||
"type": "integer"
|
||||
},
|
||||
"user_limit": {
|
||||
"type": "integer"
|
||||
},
|
||||
"rate_limit_per_user": {
|
||||
"type": "integer"
|
||||
},
|
||||
"position": {
|
||||
"type": "integer"
|
||||
},
|
||||
"permission_overwrites": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/ChannelPermissionOverwriteType"
|
||||
},
|
||||
"allow": {
|
||||
"type": "string"
|
||||
},
|
||||
"deny": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"allow",
|
||||
"deny",
|
||||
"id",
|
||||
"type"
|
||||
]
|
||||
}
|
||||
},
|
||||
"parent_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"nsfw": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"rtc_region": {
|
||||
"type": "string"
|
||||
},
|
||||
"default_auto_archive_duration": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"UserPublic": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"discriminator": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"public_flags": {
|
||||
"type": "integer"
|
||||
},
|
||||
"avatar": {
|
||||
"type": "string"
|
||||
},
|
||||
"accent_color": {
|
||||
"type": "integer"
|
||||
},
|
||||
"banner": {
|
||||
"type": "string"
|
||||
},
|
||||
"bio": {
|
||||
"type": "string"
|
||||
},
|
||||
"bot": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"bio",
|
||||
"bot",
|
||||
"discriminator",
|
||||
"id",
|
||||
"public_flags",
|
||||
"username"
|
||||
]
|
||||
},
|
||||
"PublicConnectedAccount": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
},
|
||||
"verifie": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"type",
|
||||
"verifie"
|
||||
]
|
||||
}
|
||||
},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||
},
|
||||
"EmojiModifySchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"ChannelPermissionOverwriteType": {
|
||||
@@ -4470,7 +4747,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"type": "bigint"
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "integer"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Discord Test Client</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app-mount"></div>
|
||||
<script>
|
||||
@@ -46,12 +47,52 @@
|
||||
);
|
||||
|
||||
// Auto register guest account:
|
||||
const prefix = [
|
||||
"mysterious",
|
||||
"adventurous",
|
||||
"courageous",
|
||||
"precious",
|
||||
"cynical",
|
||||
"despicable",
|
||||
"suspicious",
|
||||
"gorgeous",
|
||||
"lovely",
|
||||
"stunning",
|
||||
"based",
|
||||
"keyed",
|
||||
"ratioed",
|
||||
"twink",
|
||||
"phoned"
|
||||
];
|
||||
const suffix = [
|
||||
"Anonymous",
|
||||
"Lurker",
|
||||
"User",
|
||||
"Enjoyer",
|
||||
"Hunk",
|
||||
"Top",
|
||||
"Bottom",
|
||||
"Sub",
|
||||
"Coolstar",
|
||||
"Wrestling",
|
||||
"TylerTheCreator",
|
||||
"Ad"
|
||||
];
|
||||
|
||||
Array.prototype.random = function () {
|
||||
return this[Math.floor(Math.random() * this.length)];
|
||||
};
|
||||
|
||||
function _generateName() {
|
||||
return `${prefix.random()}${suffix.random()}`;
|
||||
}
|
||||
|
||||
const token = JSON.parse(localStorage.getItem("token"));
|
||||
if (!token && location.pathname !== "/login" && location.pathname !== "/register") {
|
||||
fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ username: "Anonymous", consent: true })
|
||||
body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)}
|
||||
})
|
||||
.then((x) => x.json())
|
||||
.then((x) => {
|
||||
@@ -62,6 +103,12 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const settings = JSON.parse(localStorage.getItem("UserSettingsStore"));
|
||||
if (settings && settings.locale === "en") {
|
||||
settings.locale = "en-US";
|
||||
localStorage.setItem("UserSettingsStore", JSON.stringify(settings));
|
||||
}
|
||||
</script>
|
||||
<script src="/assets/479a2f1e7d625dc134b9.js"></script>
|
||||
<script src="/assets/a15fd133a1d2d77a2424.js"></script>
|
||||
|
||||
Generated
BIN
Binary file not shown.
+6
-29
@@ -10,7 +10,7 @@
|
||||
"test": "npm run build && npm run test:only",
|
||||
"test:watch": "jest --watch",
|
||||
"start": "npm run build && node dist/start",
|
||||
"build": "npx tsc -b .",
|
||||
"build": "npx tsc -p .",
|
||||
"build-docker": "tsc -p tsconfig-docker.json",
|
||||
"dev": "tsnd --respawn src/start.ts",
|
||||
"patch": "ts-patch install -s && npx patch-package",
|
||||
@@ -38,10 +38,6 @@
|
||||
"homepage": "https://fosscord.com",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.15.5",
|
||||
"@babel/preset-env": "^7.15.6",
|
||||
"@babel/preset-typescript": "^7.15.0",
|
||||
"@swc/cli": "^0.1.51",
|
||||
"@swc/core": "^1.2.93",
|
||||
"@types/amqplib": "^0.8.1",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/express": "^4.17.9",
|
||||
@@ -49,65 +45,46 @@
|
||||
"@types/jest": "^27.0.1",
|
||||
"@types/jest-expect-message": "^1.0.3",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/mongodb": "^3.6.9",
|
||||
"@types/mongoose": "^5.10.5",
|
||||
"@types/mongoose-autopopulate": "^0.10.1",
|
||||
"@types/mongoose-lean-virtuals": "^0.5.1",
|
||||
"@types/multer": "^1.4.5",
|
||||
"@types/node": "^14.17.9",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@zerollup/ts-transform-paths": "^1.7.18",
|
||||
"0x": "^4.10.2",
|
||||
"babel-jest": "^27.2.0",
|
||||
"caxa": "^2.1.0",
|
||||
"image-size": "^1.0.0",
|
||||
"jest": "^26.6.3",
|
||||
"jest-expect-message": "^1.0.2",
|
||||
"jest-runtime": "^27.2.1",
|
||||
"saslprep": "^1.0.3",
|
||||
"ts-node": "^9.1.1",
|
||||
"ts-node-dev": "^1.1.6",
|
||||
"ts-patch": "^1.4.4",
|
||||
"tsup": "^5.4.0",
|
||||
"typescript": "^4.4.2",
|
||||
"typescript-json-schema": "0.50.1"
|
||||
"typescript-json-schema": "0.50.1",
|
||||
"@types/morgan": "^1.9.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fosscord/util": "file:../util",
|
||||
"@types/morgan": "^1.9.3",
|
||||
"ajv": "8.6.2",
|
||||
"ajv-formats": "^2.1.1",
|
||||
"amqplib": "^0.8.0",
|
||||
"assert": "^1.5.0",
|
||||
"atomically": "^1.7.0",
|
||||
"bcrypt": "^5.0.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"cheerio": "^1.0.0-rc.9",
|
||||
"dot-prop": "^6.0.1",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"dotenv": "^8.2.0",
|
||||
"env-paths": "^2.2.1",
|
||||
"esbuild": "^0.13.4",
|
||||
"express": "^4.17.1",
|
||||
"express-validator": "^6.9.2",
|
||||
"form-data": "^3.0.0",
|
||||
"i18next": "^19.9.2",
|
||||
"i18next-http-middleware": "^3.1.3",
|
||||
"i18next-node-fs-backend": "^2.1.3",
|
||||
"image-size": "^1.0.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-server": "^1.2.11",
|
||||
"missing-native-js-functions": "^1.2.17",
|
||||
"mongoose": "^5.12.3",
|
||||
"mongoose-autopopulate": "^0.12.3",
|
||||
"mongoose-long": "^0.3.2",
|
||||
"morgan": "^1.10.0",
|
||||
"multer": "^1.4.2",
|
||||
"node-fetch": "^2.6.1",
|
||||
"patch-package": "^6.4.7",
|
||||
"supertest": "^6.1.6",
|
||||
"tsconfig-paths": "^3.11.0",
|
||||
"typeorm": "^0.2.37",
|
||||
"wsc": "^0.3.0"
|
||||
"typeorm": "^0.2.37"
|
||||
},
|
||||
"jest": {
|
||||
"setupFiles": [
|
||||
|
||||
+2
-4
@@ -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();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { emitEvent, getPermission, MessageAckEvent, ReadState } from "@fosscord/util";
|
||||
import { emitEvent, getPermission, MessageAckEvent, ReadState, Snowflake } from "@fosscord/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
@@ -18,7 +18,11 @@ router.post("/", route({ body: "MessageAcknowledgeSchema" }), async (req: Reques
|
||||
const permission = await getPermission(req.user_id, undefined, channel_id);
|
||||
permission.hasThrow("VIEW_CHANNEL");
|
||||
|
||||
await ReadState.update({ user_id: req.user_id, channel_id }, { user_id: req.user_id, channel_id, last_message_id: message_id });
|
||||
let read_state = await ReadState.findOne({ user_id: req.user_id, channel_id });
|
||||
if (!read_state) read_state = new ReadState({ user_id: req.user_id, channel_id });
|
||||
read_state.last_message_id = message_id;
|
||||
|
||||
await read_state.save();
|
||||
|
||||
await emitEvent({
|
||||
event: "MESSAGE_ACK",
|
||||
|
||||
@@ -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;
|
||||
@@ -103,6 +102,7 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
}
|
||||
|
||||
const messages = await Message.find(query);
|
||||
const endpoint = Config.get().cdn.endpointPublic;
|
||||
|
||||
return res.json(
|
||||
messages.map((x) => {
|
||||
@@ -115,7 +115,9 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
// @ts-ignore
|
||||
if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: "0", avatar: null };
|
||||
x.attachments?.forEach((x) => {
|
||||
x.proxy_url = `${Config.get().cdn.endpointPublic || "http://localhost:3003"}${new URL(x.proxy_url).pathname}`;
|
||||
// dynamically set attachment proxy_url in case the endpoint changed
|
||||
const uri = x.proxy_url.startsWith("http") ? x.proxy_url : `https://example.org${x.proxy_url}`;
|
||||
x.proxy_url = `${endpoint == null ? "http://localhost:3003" : endpoint}${new URL(uri).pathname}`;
|
||||
});
|
||||
|
||||
return x;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { Config, DiscordApiErrors, emitEvent, Emoji, GuildEmojisUpdateEvent, handleFile, Member, Snowflake, User } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
|
||||
const router = Router();
|
||||
|
||||
export interface EmojiCreateSchema {
|
||||
name?: string;
|
||||
image: string;
|
||||
require_colons?: boolean | null;
|
||||
roles?: string[];
|
||||
}
|
||||
|
||||
export interface EmojiModifySchema {
|
||||
name?: string;
|
||||
roles?: string[];
|
||||
}
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
|
||||
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
||||
|
||||
const emojis = await Emoji.find({ where: { guild_id: guild_id }, relations: ["user"] });
|
||||
|
||||
return res.json(emojis);
|
||||
});
|
||||
|
||||
router.get("/:emoji_id", route({}), async (req: Request, res: Response) => {
|
||||
const { guild_id, emoji_id } = req.params;
|
||||
|
||||
await Member.IsInGuildOrFail(req.user_id, guild_id);
|
||||
|
||||
const emoji = await Emoji.findOneOrFail({ where: { guild_id: guild_id, id: emoji_id }, relations: ["user"] });
|
||||
|
||||
return res.json(emoji);
|
||||
});
|
||||
|
||||
router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_AND_STICKERS" }), async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
const body = req.body as EmojiCreateSchema;
|
||||
|
||||
const emoji_count = await Emoji.count({ guild_id: guild_id });
|
||||
const { maxEmojis } = Config.get().limits.guild;
|
||||
|
||||
if (emoji_count >= maxEmojis) throw DiscordApiErrors.MAXIMUM_NUMBER_OF_EMOJIS_REACHED.withParams(maxEmojis);
|
||||
|
||||
const id = Snowflake.generate();
|
||||
|
||||
if (body.require_colons == null) body.require_colons = true;
|
||||
|
||||
const user = await User.findOneOrFail({ id: req.user_id });
|
||||
|
||||
body.image = (await handleFile(`/emojis/${id}`, body.image)) as string;
|
||||
|
||||
const emoji = await new Emoji({
|
||||
id: id,
|
||||
guild_id: guild_id,
|
||||
...body,
|
||||
user: user,
|
||||
managed: false,
|
||||
animated: false, // TODO: Add support animated emojis
|
||||
available: true,
|
||||
roles: []
|
||||
}).save();
|
||||
|
||||
await emitEvent({
|
||||
event: "GUILD_EMOJIS_UPDATE",
|
||||
guild_id: guild_id,
|
||||
data: {
|
||||
guild_id: guild_id,
|
||||
emojis: await Emoji.find({ guild_id: guild_id })
|
||||
}
|
||||
} as GuildEmojisUpdateEvent);
|
||||
|
||||
return res.status(201).json(emoji);
|
||||
});
|
||||
|
||||
router.patch(
|
||||
"/:emoji_id",
|
||||
route({ body: "EmojiModifySchema", permission: "MANAGE_EMOJIS_AND_STICKERS" }),
|
||||
async (req: Request, res: Response) => {
|
||||
const { emoji_id, guild_id } = req.params;
|
||||
const body = req.body as EmojiModifySchema;
|
||||
|
||||
const emoji = await new Emoji({ ...body, id: emoji_id, guild_id: guild_id }).save();
|
||||
|
||||
await emitEvent({
|
||||
event: "GUILD_EMOJIS_UPDATE",
|
||||
guild_id: guild_id,
|
||||
data: {
|
||||
guild_id: guild_id,
|
||||
emojis: await Emoji.find({ guild_id: guild_id })
|
||||
}
|
||||
} as GuildEmojisUpdateEvent);
|
||||
|
||||
return res.json(emoji);
|
||||
}
|
||||
);
|
||||
|
||||
router.delete("/:emoji_id", route({ permission: "MANAGE_EMOJIS_AND_STICKERS" }), async (req: Request, res: Response) => {
|
||||
const { emoji_id, guild_id } = req.params;
|
||||
|
||||
await Emoji.delete({
|
||||
id: emoji_id,
|
||||
guild_id: guild_id
|
||||
});
|
||||
|
||||
await emitEvent({
|
||||
event: "GUILD_EMOJIS_UPDATE",
|
||||
guild_id: guild_id,
|
||||
data: {
|
||||
guild_id: guild_id,
|
||||
emojis: await Emoji.find({ guild_id: guild_id })
|
||||
}
|
||||
} as GuildEmojisUpdateEvent);
|
||||
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -17,7 +17,7 @@ const router: Router = Router();
|
||||
|
||||
export interface RoleModifySchema {
|
||||
name?: string;
|
||||
permissions?: bigint;
|
||||
permissions?: string;
|
||||
color?: number;
|
||||
hoist?: boolean; // whether the role should be displayed separately in the sidebar
|
||||
mentionable?: boolean; // whether the role should be mentionable
|
||||
@@ -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 & BigInt(body.permissions || "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 & BigInt(body.permissions || "0"))
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
role.save(),
|
||||
|
||||
@@ -10,10 +10,10 @@ const InviteRegex = /\W/g;
|
||||
router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
|
||||
const guild = await Guild.findOneOrFail({ where: { id: guild_id }, relations: ["vanity_url"] });
|
||||
if (!guild.vanity_url) return res.json({ code: null });
|
||||
const invite = await Invite.findOne({ where: { guild_id: guild_id, vanity_url: true } });
|
||||
if (!invite) return res.json({ code: null });
|
||||
|
||||
return res.json({ code: guild.vanity_url_code, uses: guild.vanity_url.uses });
|
||||
return res.json({ code: invite.code, uses: invite.uses });
|
||||
});
|
||||
|
||||
export interface VanityUrlSchema {
|
||||
@@ -33,20 +33,9 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" })
|
||||
const invite = await Invite.findOne({ code });
|
||||
if (invite) throw new HTTPError("Invite already exists");
|
||||
|
||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||
const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
|
||||
|
||||
Promise.all([
|
||||
Guild.update({ id: guild_id }, { vanity_url_code: code }),
|
||||
Invite.delete({ code: guild.vanity_url_code }),
|
||||
new Invite({
|
||||
code: code,
|
||||
uses: 0,
|
||||
created_at: new Date(),
|
||||
guild_id,
|
||||
channel_id: id
|
||||
}).save()
|
||||
]);
|
||||
await Invite.update({ vanity_url: true, guild_id }, { code: code, channel_id: id });
|
||||
|
||||
return res.json({ code: code });
|
||||
});
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -33,7 +33,6 @@ router.delete("/:code", route({}), async (req: Request, res: Response) => {
|
||||
|
||||
await Promise.all([
|
||||
Invite.delete({ code }),
|
||||
Guild.update({ vanity_url_code: code }, { vanity_url_code: undefined }),
|
||||
emitEvent({
|
||||
event: "INVITE_DELETE",
|
||||
guild_id: guild_id,
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
@@ -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(""));
|
||||
// // ->
|
||||
+4
-2
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"exclude": ["node_modules"],
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"incremental": true /* Enable incremental compilation */,
|
||||
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
|
||||
@@ -69,6 +70,7 @@
|
||||
"@fosscord/api": ["src/index"],
|
||||
"@fosscord/api/*": ["src/*"]
|
||||
},
|
||||
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
|
||||
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
|
||||
"experimentalDecorators": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user