From 4aa2823adce03e88979af49b14123eec4632b3b9 Mon Sep 17 00:00:00 2001 From: loren Date: Thu, 29 Jan 2026 17:36:13 +0800 Subject: [PATCH] =?UTF-8?q?style:=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=88=90?= =?UTF-8?q?=E6=9B=B4=E5=A5=BD=E7=9C=8B=E7=9A=84=E6=A0=B7=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 22 ++-- public/dashboard.html | 262 +++++++++++++++++++++++++++++++----------- 2 files changed, 209 insertions(+), 75 deletions(-) diff --git a/index.js b/index.js index b07c2bf..6f70472 100644 --- a/index.js +++ b/index.js @@ -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/, '') })); diff --git a/public/dashboard.html b/public/dashboard.html index 279aecd..99b058c 100644 --- a/public/dashboard.html +++ b/public/dashboard.html @@ -1,5 +1,6 @@ + @@ -7,67 +8,162 @@ +
-
+
- + TaskBot控制台
- +