fix: polls /active route order, features redundant auth check
This commit is contained in:
@@ -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个选项为必填' });
|
||||
|
||||
@@ -16,7 +16,7 @@ const FeaturesPage = {
|
||||
ct.innerHTML = items.length === 0
|
||||
? '<div class="empty"><i class="fas fa-lightbulb"></i><p>暂无更新项目</p></div>'
|
||||
: 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 = `<div class="alert alert-e">${e.message}</div>`; }
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user