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";
|
2024-05-30 01:44:54 +02:00
|
|
|
import fs from "fs/promises";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
|
|
|
const cacheRouter = express.Router();
|
|
|
|
|
2024-12-20 03:11:09 +01:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2024-05-30 01:44:54 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-19 15:22:48 -03:00
|
|
|
export { cacheRouter };
|