This repository was archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmod.ts
More file actions
66 lines (56 loc) · 1.76 KB
/
mod.ts
File metadata and controls
66 lines (56 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as express from "express";
import { catchErrors } from "../modules/Utils";
import ModService from "./modules/ModService";
import multer from "multer";
const storage = multer.memoryStorage();
const upload = multer({ limits: { fileSize: 75 * 1024 * 1024 }, storage });
const router = express.Router();
router.get(
"/",
catchErrors(async (req, res, next) => {
const modService = new ModService(req.ctx);
let pgp = false;
if (req.query.hasOwnProperty("pgp")) {
res.set("Content-Type", "text/plain");
pgp = true;
}
return res.send(await modService.list(req.query, pgp));
})
);
router.post(
"/create",
upload.array("file"),
catchErrors(async (req, res, next) => {
const files = ("files" in req && req.files ? req.files : []) as Express.Multer.File[];
const modService = new ModService(req.ctx);
const user = await modService.create(
req.ctx.user,
req.body.name || "",
req.body.description || "",
req.body.version || "",
req.body.gameVersion || "",
req.body.dependencies || "",
req.body.category || "",
req.body.link || "",
files
);
return res.send(user);
})
);
router.get(
"/:_id",
catchErrors(async (req, res, next) => {
const modService = new ModService(req.ctx);
const mod = await modService.get(req.params._id);
return res.send(mod);
})
);
router.post(
"/:_id",
catchErrors(async (req, res, next) => {
const modService = new ModService(req.ctx);
const mod = await modService.update({ ...req.body, _id: req.params._id });
return res.send(mod);
})
);
export default router;