Some checks failed
Lint / eslint (push) Failing after 1m32s
- Fix proxy.js: use utils/config/service-helpers (correct path for Homepage v1.7.0; utils/service-helpers does not exist) - Fix component.jsx: blank line between external and utils/ imports as required by Homepage ESLint import/order rule - Add .eslintrc.json mirroring Homepage's ESLint config - Add package.json with ESLint dev dependencies - Add Forgejo Actions workflow to lint on push/PR Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import getServiceWidget from "utils/config/service-helpers";
|
|
import { formatApiCall } from "utils/proxy/api-helpers";
|
|
import { httpProxy } from "utils/proxy/http";
|
|
|
|
function parseMetric(text, name) {
|
|
const re = new RegExp(`^${name}(?:{[^}]*})?\\s+([0-9.e+\\-]+)`, "m");
|
|
const m = text.match(re);
|
|
return m ? parseFloat(m[1]) : 0;
|
|
}
|
|
|
|
export default async function blockyProxyHandler(req, res) {
|
|
const { group, service } = req.query;
|
|
const widget = await getServiceWidget(group, service);
|
|
const url = formatApiCall("{url}/metrics", widget);
|
|
|
|
const [status, , data] = await httpProxy(url);
|
|
|
|
if (status !== 200) {
|
|
return res.status(status).json({ error: `HTTP ${status}` });
|
|
}
|
|
|
|
const text = data.toString();
|
|
const hits = parseMetric(text, "blocky_cache_hits_total");
|
|
const misses = parseMetric(text, "blocky_cache_misses_total");
|
|
const total = hits + misses;
|
|
|
|
return res.json({
|
|
enabled: parseMetric(text, "blocky_blocking_enabled") === 1,
|
|
denylistEntries: parseMetric(text, "blocky_denylist_cache_entries"),
|
|
totalQueries: total,
|
|
cacheHitRate: total > 0 ? (hits / total) * 100 : 0,
|
|
});
|
|
}
|