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();
|
|
|
|
|
2023-08-05 22:48:56 +02:00
|
|
|
cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res) => {
|
2024-05-15 21:55:59 +02:00
|
|
|
res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" });
|
2023-05-19 15:22:48 -03:00
|
|
|
});
|
|
|
|
|
2024-06-20 11:47:21 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
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 };
|