import { Handler, Router } from '@/mission-control'; import { createBan, getAdminPosts, removeBan, setPostDeleted, setPostLocked, setPostMuted, setPostThreadId, } from '~/db/admin/queries'; import { hasBan } from '~/db/queries'; import withQuery from '~/middleware/withQuery'; import AdminPostsPage from '~/views/admin/AdminPostsPage'; const router = new Router(); router.use('/', (req, res, { tb }) => { const page = req.query ? parseInt(req.query, 10) : 0; const posts = getAdminPosts(page); res.send(tb.include(AdminPostsPage, { page, posts })); res.end(); }); router.use('/ban/:origin', (req, res, { params }) => { const origin = decodeURIComponent(params.origin!); const page = req.query ? parseInt(req.query, 10) : 0; if (hasBan(origin)) { removeBan(origin); } else { createBan(origin); } res.redirect(`/admin/posts?${page}`); }); router.use('/lock/:id/:toggle', (req, res, { params }) => { const id = parseInt(params.id, 10); const page = req.query ? parseInt(req.query, 10) : 0; setPostLocked(id, params.toggle === 'lock'); res.redirect(`/admin/posts?${page}`); }); router.use('/delete/:id/:toggle', (req, res, { params }) => { const id = parseInt(params.id, 10); const page = req.query ? parseInt(req.query, 10) : 0; setPostDeleted(id, params.toggle === 'remove'); res.redirect(`/admin/posts?${page}`); }); router.use('/mute/:id/:toggle', (req, res, { params }) => { const id = parseInt(params.id, 10); const page = req.query ? parseInt(req.query, 10) : 0; setPostMuted(id, params.toggle === 'mute'); res.redirect(`/admin/posts?${page}`); }); router.use('/move/:id', withQuery('thread id'), (req, res, { params }) => { const id = parseInt(params.id, 10); const threadId = parseInt(req.query!, 10); setPostThreadId(id, threadId); res.redirect(`/admin/posts`); }); export default router;