32 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-05-19 15:22:48 -03:00
import express from "express";
2024-05-15 21:55:59 +02:00
import buildConfig from "@/static/data/buildConfig.json";
import fs from "fs/promises";
2023-05-19 15:22:48 -03:00
const cacheRouter = express.Router();
cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (req, res) => {
if (typeof req.query.version == "string" && req.query.version.match(/^\d\d\d\d\.\d\d\.\d\d\.\d\d\.\d\d$/)) {
res.sendFile(`static/data/H.Cache_${req.query.version}.bin`, { root: "./" });
} else {
res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" });
}
2023-05-19 15:22:48 -03:00
});
cacheRouter.get(/^\/0\/Lotus\/.+!.+$/, 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();
}
});
2023-05-19 15:22:48 -03:00
export { cacheRouter };