add explicit types to req and res

This commit is contained in:
Flam3rboy 2021-05-31 21:01:28 +02:00
parent f0d59bb37d
commit e4fc61dc34
3 changed files with 11 additions and 11 deletions

View File

@ -1,4 +1,4 @@
import { Router } from "express"; import { Router, Response, Request } from "express";
import { Config, Snowflake } from "@fosscord/server-util"; import { Config, Snowflake } from "@fosscord/server-util";
import { storage } from "../util/Storage"; import { storage } from "../util/Storage";
import FileType from "file-type"; import FileType from "file-type";
@ -8,7 +8,7 @@ import imageSize from "image-size";
const router = Router(); const router = Router();
router.post("/:channel_id", multer.single("file"), async (req, res) => { router.post("/:channel_id", multer.single("file"), async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature"); throw new HTTPError("Invalid request signature");
@ -44,7 +44,7 @@ router.post("/:channel_id", multer.single("file"), async (req, res) => {
return res.json(file); return res.json(file);
}); });
router.get("/:channel_id/:id/:filename", async (req, res) => { router.get("/:channel_id/:id/:filename", async (req: Request, res: Response) => {
const { channel_id, id, filename } = req.params; const { channel_id, id, filename } = req.params;
const file = await storage.get(`attachments/${channel_id}/${id}/${filename}`); const file = await storage.get(`attachments/${channel_id}/${id}/${filename}`);
@ -56,7 +56,7 @@ router.get("/:channel_id/:id/:filename", async (req, res) => {
return res.send(file); return res.send(file);
}); });
router.delete("/:channel_id/:id/:filename", async (req, res) => { router.delete("/:channel_id/:id/:filename", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature"); throw new HTTPError("Invalid request signature");

View File

@ -1,4 +1,4 @@
import { Router } from "express"; import { Router, Response, Request } from "express";
import { Config, Snowflake } from "@fosscord/server-util"; import { Config, Snowflake } from "@fosscord/server-util";
import { storage } from "../util/Storage"; import { storage } from "../util/Storage";
import FileType from "file-type"; import FileType from "file-type";
@ -18,7 +18,7 @@ const ALLOWED_MIME_TYPES = [...ANIMATED_MIME_TYPES, ...STATIC_MIME_TYPES];
const router = Router(); const router = Router();
router.post("/:user_id", multer.single("file"), async (req, res) => { router.post("/:user_id", multer.single("file"), async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature"); throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file"); if (!req.file) throw new HTTPError("Missing file");
@ -42,7 +42,7 @@ router.post("/:user_id", multer.single("file"), async (req, res) => {
}); });
}); });
router.get("/:user_id/:id", async (req, res) => { router.get("/:user_id/:id", async (req: Request, res: Response) => {
var { user_id, id } = req.params; var { user_id, id } = req.params;
id = id.split(".")[0]; id = id.split(".")[0];
const path = `avatars/${user_id}/${id}`; const path = `avatars/${user_id}/${id}`;
@ -56,7 +56,7 @@ router.get("/:user_id/:id", async (req, res) => {
return res.send(file); return res.send(file);
}); });
router.delete("/:user_id/:id", async (req, res) => { router.delete("/:user_id/:id", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature"); throw new HTTPError("Invalid request signature");
const { user_id, id } = req.params; const { user_id, id } = req.params;

View File

@ -1,6 +1,6 @@
// @ts-nocheck // @ts-nocheck
import bodyParser from "body-parser"; import bodyParser from "body-parser";
import { Router } from "express"; import { Router, Response, Request } from "express";
import fetch from "node-fetch"; import fetch from "node-fetch";
import crypto from "crypto"; import crypto from "crypto";
import { HTTPError } from "lambert-server"; import { HTTPError } from "lambert-server";
@ -29,7 +29,7 @@ const DEFAULT_FETCH_OPTIONS: any = {
method: "GET", method: "GET",
}; };
router.post("/", bodyParser.json(), async (req, res) => { router.post("/", bodyParser.json(), async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) if (req.headers.signature !== Config.get().security.requestSignature)
throw new HTTPError("Invalid request signature"); throw new HTTPError("Invalid request signature");
if (!req.body) throw new HTTPError("Invalid Body"); if (!req.body) throw new HTTPError("Invalid Body");
@ -50,7 +50,7 @@ router.post("/", bodyParser.json(), async (req, res) => {
} }
}); });
router.get("/:id/", async (req, res) => { router.get("/:id/", async (req: Request, res: Response) => {
const { id } = req.params; const { id } = req.params;
const file = await storage.get(`/external/${id}`); const file = await storage.get(`/external/${id}`);