style:格式化成更好看的样子

This commit is contained in:
2026-01-29 17:36:13 +08:00
parent 44038da2aa
commit 4aa2823adc
2 changed files with 209 additions and 75 deletions

View File

@@ -17,19 +17,19 @@ const rateLimiter = async (c, next) => {
const now = Date.now();
const windowMs = 15 * 60 * 1000;
const maxRequests = 100;
if (!requestCounts.has(ip)) {
requestCounts.set(ip, []);
}
const requests = requestCounts.get(ip).filter(time => now - time < windowMs);
requests.push(now);
requestCounts.set(ip, requests);
if (requests.length > maxRequests) {
return c.text('Too many requests from this IP, please try again later.', 429);
}
await next();
};
@@ -58,12 +58,12 @@ app.post('/hooks/gitea', rateLimiter, async (c) => {
logger.error('GITEA_WEBHOOK_SECRET not configured!');
return c.text('Server configuration error', 500);
}
if (!signature) {
logger.security('Request missing signature header', { ip });
return c.text('Signature required', 401);
}
//获取原始请求体进行签名验证
const rawBody = await c.req.text();
const hmac = crypto.createHmac('sha256', config.gitea.secret);
@@ -75,7 +75,7 @@ app.post('/hooks/gitea', rateLimiter, async (c) => {
//解析JSON
const body = JSON.parse(rawBody);
//Payload结构验证
if (!body || !body.issue || !body.repository) {
logger.warn('Invalid payload structure', { ip });
@@ -101,7 +101,7 @@ app.post('/hooks/jira', rateLimiter, async (c) => {
try {
const body = await c.req.json();
logger.info(`[JIRA HOOK] Received request`, { event: body?.webhookEvent });
// Jira Webhook通常没有签名头依赖IP白名单或URL secret参数此处仅校验结构
if (!body || !body.webhookEvent) {
logger.warn(`[JIRA HOOK] Invalid payload: missing webhookEvent`);
@@ -109,7 +109,7 @@ app.post('/hooks/jira', rateLimiter, async (c) => {
}
handleJiraHook(body).catch(err => logger.error('Jira Async handler error', err.message));
return c.text('OK');
} catch (error) {
logger.error('Jira Webhook Error', error.message);
@@ -126,12 +126,12 @@ app.get('/dashboard', serveStatic({ path: './public/dashboard.html' }));
app.route('/api', editorRoutes);
app.route('/editor/api', editorRoutes);
app.use('/editor/*', serveStatic({
app.use('/editor/*', serveStatic({
root: './public',
rewriteRequestPath: (path) => path.replace(/^\/editor/, '')
}));
app.use('/assets/*', serveStatic({
app.use('/assets/*', serveStatic({
root: './public',
rewriteRequestPath: (path) => path.replace(/^\/assets/, '')
}));