💾 Archived View for iich.space › src › app › admin › posts.ts captured on 2021-12-03 at 14:04:38.
-=-=-=-=-=-=-
import { Handler, Router } from '@/mission-control'; import { createBan, getAdminPosts, removeBan, setPostDeleted, setPostLocked, setPostMuted, } from '~/db/admin/queries'; import { hasBan } from '~/db/queries'; import AdminPostsPage from '~/views/admin/AdminPostsPage'; const router = new Router<Handler>(); 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}`); }); export default router;