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 @@ +