diff --git a/pages/api/v2/bots/[id]/report.ts b/pages/api/v2/bots/[id]/report.ts index d381925..2458350 100644 --- a/pages/api/v2/bots/[id]/report.ts +++ b/pages/api/v2/bots/[id]/report.ts @@ -6,6 +6,7 @@ import RequestHandler from '@utils/RequestHandler' import ResponseWrapper from '@utils/ResponseWrapper' import { ReportSchema, Report} from '@utils/Yup' import { getReportChannel } from '@utils/DiscordBot' +import { checkToken } from '@utils/Csrf' const limiter = rateLimit({ windowMs: 5 * 60 * 1000, @@ -25,6 +26,8 @@ const BotReport = RequestHandler().post(limiter) if(!user) return ResponseWrapper(res, { code: 401 }) const bot = await get.bot.load(req.query.id) if(!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' }) + const csrfValidated = checkToken(req, res, req.body._csrf) + if (!csrfValidated) return if(!req.body) return ResponseWrapper(res, { code: 400 }) const validated: Report = await ReportSchema.validate(req.body, { abortEarly: false }) .then(el => el) diff --git a/pages/bots/[id]/index.tsx b/pages/bots/[id]/index.tsx index 9b51464..4bca78e 100644 --- a/pages/bots/[id]/index.tsx +++ b/pages/bots/[id]/index.tsx @@ -3,20 +3,22 @@ import { useRouter } from 'next/router' import dynamic from 'next/dynamic' import Link from 'next/link' import { useState } from 'react' +import { Field, Form, Formik } from 'formik' import { SnowflakeUtil } from 'discord.js' import { ParsedUrlQuery } from 'querystring' -import { Bot, Theme, User } from '@types' +import { Bot, ResponseProps, Theme, User } from '@types' import { git, reportCats, Status } from '@utils/Constants' import { get } from '@utils/Query' import Day from '@utils/Day' +import { ReportSchema } from '@utils/Yup' +import Fetch from '@utils/Fetch' import { checkBotFlag, checkUserFlag, formatNumber, parseCookie } from '@utils/Tools' +import { getToken } from '@utils/Csrf' import NotFound from '../../404' import Footer from '@components/Footer' -import { Field, Form, Formik } from 'formik' -import { ReportSchema } from '@utils/Yup' const Container = dynamic(() => import('@components/Container')) const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar')) @@ -34,10 +36,11 @@ const Button = dynamic(() => import('@components/Button')) const TextArea = dynamic(() => import('@components/Form/TextArea')) const Modal = dynamic(() => import('@components/Modal')) -const Bots: NextPage = ({ data, date, user, theme, setTheme }) => { +const Bots: NextPage = ({ data, date, user, theme, csrfToken, setTheme }) => { const bg = checkBotFlag(data?.flags, 'trusted') && data?.banner const router = useRouter() const [ reportModal, setReportModal ] = useState(false) + const [ reportRes, setReportRes ] = useState>(null) if (!data?.id) return if((checkBotFlag(data.flags, 'trusted') || checkBotFlag(data.flags, 'partnered')) && data.vanity && data.vanity !== router.query.id) router.push(`/bots/${data.vanity}`) return
@@ -185,39 +188,50 @@ const Bots: NextPage = ({ data, date, user, theme, setTheme }) => { 신고하기 - setReportModal(false)} full dark={theme === 'dark'}> - - { - ({ errors, touched, values, setFieldValue }) => ( -
-
-

신고 구분

-

해당되는 항복을 선택해주세요.

- { - reportCats.map(el => -
- -
- ) - } -
{errors.category && touched.category ? errors.category : null}
-

설명

-

신고하시는 내용을 자세하게 설명해주세요.

-