feat: implement loading of ability videos (#205)

This commit is contained in:
Sainan 2024-05-30 01:44:54 +02:00 committed by GitHub
parent cfcdaae668
commit 02e4562daa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import express from "express"; import express from "express";
import buildConfig from "@/static/data/buildConfig.json"; import buildConfig from "@/static/data/buildConfig.json";
import fs from "fs/promises";
const cacheRouter = express.Router(); const cacheRouter = express.Router();
@ -15,4 +16,20 @@ cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res)
res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" }); res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" });
}); });
cacheRouter.get(/\.bk2!/, async (req, res) => {
try {
const dir = req.path.substr(0, req.path.lastIndexOf("/"));
const file = req.path.substr(dir.length + 1);
const filePath = `static/data${dir}/${file}`;
// Return file if we have it
await fs.access(filePath);
const data = await fs.readFile(filePath, null);
res.send(data);
} catch (err) {
// 404 if we don't
res.status(404).end();
}
});
export { cacheRouter }; export { cacheRouter };