Merge branch 'master' into fix/claim_accounts
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"openapi": "3.0.0",
|
||||
"servers": [
|
||||
{
|
||||
"url": "https://api.fosscord.com/v{version}",
|
||||
"url": "https://api.fosscord.com/api/v{version}",
|
||||
"description": "Official fosscord instance",
|
||||
"variables": {
|
||||
"version": {
|
||||
@@ -2960,7 +2960,7 @@
|
||||
"type": {
|
||||
"type": "string"
|
||||
},
|
||||
"verifie": {
|
||||
"verified": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"visibility": {
|
||||
@@ -2980,7 +2980,7 @@
|
||||
"type",
|
||||
"user",
|
||||
"user_id",
|
||||
"verifie",
|
||||
"verified",
|
||||
"visibility"
|
||||
]
|
||||
},
|
||||
@@ -3119,7 +3119,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"status": {
|
||||
"enum": ["dnd", "idle", "offline", "online"],
|
||||
"enum": ["dnd", "idle", "offline", "online", "invisible"],
|
||||
"type": "string"
|
||||
},
|
||||
"stream_notifications_enabled": {
|
||||
@@ -5677,7 +5677,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"status": {
|
||||
"enum": ["dnd", "idle", "offline", "online"],
|
||||
"enum": ["dnd", "idle", "offline", "online", "invisible"],
|
||||
"type": "string"
|
||||
},
|
||||
"stream_notifications_enabled": {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Remove `<link id="logincss" rel="stylesheet" href="/assets/fosscord-login.css" />` from header when we're not accessing `/login` or `/register`
|
||||
// fosscord-login.css replaces discord's TOS tooltip with something more fitting for fosscord, which when included in the main app, causes other tooltips
|
||||
// to be affected, which is potentially unwanted.
|
||||
//
|
||||
// This script removes fosscord-login.css when a user reloads the page. From testing, it appears fosscord already properly removes
|
||||
// fosscord-login.css after login is successful, but not if you reload the page after logging in. This script is to remove fosscord-login.css in
|
||||
// that specific case.
|
||||
|
||||
var token = JSON.parse(localStorage.getItem("token"));
|
||||
if (!token && location.pathname !== "/login" && location.pathname !== "/register") {
|
||||
document.getElementById("logincss").remove();
|
||||
}
|
||||
@@ -355,11 +355,11 @@
|
||||
"type": {
|
||||
"type": "string"
|
||||
},
|
||||
"verifie": {
|
||||
"verified": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["name", "type", "verifie"]
|
||||
"required": ["name", "type", "verified"]
|
||||
}
|
||||
},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||
@@ -7900,7 +7900,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"status": {
|
||||
"enum": ["dnd", "idle", "offline", "online"],
|
||||
"enum": ["dnd", "idle", "offline", "online", "invisible"],
|
||||
"type": "string"
|
||||
},
|
||||
"stream_notifications_enabled": {
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
"BASE_TYPE_BOOLEAN": "This field must be a boolean",
|
||||
"BASE_TYPE_CHOICES": "This field must be one of ({{types}})",
|
||||
"BASE_TYPE_CLASS": "This field must be an instance of {{type}}",
|
||||
"BASE_TYPE_OBJECT": "This field must be an object",
|
||||
"BASE_TYPE_ARRAY": "This field must be an array",
|
||||
"UNKOWN_FIELD": "Unknown key: {{key}}",
|
||||
"BASE_TYPE_CONSTANT": "This field must be {{value}}",
|
||||
"EMAIL_TYPE_INVALID_EMAIL": "Not a well-formed email address",
|
||||
"DATE_TYPE_PARSE": "Could not parse {{date}}. Should be ISO8601",
|
||||
"BASE_TYPE_BAD_LENGTH": "Must be between {{length}} in length"
|
||||
"BASE_TYPE_OBJECT": "שדה זה חייב להיות אובייקט",
|
||||
"BASE_TYPE_ARRAY": "שדה זה חייב להיות מערך",
|
||||
"UNKOWN_FIELD": "מפתח לא ידוע: {{key}}",
|
||||
"BASE_TYPE_CONSTANT": "שדה זה להיות {{value}}",
|
||||
"EMAIL_TYPE_INVALID_EMAIL": "כתובת דואר אלקטרוני לא חוקית",
|
||||
"DATE_TYPE_PARSE": "לא ניתן לנתח {{date}}. צריך להיות ISO8601",
|
||||
"BASE_TYPE_BAD_LENGTH": "האורך חייב להיות בין {{length}}"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+2583
-3814
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -49,7 +49,7 @@
|
||||
"@types/morgan": "^1.9.3",
|
||||
"@types/multer": "^1.4.5",
|
||||
"@types/node": "^14.17.9",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/node-fetch": "^2.5.5",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@zerollup/ts-transform-paths": "^1.7.18",
|
||||
"jest": "^27.2.5",
|
||||
@@ -86,7 +86,7 @@
|
||||
"missing-native-js-functions": "^1.2.18",
|
||||
"morgan": "^1.10.0",
|
||||
"multer": "^1.4.2",
|
||||
"node-fetch": "^3.1.1",
|
||||
"node-fetch": "^2.6.2",
|
||||
"patch-package": "^6.4.7",
|
||||
"picocolors": "^1.0.0",
|
||||
"proxy-agent": "^5.0.0",
|
||||
|
||||
@@ -26,6 +26,6 @@ DROP TABLE webhooks;
|
||||
DROP TABLE channels;
|
||||
DROP TABLE members;
|
||||
DROP TABLE guilds;
|
||||
DROP TABLE client_relase;
|
||||
DROP TABLE client_release;
|
||||
-- DROP TABLE users;
|
||||
-- DROP TABLE config;
|
||||
@@ -15,6 +15,7 @@ export const NO_AUTHORIZATION_ROUTES = [
|
||||
"/experiments",
|
||||
"/updates",
|
||||
"/downloads/",
|
||||
"/scheduled-maintenances/upcoming.json",
|
||||
// Public kubernetes integration
|
||||
"/-/readyz",
|
||||
"/-/healthz",
|
||||
|
||||
@@ -19,7 +19,8 @@ export interface InviteCreateSchema {
|
||||
target_user_type?: number;
|
||||
}
|
||||
|
||||
router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE" }), async (req: Request, res: Response) => {
|
||||
router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE", right: "CREATE_INVITES" }),
|
||||
async (req: Request, res: Response) => {
|
||||
const { user_id } = req;
|
||||
const { channel_id } = req.params;
|
||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Channel, emitEvent, getPermission, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
|
||||
import { Channel, emitEvent, getPermission, getRights, MessageDeleteEvent, Message, MessageUpdateEvent } from "@fosscord/util";
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { handleMessage, postHandleMessage } from "@fosscord/api";
|
||||
@@ -7,18 +7,23 @@ import { MessageCreateSchema } from "../index";
|
||||
const router = Router();
|
||||
// TODO: message content/embed string length limit
|
||||
|
||||
router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
|
||||
router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES", right: "SEND_MESSAGES" }), async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
var body = req.body as MessageCreateSchema;
|
||||
|
||||
const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] });
|
||||
|
||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
||||
|
||||
const rights = await getRights(req.user_id);
|
||||
|
||||
if (req.user_id !== message.author_id) {
|
||||
permissions.hasThrow("MANAGE_MESSAGES");
|
||||
body = { flags: body.flags }; // admins can only suppress embeds of other messages
|
||||
}
|
||||
if ((req.user_id !== message.author_id)) {
|
||||
if (!rights.has("MANAGE_MESSAGES")) {
|
||||
permissions.hasThrow("MANAGE_MESSAGES");
|
||||
body = { flags: body.flags };
|
||||
// guild admins can only suppress embeds of other messages, no such restriction imposed to instance-wide admins
|
||||
}
|
||||
} else rights.hasThrow("SELF_EDIT_MESSAGES");
|
||||
|
||||
const new_message = await handleMessage({
|
||||
...message,
|
||||
@@ -46,17 +51,20 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
|
||||
return res.json(message);
|
||||
});
|
||||
|
||||
// permission check only if deletes messagr from other user
|
||||
router.delete("/", route({}), async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
|
||||
const channel = await Channel.findOneOrFail({ id: channel_id });
|
||||
const message = await Message.findOneOrFail({ id: message_id });
|
||||
|
||||
const rights = await getRights(req.user_id);
|
||||
|
||||
if (message.author_id !== req.user_id) {
|
||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||
permission.hasThrow("MANAGE_MESSAGES");
|
||||
}
|
||||
if ((message.author_id !== req.user_id)) {
|
||||
if (!rights.has("MANAGE_MESSAGES")) {
|
||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||
permission.hasThrow("MANAGE_MESSAGES");
|
||||
}
|
||||
} else rights.hasThrow("SELF_DELETE_MESSAGES");
|
||||
|
||||
await Message.delete({ id: message_id });
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { Relase, Config } from "@fosscord/util";
|
||||
import { Release, Config } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -12,9 +12,9 @@ router.get("/:branch", route({}), async (req: Request, res: Response) => {
|
||||
|
||||
if(!platform || !["linux", "osx", "win"].includes(platform.toString())) return res.status(404)
|
||||
|
||||
const relase = await Relase.findOneOrFail({ name: client.relases.upstreamVersion });
|
||||
const release = await Release.findOneOrFail({ name: client.releases.upstreamVersion });
|
||||
|
||||
res.redirect(relase[`win_url`]);
|
||||
res.redirect(release[`win_url`]);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -33,17 +33,32 @@ router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res:
|
||||
const { guild_id } = req.params;
|
||||
|
||||
let bans = await Ban.find({ guild_id: guild_id });
|
||||
let promisesToAwait: object[] = [];
|
||||
const bansObj: object[] = [];
|
||||
|
||||
/* Filter secret from database registry.*/
|
||||
bans.filter((ban) => ban.user_id !== ban.executor_id); // pretend self-bans don't exist to prevent victim chasing
|
||||
|
||||
bans.filter(ban => ban.user_id !== ban.executor_id);
|
||||
// pretend self-bans don't exist to prevent victim chasing
|
||||
|
||||
bans.forEach((registry: BanRegistrySchema) => {
|
||||
delete registry.ip;
|
||||
bans.forEach((ban) => {
|
||||
promisesToAwait.push(User.getPublicUser(ban.user_id));
|
||||
});
|
||||
|
||||
return res.json(bans);
|
||||
|
||||
const bannedUsers: object[] = await Promise.all(promisesToAwait);
|
||||
|
||||
bans.forEach((ban, index) => {
|
||||
const user = bannedUsers[index] as User;
|
||||
bansObj.push({
|
||||
reason: ban.reason,
|
||||
user: {
|
||||
username: user.username,
|
||||
discriminator: user.discriminator,
|
||||
id: user.id,
|
||||
avatar: user.avatar,
|
||||
public_flags: user.public_flags
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return res.json(bansObj);
|
||||
});
|
||||
|
||||
router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { emitEvent, getPermission, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util";
|
||||
import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { route } from "@fosscord/api";
|
||||
import "missing-native-js-functions";
|
||||
@@ -37,9 +37,17 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
return res.send(guild);
|
||||
});
|
||||
|
||||
router.patch("/", route({ body: "GuildUpdateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||
router.patch("/", route({ body: "GuildUpdateSchema"}), async (req: Request, res: Response) => {
|
||||
const body = req.body as GuildUpdateSchema;
|
||||
const { guild_id } = req.params;
|
||||
|
||||
|
||||
const rights = await getRights(req.user_id);
|
||||
const permission = await getPermission(req.user_id, guild_id);
|
||||
|
||||
if (!rights.has("MANAGE_GUILDS")||!permission.has("MANAGE_GUILD"))
|
||||
throw DiscordApiErrors.MISSING_PERMISSIONS.withParams("MANAGE_GUILD");
|
||||
|
||||
// TODO: guild update check image
|
||||
|
||||
if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon);
|
||||
|
||||
@@ -25,13 +25,19 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re
|
||||
|
||||
const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] });
|
||||
const permission = await getPermission(req.user_id, guild_id);
|
||||
const everyone = await Role.findOneOrFail({ guild_id: guild_id, name: "@everyone", position: 0 });
|
||||
|
||||
if (body.roles) {
|
||||
permission.hasThrow("MANAGE_ROLES");
|
||||
|
||||
if (body.roles.indexOf(everyone.id) === -1) body.roles.push(everyone.id);
|
||||
member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist
|
||||
}
|
||||
|
||||
await member.save();
|
||||
|
||||
member.roles = member.roles.filter((x) => x.id !== everyone.id);
|
||||
|
||||
// do not use promise.all as we have to first write to db before emitting the event to catch errors
|
||||
await emitEvent({
|
||||
event: "GUILD_MEMBER_UPDATE",
|
||||
|
||||
@@ -9,11 +9,19 @@ 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({ id: guild_id });
|
||||
|
||||
const invite = await Invite.findOne({ where: { guild_id: guild_id, vanity_url: true } });
|
||||
if (!invite) return res.json({ code: null });
|
||||
if (!guild.features.includes("ALIASABLE_NAMES")) {
|
||||
const invite = await Invite.findOne({ where: { guild_id: guild_id, vanity_url: true } });
|
||||
if (!invite) return res.json({ code: null });
|
||||
|
||||
return res.json({ code: invite.code, uses: invite.uses });
|
||||
return res.json({ code: invite.code, uses: invite.uses });
|
||||
} else {
|
||||
const invite = await Invite.find({ where: { guild_id: guild_id, vanity_url: true } });
|
||||
if (!invite || invite.length == 0) return res.json({ code: null });
|
||||
|
||||
return res.json(invite.map((x) => ({ code: x.code, uses: x.uses })));
|
||||
}
|
||||
});
|
||||
|
||||
export interface VanityUrlSchema {
|
||||
@@ -24,18 +32,33 @@ export interface VanityUrlSchema {
|
||||
code?: string;
|
||||
}
|
||||
|
||||
// TODO: check if guild is elgible for vanity url
|
||||
router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
const body = req.body as VanityUrlSchema;
|
||||
const code = body.code?.replace(InviteRegex, "");
|
||||
|
||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||
if (!guild.features.includes("VANITY_URL")) throw new HTTPError("Your guild doesn't support vanity urls");
|
||||
|
||||
if (!code || code.length === 0) throw new HTTPError("Code cannot be null or empty");
|
||||
|
||||
const invite = await Invite.findOne({ code });
|
||||
if (invite) throw new HTTPError("Invite already exists");
|
||||
|
||||
const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
|
||||
|
||||
await Invite.update({ vanity_url: true, guild_id }, { code: code, channel_id: id });
|
||||
await new Invite({
|
||||
vanity_url: true,
|
||||
code: code,
|
||||
temporary: false,
|
||||
uses: 0,
|
||||
max_uses: 0,
|
||||
max_age: 0,
|
||||
created_at: new Date(),
|
||||
expires_at: new Date(),
|
||||
guild_id: guild_id,
|
||||
channel_id: id
|
||||
}).save();
|
||||
|
||||
return res.json({ code: code });
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { Role, Guild, Snowflake, Config, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util";
|
||||
import { Role, Guild, Snowflake, Config, getRights, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util";
|
||||
import { route } from "@fosscord/api";
|
||||
import { ChannelModifySchema } from "../channels/#channel_id";
|
||||
|
||||
@@ -20,12 +20,13 @@ export interface GuildCreateSchema {
|
||||
|
||||
//TODO: create default channel
|
||||
|
||||
router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: Response) => {
|
||||
router.post("/", route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }), async (req: Request, res: Response) => {
|
||||
const body = req.body as GuildCreateSchema;
|
||||
|
||||
const { maxGuilds } = Config.get().limits.user;
|
||||
const guild_count = await Member.count({ id: req.user_id });
|
||||
if (guild_count >= maxGuilds) {
|
||||
const rights = await getRights(req.user_id);
|
||||
if ((guild_count >= maxGuilds)&&!rights.has("MANAGE_GUILDS")) {
|
||||
throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
|
||||
res.status(200).send(invite);
|
||||
});
|
||||
|
||||
router.post("/:code", route({}), async (req: Request, res: Response) => {
|
||||
router.post("/:code", route({right: "JOIN_GUILDS"}), async (req: Request, res: Response) => {
|
||||
const { code } = req.params;
|
||||
const { guild_id } = await Invite.findOneOrFail({ code })
|
||||
const { features } = await Guild.findOneOrFail({ id: guild_id});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
const router = Router();
|
||||
|
||||
router.get("/scheduled-maintenances/upcoming.json",route({}), async (req: Request, res: Response) => {
|
||||
res.json({
|
||||
"page": {},
|
||||
"scheduled_maintenances": {}
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -18,7 +18,7 @@ router.get("/:id", route({}), async (req: Request, res: Response) => {
|
||||
access_type: 2,
|
||||
name: "",
|
||||
features: [],
|
||||
relase_date: "",
|
||||
release_date: "",
|
||||
premium: false,
|
||||
slug: "",
|
||||
flags: 4,
|
||||
|
||||
@@ -18,7 +18,7 @@ router.get("/:id", route({}), async (req: Request, res: Response) => {
|
||||
access_type: 2,
|
||||
name: "",
|
||||
features: [],
|
||||
relase_date: "",
|
||||
release_date: "",
|
||||
premium: false,
|
||||
slug: "",
|
||||
flags: 4,
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { Router, Response, Request } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { Config, Relase } from "@fosscord/util";
|
||||
import { Config, Release } from "@fosscord/util";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||
const { client } = Config.get();
|
||||
|
||||
const relase = await Relase.findOneOrFail({ name: client.relases.upstreamVersion})
|
||||
const release = await Release.findOneOrFail({ name: client.releases.upstreamVersion})
|
||||
|
||||
res.json({
|
||||
name: relase.name,
|
||||
pub_date: relase.pub_date,
|
||||
url: relase.url,
|
||||
notes: relase.notes
|
||||
name: release.name,
|
||||
pub_date: release.pub_date,
|
||||
url: release.url,
|
||||
notes: release.notes
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -53,8 +53,6 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
|
||||
throw FieldErrors({ email: { message: req.t("auth:register.EMAIL_INVALID"), code: "EMAIL_INVALID" } });
|
||||
}
|
||||
|
||||
user.assign(body);
|
||||
|
||||
if (body.new_password) {
|
||||
if (!body.password && !user.email) {
|
||||
throw FieldErrors({
|
||||
@@ -64,14 +62,16 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
|
||||
user.data.hash = await bcrypt.hash(body.new_password, 12);
|
||||
}
|
||||
|
||||
var check_username = body?.username?.replace(/\s/g, '');
|
||||
|
||||
if(!check_username && !body?.avatar && !body?.banner) {
|
||||
throw FieldErrors({
|
||||
username: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
||||
});
|
||||
if (body.username) {
|
||||
var check_username = body?.username?.replace(/\s/g, '');
|
||||
if (!check_username) {
|
||||
throw FieldErrors({
|
||||
username: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
user.assign(body);
|
||||
await user.save();
|
||||
|
||||
// @ts-ignore
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { User, emitEvent } from "@fosscord/util";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
router.get("/:id", route({}), async (req: Request, res: Response) => {
|
||||
const { id } = req.params;
|
||||
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["notes"] });
|
||||
|
||||
const note = user.notes[id];
|
||||
return res.json({
|
||||
note: note,
|
||||
note_user_id: id,
|
||||
user_id: user.id,
|
||||
});
|
||||
});
|
||||
|
||||
router.put("/:id", route({}), async (req: Request, res: Response) => {
|
||||
//TODO
|
||||
res.json({
|
||||
message: "400: Bad Request",
|
||||
code: 0
|
||||
}).status(400);
|
||||
const { id } = req.params;
|
||||
const user = await User.findOneOrFail({ where: { id: req.user_id } });
|
||||
const noteUser = await User.findOneOrFail({ where: { id: id }}); //if noted user does not exist throw
|
||||
const { note } = req.body;
|
||||
|
||||
await User.update({ id: req.user_id }, { notes: { ...user.notes, [noteUser.id]: note } });
|
||||
|
||||
await emitEvent({
|
||||
event: "USER_NOTE_UPDATE",
|
||||
data: {
|
||||
note: note,
|
||||
id: noteUser.id
|
||||
},
|
||||
user_id: user.id,
|
||||
})
|
||||
|
||||
return res.status(204);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
MessageCreateEvent,
|
||||
MessageUpdateEvent,
|
||||
getPermission,
|
||||
getRights,
|
||||
CHANNEL_MENTION,
|
||||
Snowflake,
|
||||
USER_MENTION,
|
||||
@@ -61,19 +62,20 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
throw new HTTPError("Content length over max character limit")
|
||||
}
|
||||
|
||||
// TODO: are tts messages allowed in dm channels? should permission be checked?
|
||||
if (opts.author_id) {
|
||||
message.author = await User.getPublicUser(opts.author_id);
|
||||
}
|
||||
const rights = await getRights(opts.author_id);
|
||||
rights.hasThrow("SEND_MESSAGES");
|
||||
}
|
||||
if (opts.application_id) {
|
||||
message.application = await Application.findOneOrFail({ id: opts.application_id });
|
||||
}
|
||||
if (opts.webhook_id) {
|
||||
message.webhook = await Webhook.findOneOrFail({ id: opts.webhook_id });
|
||||
}
|
||||
|
||||
|
||||
const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id);
|
||||
permission.hasThrow("SEND_MESSAGES"); // TODO: add the rights check
|
||||
permission.hasThrow("SEND_MESSAGES");
|
||||
if (permission.cache.member) {
|
||||
message.member = permission.cache.member;
|
||||
}
|
||||
@@ -81,13 +83,15 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
if (opts.tts) permission.hasThrow("SEND_TTS_MESSAGES");
|
||||
if (opts.message_reference) {
|
||||
permission.hasThrow("READ_MESSAGE_HISTORY");
|
||||
// code below has to be redone when we add custom message routing and cross-channel replies
|
||||
const guild = await Guild.findOneOrFail({ id: channel.guild_id });
|
||||
if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
|
||||
if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError("You can only reference messages from this guild");
|
||||
if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel");
|
||||
// code below has to be redone when we add custom message routing
|
||||
if (message.guild_id !== null) {
|
||||
const guild = await Guild.findOneOrFail({ id: channel.guild_id });
|
||||
if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
|
||||
if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError("You can only reference messages from this guild");
|
||||
if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel");
|
||||
}
|
||||
}
|
||||
// TODO: should be checked if the referenced message exists?
|
||||
// Q: should be checked if the referenced message exists? ANSWER: NO
|
||||
// @ts-ignore
|
||||
message.type = MessageType.REPLY;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored
|
||||
* - min <n> numbers
|
||||
* - min <n> symbols
|
||||
* - min <n> uppercase chars
|
||||
* - shannon entropy divided by password entropy
|
||||
*
|
||||
* Returns: 0 > pw > 1
|
||||
*/
|
||||
@@ -22,28 +23,38 @@ export function checkPassword(password: string): number {
|
||||
|
||||
// checks for total password len
|
||||
if (password.length >= minLength - 1) {
|
||||
strength += 0.25;
|
||||
strength += 0.05;
|
||||
}
|
||||
|
||||
// checks for amount of Numbers
|
||||
if (password.count(reNUMBER) >= minNumbers - 1) {
|
||||
strength += 0.25;
|
||||
strength += 0.05;
|
||||
}
|
||||
|
||||
// checks for amount of Uppercase Letters
|
||||
if (password.count(reUPPERCASELETTER) >= minUpperCase - 1) {
|
||||
strength += 0.25;
|
||||
strength += 0.05;
|
||||
}
|
||||
|
||||
// checks for amount of symbols
|
||||
if (password.replace(reSYMBOLS, "").length >= minSymbols - 1) {
|
||||
strength += 0.25;
|
||||
strength += 0.05;
|
||||
}
|
||||
|
||||
// checks if password only consists of numbers or only consists of chars
|
||||
if (password.length == password.count(reNUMBER) || password.length === password.count(reUPPERCASELETTER)) {
|
||||
strength = 0;
|
||||
}
|
||||
|
||||
|
||||
let entropyMap;
|
||||
for (let i = 0; i < password.length; i++) {
|
||||
if (entropyMap[password[i]]) entropyMap[password[i]]++;
|
||||
else entropyMap[password[i]] = 1;
|
||||
}
|
||||
|
||||
let entropies = Array(entropyMap);
|
||||
|
||||
entropies.map(x => (x / entropyMap.length));
|
||||
strength += entropies.reduceRight((a, x), a - (x * Math.log2(x))) / Math.log2(password.length);
|
||||
return strength;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user