// Admin · Bot Activity — the botScore middleware's scoring/ban state. // // Mounted at /api/v1/admin/bot-activity by admin/index.js, which already applied // `noindex, isLoggedIn, staffOnly`. Read-only view of the in-memory scores, // banned IPs and recent events, plus an emergency unban for false positives. // // Admin-only, and kept as a per-route gate rather than a router-level `use` so // the middleware chain each route carries is unchanged by the move. const express = require('express') const { body } = require('express-validator') const botActivity = require('./botActivity.controller') const { requireRole } = require('../../../utils/auth') const validate = require('../../../middleware/validate') const botActivityRouter = express.Router() const adminOnly = requireRole('admin') botActivityRouter.get( '/', // #swagger.tags = ['Admin · Bot Activity'] // #swagger.summary = 'Bot-scoring / ban state and recent events (admin only)' // #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }] /* #swagger.responses[200] = { description: 'Banned IPs, scores and recent events', content: { "application/json": { schema: { type: "object", additionalProperties: true } } } } */ /* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */ /* #swagger.responses[403] = { description: 'Admin role required', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */ adminOnly, botActivity.getBotActivity, ) botActivityRouter.post( '/unban', // #swagger.tags = ['Admin · Bot Activity'] // #swagger.summary = 'Emergency unban an IP (admin only)' // #swagger.security = [{ "cookieAuth": [] }, { "bearerAuth": [] }] /* #swagger.requestBody = { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/UnbanRequest" } } } } */ /* #swagger.responses[200] = { description: 'Unbanned (echoes the ip and whether an entry was cleared)', content: { "application/json": { schema: { $ref: "#/components/schemas/UnbanResult" } } } } */ /* #swagger.responses[400] = { description: 'Invalid IP', content: { "application/json": { schema: { $ref: "#/components/schemas/ValidationError" } } } } */ /* #swagger.responses[401] = { description: 'Not authenticated', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */ /* #swagger.responses[403] = { description: 'Admin role required', content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } } */ adminOnly, body('ip').isIP(), validate, botActivity.unbanIp, ) module.exports = botActivityRouter