Sainan 9c55a8a4aa
All checks were successful
Build Docker image / docker-amd64 (push) Successful in 47s
Build Docker image / docker-arm64 (push) Successful in 1m4s
Build / build (push) Successful in 1m55s
chore: enable no-deprecated warning (#2762)
Reviewed-on: #2762
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-09-08 20:43:31 -07:00

32 lines
1.0 KiB
TypeScript

import express from "express";
import { buildConfig } from "../services/buildConfigService.ts";
import fs from "fs/promises";
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: "./" });
}
});
cacheRouter.get(/^\/0\/.+!.+$/, async (req, res) => {
try {
const dir = req.path.substring(0, req.path.lastIndexOf("/"));
const file = req.path.substring(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 };