From 3d7393817cf41b1e44f840e29173db29437034ca Mon Sep 17 00:00:00 2001 From: canglan Date: Tue, 14 Jul 2026 03:03:56 +0800 Subject: [PATCH] fix: polls /active route order, features redundant auth check --- backend/routes/polls.js | 12 ++++++------ public/js/pages/features.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/routes/polls.js b/backend/routes/polls.js index 17aacce..34d7722 100644 --- a/backend/routes/polls.js +++ b/backend/routes/polls.js @@ -4,12 +4,6 @@ const { authenticate, requireRole } = require('../middleware/auth'); const router = express.Router(); -router.get('/:id', authenticate, requireRole('owner'), async (req, res) => { - const p = await getRow('SELECT * FROM polls WHERE id = ?', [req.params.id]); - if (!p) return res.status(404).json({ error: '不存在' }); - res.json(p); -}); - router.get('/active', authenticate, async (req, res) => { const polls = await query('SELECT id, title, description, active, created_at FROM polls WHERE active = 1 ORDER BY created_at DESC'); for (const p of polls) { @@ -29,6 +23,12 @@ router.get('/active', authenticate, async (req, res) => { res.json(polls); }); +router.get('/:id', authenticate, requireRole('owner'), async (req, res) => { + const p = await getRow('SELECT * FROM polls WHERE id = ?', [req.params.id]); + if (!p) return res.status(404).json({ error: '不存在' }); + res.json(p); +}); + router.post('/', authenticate, requireRole('owner'), async (req, res) => { const { title, description, options } = req.body; if (!title || !options || !Array.isArray(options) || options.length < 2) return res.status(400).json({ error: '标题和至少2个选项为必填' }); diff --git a/public/js/pages/features.js b/public/js/pages/features.js index 4216b17..06310e2 100644 --- a/public/js/pages/features.js +++ b/public/js/pages/features.js @@ -16,7 +16,7 @@ const FeaturesPage = { ct.innerHTML = items.length === 0 ? '

暂无更新项目

' : items.map(i => this.renderItem(i)).join(''); - for (const i of items) if (Auth.logged() || Auth.logged()) this.bindVote(i); + for (const i of items) if (Auth.logged()) this.bindVote(i); } catch (e) { ct.innerHTML = `
${e.message}
`; } },