返回提交历史
Modified
src/routes/webui.ts
+37
-24
XFEstudio/SpaceNinjaServer
chore: avoid using sendFile as it may spontaneously fail (#2977)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2977 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
38326fc4
代码差异
1 个文件
+37
-24
@@ -1,5 +1,6 @@
1
1
import express from "express";
2
2
import path from "path";
3
import fs from "fs/promises";
3
4
import { repoDir, rootDir } from "../helpers/pathHelper.ts";
4
5
import { args } from "../helpers/commandLineArguments.ts";
5
6
@@ -21,50 +22,62 @@ webuiRouter.use("/webui", (req, res, next) => {
21
22
});
22
23
23
24
// Serve virtual routes
24
webuiRouter.get("/webui/inventory", (_req, res) => {
25
res.sendFile(path.join(baseDir, "static/webui/index.html"));
25
webuiRouter.get("/webui/inventory", async (_req, res) => {
26
res.set("Content-Type", "text/html;charset=utf8");
27
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
26
28
});
27
webuiRouter.get("/webui/detailedView", (_req, res) => {
28
res.sendFile(path.join(baseDir, "static/webui/index.html"));
29
webuiRouter.get("/webui/detailedView", async (_req, res) => {
30
res.set("Content-Type", "text/html;charset=utf8");
31
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
29
32
});
30
webuiRouter.get("/webui/mods", (_req, res) => {
31
res.sendFile(path.join(baseDir, "static/webui/index.html"));
33
webuiRouter.get("/webui/mods", async (_req, res) => {
34
res.set("Content-Type", "text/html;charset=utf8");
35
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
32
36
});
33
webuiRouter.get("/webui/settings", (_req, res) => {
34
res.sendFile(path.join(baseDir, "static/webui/index.html"));
37
webuiRouter.get("/webui/settings", async (_req, res) => {
38
res.set("Content-Type", "text/html;charset=utf8");
39
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
35
40
});
36
webuiRouter.get("/webui/quests", (_req, res) => {
37
res.sendFile(path.join(baseDir, "static/webui/index.html"));
41
webuiRouter.get("/webui/quests", async (_req, res) => {
42
res.set("Content-Type", "text/html;charset=utf8");
43
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
38
44
});
39
webuiRouter.get("/webui/cheats", (_req, res) => {
40
res.sendFile(path.join(baseDir, "static/webui/index.html"));
45
webuiRouter.get("/webui/cheats", async (_req, res) => {
46
res.set("Content-Type", "text/html;charset=utf8");
47
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
41
48
});
42
webuiRouter.get("/webui/import", (_req, res) => {
43
res.sendFile(path.join(baseDir, "static/webui/index.html"));
49
webuiRouter.get("/webui/import", async (_req, res) => {
50
res.set("Content-Type", "text/html;charset=utf8");
51
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
44
52
});
45
webuiRouter.get("/webui/guildView", (_req, res) => {
46
res.sendFile(path.join(baseDir, "static/webui/index.html"));
53
webuiRouter.get("/webui/guildView", async (_req, res) => {
54
res.set("Content-Type", "text/html;charset=utf8");
55
res.send(await fs.readFile(path.join(baseDir, "static/webui/index.html")));
47
56
});
48
57
49
58
// Serve static files
50
59
webuiRouter.use("/webui", express.static(path.join(baseDir, "static/webui")));
51
60
52
61
// Serve favicon
53
webuiRouter.get("/favicon.ico", (_req, res) => {
54
res.sendFile(path.join(repoDir, "static/fixed_responses/favicon.ico"));
62
webuiRouter.get("/favicon.ico", async (_req, res) => {
63
res.set("Content-Type", "image/vnd.microsoft.icon");
64
res.send(await fs.readFile(path.join(repoDir, "static/fixed_responses/favicon.ico")));
55
65
});
56
66
57
67
// Serve warframe-riven-info
58
webuiRouter.get("/webui/riven-tool/", (_req, res) => {
59
res.sendFile(path.join(repoDir, "node_modules/warframe-riven-info/index.html"));
68
webuiRouter.get("/webui/riven-tool/", async (_req, res) => {
69
res.set("Content-Type", "text/html;charset=utf8");
70
res.send(await fs.readFile(path.join(repoDir, "node_modules/warframe-riven-info/index.html")));
60
71
});
61
webuiRouter.get("/webui/riven-tool/RivenParser.js", (_req, res) => {
62
res.sendFile(path.join(repoDir, "node_modules/warframe-riven-info/RivenParser.js"));
72
webuiRouter.get("/webui/riven-tool/RivenParser.js", async (_req, res) => {
73
res.set("Content-Type", "text/javascript;charset=utf8");
74
res.send(await fs.readFile(path.join(repoDir, "node_modules/warframe-riven-info/RivenParser.js")));
63
75
});
64
76
65
77
// Serve translations
66
webuiRouter.get("/translations/:file", (req, res) => {
67
res.sendFile(path.join(baseDir, `static/webui/translations/${req.params.file}`));
78
webuiRouter.get("/translations/:file", async (req, res) => {
79
res.set("Content-Type", "text/javascript;charset=utf8");
80
res.send(await fs.readFile(path.join(baseDir, `static/webui/translations/${req.params.file}`)));
68
81
});
69
82
70
83
export { webuiRouter };