Merge branch 'master' into slowcord
This commit is contained in:
@@ -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"] });
|
||||
|
||||
@@ -4,8 +4,9 @@ import { route } from "@fosscord/api";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// TODO: check if message exists
|
||||
// TODO: public read receipts & privacy scoping
|
||||
// TODO: send read state event to all channel members
|
||||
// TODO: advance-only notification cursor
|
||||
|
||||
export interface MessageAcknowledgeSchema {
|
||||
manual?: boolean;
|
||||
|
||||
@@ -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,32 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
|
||||
return res.json(message);
|
||||
});
|
||||
|
||||
// permission check only if deletes messagr from other user
|
||||
router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
|
||||
const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] });
|
||||
|
||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
||||
|
||||
if (message.author_id !== req.user_id) permissions.hasThrow("READ_MESSAGE_HISTORY");
|
||||
|
||||
return res.json(message);
|
||||
});
|
||||
|
||||
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 });
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ router.get("/:emoji", route({ permission: "VIEW_CHANNEL" }), async (req: Request
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY" }), async (req: Request, res: Response) => {
|
||||
router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY", right: "SELF_ADD_REACTIONS" }), async (req: Request, res: Response) => {
|
||||
const { message_id, channel_id, user_id } = req.params;
|
||||
if (user_id !== "@me") throw new HTTPError("Invalid user");
|
||||
const emoji = getEmoji(req.params.emoji);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Embed,
|
||||
emitEvent,
|
||||
getPermission,
|
||||
getRights,
|
||||
Message,
|
||||
MessageCreateEvent,
|
||||
uploadFile,
|
||||
@@ -119,7 +120,7 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
delete x.user_ids;
|
||||
});
|
||||
// @ts-ignore
|
||||
if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: "0", avatar: null };
|
||||
if (!x.author) x.author = { id: "4", discriminator: "0000", username: "Fosscord Ghost", public_flags: "0", avatar: null };
|
||||
x.attachments?.forEach((y: any) => {
|
||||
// dynamically set attachment proxy_url in case the endpoint changed
|
||||
const uri = y.proxy_url.startsWith("http") ? y.proxy_url : `https://example.org${y.proxy_url}`;
|
||||
@@ -149,7 +150,7 @@ const messageUpload = multer({
|
||||
}); // max upload 50 mb
|
||||
|
||||
// TODO: dynamically change limit of MessageCreateSchema with config
|
||||
// TODO: check: sum of all characters in an embed structure must not exceed 6000 characters
|
||||
// TODO: check: sum of all characters in an embed structure must not exceed instance limits
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#create-message
|
||||
// TODO: text channel slowdown
|
||||
@@ -167,7 +168,7 @@ router.post(
|
||||
|
||||
next();
|
||||
},
|
||||
route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }),
|
||||
route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES", right: "SEND_MESSAGES" }),
|
||||
async (req: Request, res: Response) => {
|
||||
const { channel_id } = req.params;
|
||||
var body = req.body as MessageCreateSchema;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,7 +6,6 @@ import { HTTPError } from "lambert-server";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// TODO: not allowed for user -> only allowed for bots with privileged intents
|
||||
// TODO: send over websocket
|
||||
// TODO: check for GUILD_MEMBERS intent
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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: "Unknown User",
|
||||
code: 10013
|
||||
}).status(404);
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user