mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: added auto refresh
This commit is contained in:
1 parent
3fd90588a3
commit
90d4b76b31
3 files changed
+30
-9
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
export default function withAutoRefresh(svg: string, refreshAfter: number) {
|
||||||
|
return `
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script>
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload();
|
||||||
|
}, ${refreshAfter});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
${svg}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import { RouteRegistry } from '../server.js';
|
|||||||
export default {
|
export default {
|
||||||
route: '/stats/:type/:period',
|
route: '/stats/:type/:period',
|
||||||
inProduction: true,
|
inProduction: true,
|
||||||
inDevelopment: false,
|
inDevelopment: true,
|
||||||
|
|
||||||
async handler(req) {
|
async handler(req) {
|
||||||
const type = req.params.type as StatType;
|
const type = req.params.type as StatType;
|
||||||
|
|||||||
+6
-8
@@ -1,5 +1,6 @@
|
|||||||
import express, { Request, Response } from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
import normalizeRouteReturnable from './core/express/normalizeRouteReturnable.js';
|
import normalizeRouteReturnable from './core/express/normalizeRouteReturnable.js';
|
||||||
|
import withAutoRefresh from './core/express/withAutoRefresh.js';
|
||||||
import isDev from './core/node/isDev.js';
|
import isDev from './core/node/isDev.js';
|
||||||
import { Registry } from './events/interactionCreate/index.js';
|
import { Registry } from './events/interactionCreate/index.js';
|
||||||
import stats from './routes/stats.js';
|
import stats from './routes/stats.js';
|
||||||
@@ -23,17 +24,14 @@ const app = express();
|
|||||||
if (!(isDev() ? registry.inDevelopment : registry.inProduction)) return;
|
if (!(isDev() ? registry.inDevelopment : registry.inProduction)) return;
|
||||||
|
|
||||||
app.get(registry.route, async (req, res) => {
|
app.get(registry.route, async (req, res) => {
|
||||||
const returnable = registry.handler(req, res);
|
console.log(req.originalUrl);
|
||||||
|
|
||||||
|
const returnable = registry.handler(req, res);
|
||||||
if (registry.handlesInteraction) return;
|
if (registry.handlesInteraction) return;
|
||||||
|
|
||||||
const response = await normalizeRouteReturnable(returnable);
|
res.send(
|
||||||
|
withAutoRefresh(await normalizeRouteReturnable(returnable), 60 * 1000),
|
||||||
res.writeHead(200, {
|
);
|
||||||
'Content-Type': 'image/svg+xml',
|
|
||||||
'Content-Length': response.length,
|
|
||||||
});
|
|
||||||
res.end(response);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user