返回提交历史
Modified
src/routes/cache.ts
+17
-0
XFEstudio/SpaceNinjaServer
feat: implement loading of ability videos (#205)
02e4562d
代码差异
1 个文件
+17
-0
@@ -1,5 +1,6 @@
1
1
import express from "express";
2
2
import buildConfig from "@/static/data/buildConfig.json";
3
import fs from "fs/promises";
3
4
4
5
const cacheRouter = express.Router();
5
6
@@ -15,4 +16,20 @@ cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res)
15
16
res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" });
16
17
});
17
18
19
cacheRouter.get(/\.bk2!/, async (req, res) => {
20
try {
21
const dir = req.path.substr(0, req.path.lastIndexOf("/"));
22
const file = req.path.substr(dir.length + 1);
23
const filePath = `static/data${dir}/${file}`;
24
25
// Return file if we have it
26
await fs.access(filePath);
27
const data = await fs.readFile(filePath, null);
28
res.send(data);
29
} catch (err) {
30
// 404 if we don't
31
res.status(404).end();
32
}
33
});
34
18
35
export { cacheRouter };