mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
⚡ add explicit types to req and res
This commit is contained in:
parent
536900d255
commit
491565aef8
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,7 +9,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fosscord/server-util": "^1.3.15",
|
"@fosscord/server-util": "^1.3.16",
|
||||||
"@types/jest": "^26.0.22",
|
"@types/jest": "^26.0.22",
|
||||||
"@types/json-schema": "^7.0.7",
|
"@types/json-schema": "^7.0.7",
|
||||||
"ajv": "^8.4.0",
|
"ajv": "^8.4.0",
|
||||||
@ -520,9 +520,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@fosscord/server-util": {
|
"node_modules/@fosscord/server-util": {
|
||||||
"version": "1.3.15",
|
"version": "1.3.16",
|
||||||
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.15.tgz",
|
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.16.tgz",
|
||||||
"integrity": "sha512-PCSOYOUiEzpdcUoyBSCHqOB72b+xdNuYStEuvvxLJt6MV6id4GA18DvD79Hw7F38F4gm/PIK6di+GnHWMd3Prw==",
|
"integrity": "sha512-/oDDGyWllVNMb/84wzzYQ6vpwkcW+mg57ECWS5bUDQ0OhT3apdpYgQFfWxwGYgyYo6fB4gmyJh/U2bzWo6Jmeg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/jsonwebtoken": "^8.5.0",
|
"@types/jsonwebtoken": "^8.5.0",
|
||||||
"@types/mongoose-autopopulate": "^0.10.1",
|
"@types/mongoose-autopopulate": "^0.10.1",
|
||||||
@ -12864,9 +12864,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@fosscord/server-util": {
|
"@fosscord/server-util": {
|
||||||
"version": "1.3.15",
|
"version": "1.3.16",
|
||||||
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.15.tgz",
|
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.16.tgz",
|
||||||
"integrity": "sha512-PCSOYOUiEzpdcUoyBSCHqOB72b+xdNuYStEuvvxLJt6MV6id4GA18DvD79Hw7F38F4gm/PIK6di+GnHWMd3Prw==",
|
"integrity": "sha512-/oDDGyWllVNMb/84wzzYQ6vpwkcW+mg57ECWS5bUDQ0OhT3apdpYgQFfWxwGYgyYo6fB4gmyJh/U2bzWo6Jmeg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/jsonwebtoken": "^8.5.0",
|
"@types/jsonwebtoken": "^8.5.0",
|
||||||
"@types/mongoose-autopopulate": "^0.10.1",
|
"@types/mongoose-autopopulate": "^0.10.1",
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/fosscord/fosscord-api#readme",
|
"homepage": "https://github.com/fosscord/fosscord-api#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fosscord/server-util": "^1.3.15",
|
"@fosscord/server-util": "^1.3.16",
|
||||||
"@types/jest": "^26.0.22",
|
"@types/jest": "^26.0.22",
|
||||||
"@types/json-schema": "^7.0.7",
|
"@types/json-schema": "^7.0.7",
|
||||||
"ajv": "^8.4.0",
|
"ajv": "^8.4.0",
|
||||||
|
@ -9,8 +9,8 @@ import i18nextMiddleware, { I18next } from "i18next-http-middleware";
|
|||||||
import i18nextBackend from "i18next-node-fs-backend";
|
import i18nextBackend from "i18next-node-fs-backend";
|
||||||
import { ErrorHandler } from "./middlewares/ErrorHandler";
|
import { ErrorHandler } from "./middlewares/ErrorHandler";
|
||||||
import { BodyParser } from "./middlewares/BodyParser";
|
import { BodyParser } from "./middlewares/BodyParser";
|
||||||
import express, { Router } from "express";
|
import express, { Router, Request, Response } from "express";
|
||||||
import fetch, { Response } from "node-fetch";
|
import fetch, { Response as FetchResponse } from "node-fetch";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
@ -31,13 +31,13 @@ declare global {
|
|||||||
const assetCache = new Map<
|
const assetCache = new Map<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
response: Response;
|
response: FetchResponse;
|
||||||
buffer: Buffer;
|
buffer: Buffer;
|
||||||
}
|
}
|
||||||
>();
|
>();
|
||||||
|
|
||||||
export class FosscordServer extends Server {
|
export class FosscordServer extends Server {
|
||||||
public options: FosscordServerOptions;
|
public declare options: FosscordServerOptions;
|
||||||
|
|
||||||
constructor(opts?: Partial<FosscordServerOptions>) {
|
constructor(opts?: Partial<FosscordServerOptions>) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -101,9 +101,9 @@ export class FosscordServer extends Server {
|
|||||||
|
|
||||||
this.app.use("/assets", express.static(path.join(__dirname, "..", "assets")));
|
this.app.use("/assets", express.static(path.join(__dirname, "..", "assets")));
|
||||||
|
|
||||||
this.app.get("/assets/:file", async (req, res) => {
|
this.app.get("/assets/:file", async (req: Request, res: Response) => {
|
||||||
delete req.headers.host;
|
delete req.headers.host;
|
||||||
var response: Response;
|
var response: FetchResponse;
|
||||||
var buffer: Buffer;
|
var buffer: Buffer;
|
||||||
const cache = assetCache.get(req.params.file);
|
const cache = assetCache.get(req.params.file);
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
@ -140,7 +140,7 @@ export class FosscordServer extends Server {
|
|||||||
|
|
||||||
return res.send(buffer);
|
return res.send(buffer);
|
||||||
});
|
});
|
||||||
this.app.get("*", (req, res) => {
|
this.app.get("*", (req: Request, res: Response) => {
|
||||||
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
|
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
|
||||||
res.set("content-type", "text/html");
|
res.set("content-type", "text/html");
|
||||||
res.send(
|
res.send(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ChannelDeleteEvent, ChannelModel, ChannelUpdateEvent, getPermission, GuildUpdateEvent, toObject } from "@fosscord/server-util";
|
import { ChannelDeleteEvent, ChannelModel, ChannelUpdateEvent, getPermission, GuildUpdateEvent, toObject } from "@fosscord/server-util";
|
||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { ChannelModifySchema } from "../../../schema/Channel";
|
import { ChannelModifySchema } from "../../../schema/Channel";
|
||||||
import { emitEvent } from "../../../util/Event";
|
import { emitEvent } from "../../../util/Event";
|
||||||
@ -8,7 +8,7 @@ const router: Router = Router();
|
|||||||
// TODO: delete channel
|
// TODO: delete channel
|
||||||
// TODO: Get channel
|
// TODO: Get channel
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
||||||
@ -20,7 +20,7 @@ router.get("/", async (req, res) => {
|
|||||||
return res.send(toObject(channel));
|
return res.send(toObject(channel));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/", async (req, res) => {
|
router.delete("/", async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
||||||
@ -39,7 +39,7 @@ router.delete("/", async (req, res) => {
|
|||||||
res.send(data);
|
res.send(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(ChannelModifySchema), async (req, res) => {
|
router.patch("/", check(ChannelModifySchema), async (req: Request, res: Response) => {
|
||||||
var payload = req.body as ChannelModifySchema;
|
var payload = req.body as ChannelModifySchema;
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// router.post("/", (req, res) => {});
|
// router.post("/", (req: Request, res: Response) => {});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ChannelModel, getPermission, MessageDeleteEvent, MessageModel, MessageUpdateEvent, toObject } from "@fosscord/server-util";
|
import { ChannelModel, getPermission, MessageDeleteEvent, MessageModel, MessageUpdateEvent, toObject } from "@fosscord/server-util";
|
||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { MessageCreateSchema } from "../../../../../schema/Message";
|
import { MessageCreateSchema } from "../../../../../schema/Message";
|
||||||
import { emitEvent } from "../../../../../util/Event";
|
import { emitEvent } from "../../../../../util/Event";
|
||||||
@ -8,7 +8,7 @@ import { handleMessage, postHandleMessage } from "../../../../../util/Message";
|
|||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.patch("/", check(MessageCreateSchema), async (req, res) => {
|
router.patch("/", check(MessageCreateSchema), async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ router.patch("/", check(MessageCreateSchema), async (req, res) => {
|
|||||||
|
|
||||||
// TODO: delete attachments in message
|
// TODO: delete attachments in message
|
||||||
|
|
||||||
router.delete("/", async (req, res) => {
|
router.delete("/", async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true });
|
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true });
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
toObject,
|
toObject,
|
||||||
UserModel
|
UserModel
|
||||||
} from "@fosscord/server-util";
|
} from "@fosscord/server-util";
|
||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { emitEvent } from "../../../../../util/Event";
|
import { emitEvent } from "../../../../../util/Event";
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ function getEmoji(emoji: string): PartialEmoji {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
router.delete("/", async (req, res) => {
|
router.delete("/", async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
|
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true }).exec();
|
||||||
@ -61,7 +61,7 @@ router.delete("/", async (req, res) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:emoji", async (req, res) => {
|
router.delete("/:emoji", async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ router.delete("/:emoji", async (req, res) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/:emoji", async (req, res) => {
|
router.get("/:emoji", async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ router.get("/:emoji", async (req, res) => {
|
|||||||
res.json(toObject(users));
|
res.json(toObject(users));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.put("/:emoji/:user_id", async (req, res) => {
|
router.put("/:emoji/:user_id", async (req: Request, res: Response) => {
|
||||||
const { message_id, channel_id, user_id } = req.params;
|
const { message_id, channel_id, user_id } = req.params;
|
||||||
if (user_id !== "@me") throw new HTTPError("Invalid user");
|
if (user_id !== "@me") throw new HTTPError("Invalid user");
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
@ -162,7 +162,7 @@ router.put("/:emoji/:user_id", async (req, res) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:emoji/:user_id", async (req, res) => {
|
router.delete("/:emoji/:user_id", async (req: Request, res: Response) => {
|
||||||
var { message_id, channel_id, user_id } = req.params;
|
var { message_id, channel_id, user_id } = req.params;
|
||||||
|
|
||||||
const emoji = getEmoji(req.params.emoji);
|
const emoji = getEmoji(req.params.emoji);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { ChannelModel, Config, getPermission, MessageDeleteBulkEvent, MessageModel } from "@fosscord/server-util";
|
import { ChannelModel, Config, getPermission, MessageDeleteBulkEvent, MessageModel } from "@fosscord/server-util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { emitEvent } from "../../../../util/Event";
|
import { emitEvent } from "../../../../util/Event";
|
||||||
@ -11,7 +11,7 @@ export default router;
|
|||||||
// TODO: should users be able to bulk delete messages or only bots?
|
// TODO: should users be able to bulk delete messages or only bots?
|
||||||
// TODO: should this request fail, if you provide messages older than 14 days/invalid ids?
|
// TODO: should this request fail, if you provide messages older than 14 days/invalid ids?
|
||||||
// https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
// https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
||||||
router.post("/", check({ messages: [String] }), async (req, res) => {
|
router.post("/", check({ messages: [String] }), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }, { permission_overwrites: true, guild_id: true }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }, { permission_overwrites: true, guild_id: true }).exec();
|
||||||
if (!channel?.guild_id) throw new HTTPError("Can't bulk delete dm channel messages", 400);
|
if (!channel?.guild_id) throw new HTTPError("Can't bulk delete dm channel messages", 400);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { Attachment, ChannelModel, ChannelType, getPermission, MessageDocument, MessageModel, toObject } from "@fosscord/server-util";
|
import { Attachment, ChannelModel, ChannelType, getPermission, MessageDocument, MessageModel, toObject } from "@fosscord/server-util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { MessageCreateSchema } from "../../../../schema/Message";
|
import { MessageCreateSchema } from "../../../../schema/Message";
|
||||||
@ -28,7 +28,7 @@ export function isTextChannel(type: ChannelType): boolean {
|
|||||||
|
|
||||||
// https://discord.com/developers/docs/resources/channel#create-message
|
// https://discord.com/developers/docs/resources/channel#create-message
|
||||||
// get messages
|
// get messages
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
const channel_id = req.params.channel_id;
|
const channel_id = req.params.channel_id;
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true, type: true, permission_overwrites: true }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true, type: true, permission_overwrites: true }).exec();
|
||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
@ -101,7 +101,7 @@ const messageUpload = multer({
|
|||||||
// TODO: trim and replace message content and every embed field
|
// TODO: trim and replace message content and every embed field
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
router.post("/", check(MessageCreateSchema), messageUpload.single("file"), async (req, res) => {
|
router.post("/", check(MessageCreateSchema), messageUpload.single("file"), async (req: Request, res: Response) => {
|
||||||
const { channel_id } = req.params;
|
const { channel_id } = req.params;
|
||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
const attachments: Attachment[] = [];
|
const attachments: Attachment[] = [];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ChannelModel, ChannelPermissionOverwrite, ChannelUpdateEvent, getPermission, MemberModel, RoleModel } from "@fosscord/server-util";
|
import { ChannelModel, ChannelPermissionOverwrite, ChannelUpdateEvent, getPermission, MemberModel, RoleModel } from "@fosscord/server-util";
|
||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { emitEvent } from "../../../util/Event";
|
import { emitEvent } from "../../../util/Event";
|
||||||
import { check } from "../../../util/instanceOf";
|
import { check } from "../../../util/instanceOf";
|
||||||
@ -7,7 +7,7 @@ const router: Router = Router();
|
|||||||
|
|
||||||
// TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel)
|
// TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel)
|
||||||
|
|
||||||
router.put("/:overwrite_id", check({ allow: String, deny: String, type: Number, id: String }), async (req, res) => {
|
router.put("/:overwrite_id", check({ allow: String, deny: String, type: Number, id: String }), async (req: Request, res: Response) => {
|
||||||
const { channel_id, overwrite_id } = req.params;
|
const { channel_id, overwrite_id } = req.params;
|
||||||
const body = req.body as { allow: bigint; deny: bigint; type: number; id: string };
|
const body = req.body as { allow: bigint; deny: bigint; type: number; id: string };
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ router.put("/:overwrite_id", check({ allow: String, deny: String, type: Number,
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO: check permission hierarchy
|
// TODO: check permission hierarchy
|
||||||
router.delete("/:overwrite_id", async (req, res) => {
|
router.delete("/:overwrite_id", async (req: Request, res: Response) => {
|
||||||
const { channel_id, overwrite_id } = req.params;
|
const { channel_id, overwrite_id } = req.params;
|
||||||
|
|
||||||
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
const permissions = await getPermission(req.user_id, undefined, channel_id);
|
||||||
|
@ -53,7 +53,7 @@ router.put("/:message_id", async (req: Request, res: Response) => {
|
|||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:message_id", async (req, res) => {
|
router.delete("/:message_id", async (req: Request, res: Response) => {
|
||||||
const { channel_id, message_id } = req.params;
|
const { channel_id, message_id } = req.params;
|
||||||
|
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }).exec();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { check, Length } from "../../../util/instanceOf";
|
import { check, Length } from "../../../util/instanceOf";
|
||||||
import { ChannelModel, getPermission, trimSpecial } from "@fosscord/server-util";
|
import { ChannelModel, getPermission, trimSpecial } from "@fosscord/server-util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
@ -8,7 +8,7 @@ const router: Router = Router();
|
|||||||
// TODO:
|
// TODO:
|
||||||
|
|
||||||
// TODO: use Image Data Type for avatar instead of String
|
// TODO: use Image Data Type for avatar instead of String
|
||||||
router.post("/", check({ name: new Length(String, 1, 80), $avatar: String }), async (req, res) => {
|
router.post("/", check({ name: new Length(String, 1, 80), $avatar: String }), async (req: Request, res: Response) => {
|
||||||
const channel_id = req.params.channel_id;
|
const channel_id = req.params.channel_id;
|
||||||
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true, type: true }).exec();
|
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true, type: true }).exec();
|
||||||
if (!channel) throw new HTTPError("Channel not found", 404);
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.send({ fingerprint: "", assignments: [] });
|
res.send({ fingerprint: "", assignments: [] });
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Config } from "@fosscord/server-util";
|
import { Config } from "@fosscord/server-util";
|
||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req: Request, res: Response) => {
|
||||||
const { endpoint } = Config.get().gateway;
|
const { endpoint } = Config.get().gateway;
|
||||||
res.send({ url: endpoint || process.env.GATEWAY || "ws://localhost:3002" });
|
res.send({ url: endpoint || process.env.GATEWAY || "ws://localhost:3002" });
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import {
|
import {
|
||||||
ChannelCreateEvent,
|
ChannelCreateEvent,
|
||||||
ChannelModel,
|
ChannelModel,
|
||||||
@ -16,14 +16,14 @@ import { check } from "../../../util/instanceOf";
|
|||||||
import { createChannel } from "../../../util/Channel";
|
import { createChannel } from "../../../util/Channel";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const channels = await ChannelModel.find({ guild_id }).exec();
|
const channels = await ChannelModel.find({ guild_id }).exec();
|
||||||
|
|
||||||
res.json(toObject(channels));
|
res.json(toObject(channels));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check(ChannelModifySchema), async (req, res) => {
|
router.post("/", check(ChannelModifySchema), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as ChannelModifySchema;
|
const body = req.body as ChannelModifySchema;
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ router.post("/", check(ChannelModifySchema), async (req, res) => {
|
|||||||
res.json(channel);
|
res.json(channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(ChannelModifySchema), async (req, res) => {
|
router.patch("/", check(ChannelModifySchema), async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as ChannelModifySchema;
|
const body = req.body as ChannelModifySchema;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
return res.json(toObject(member));
|
return res.json(toObject(member));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.patch("/", check(MemberChangeSchema), async (req, res) => {
|
router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response) => {
|
||||||
const { guild_id, member_id } = req.params;
|
const { guild_id, member_id } = req.params;
|
||||||
const body = req.body as MemberChangeSchema;
|
const body = req.body as MemberChangeSchema;
|
||||||
if (body.roles) {
|
if (body.roles) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", (req, res) => {
|
router.post("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.status(200).send({ guild_affinities: [] });
|
res.status(200).send({ guild_affinities: [] });
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.status(200).send({ user_affinities: [], inverse_user_affinities: [] });
|
res.status(200).send({ user_affinities: [], inverse_user_affinities: [] });
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
res.json(toObject(channels));
|
res.json(toObject(channels));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/", check(DmChannelCreateSchema), async (req, res) => {
|
router.post("/", check(DmChannelCreateSchema), async (req: Request, res: Response) => {
|
||||||
const body = req.body as DmChannelCreateSchema;
|
const body = req.body as DmChannelCreateSchema;
|
||||||
|
|
||||||
body.recipients = body.recipients.filter((x) => x !== req.user_id).unique();
|
body.recipients = body.recipients.filter((x) => x !== req.user_id).unique();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", (req, res) => {
|
router.post("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.status(200).send([]);
|
res.status(200).send([]);
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
RelationshipType,
|
RelationshipType,
|
||||||
RelationshipRemoveEvent
|
RelationshipRemoveEvent
|
||||||
} from "@fosscord/server-util";
|
} from "@fosscord/server-util";
|
||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
import { check, HTTPError } from "lambert-server";
|
import { check, HTTPError } from "lambert-server";
|
||||||
import { emitEvent } from "../../../util/Event";
|
import { emitEvent } from "../../../util/Event";
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ const router = Router();
|
|||||||
|
|
||||||
const userProjection = { "user_data.relationships": true, ...PublicUserProjection };
|
const userProjection = { "user_data.relationships": true, ...PublicUserProjection };
|
||||||
|
|
||||||
router.put("/:id", check({ $type: Number }), async (req, res) => {
|
router.put("/:id", check({ $type: Number }), async (req: Request, res: Response) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend");
|
if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend");
|
||||||
const body = req.body as { type?: number };
|
const body = req.body as { type?: number };
|
||||||
@ -107,7 +107,7 @@ router.put("/:id", check({ $type: Number }), async (req, res) => {
|
|||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete("/:id", async (req, res) => {
|
router.delete("/:id", async (req: Request, res: Response) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend");
|
if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend");
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.patch("/", (req, res) => {
|
router.patch("/", (req: Request, res: Response) => {
|
||||||
// TODO:
|
// TODO:
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user