mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 06:20:24 +00:00
fix: router called at serverside
This commit is contained in:
parent
87a98bdbc6
commit
edc51d773e
@ -42,12 +42,11 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [ nsfw, setNSFW ] = useState<boolean>()
|
const [ nsfw, setNSFW ] = useState<boolean>()
|
||||||
const [ reportModal, setReportModal ] = useState(false)
|
const [ reportModal, setReportModal ] = useState(false)
|
||||||
const [ reportRes, setReportRes ] = useState<ResponseProps<null>>(null)
|
const [ reportRes, setReportRes ] = useState<ResponseProps<unknown>>(null)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setNSFW(localStorage.nsfw)
|
setNSFW(localStorage.nsfw)
|
||||||
}, [])
|
}, [])
|
||||||
if (!data?.id) return <NotFound />
|
if (!data?.id) return <NotFound />
|
||||||
if((checkBotFlag(data.flags, 'trusted') || checkBotFlag(data.flags, 'partnered')) && data.vanity && data.vanity !== router.query.id) router.push(`/bots/${data.vanity}`)
|
|
||||||
return <div style={bg ? { background: `linear-gradient(to right, rgba(34, 36, 38, 0.68), rgba(34, 36, 38, 0.68)), url("${data.bg}") center top / cover no-repeat fixed` } : {}}>
|
return <div style={bg ? { background: `linear-gradient(to right, rgba(34, 36, 38, 0.68), rgba(34, 36, 38, 0.68)), url("${data.bg}") center top / cover no-repeat fixed` } : {}}>
|
||||||
<Container paddingTop className='py-10'>
|
<Container paddingTop className='py-10'>
|
||||||
<SEO
|
<SEO
|
||||||
@ -201,7 +200,7 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
<h2 className='text-lg font-semibold'>성공적으로 신고하였습니다!</h2>
|
<h2 className='text-lg font-semibold'>성공적으로 신고하였습니다!</h2>
|
||||||
<p>더 자세한 설명이 필요할 수 있습니다! <a className='text-blue-600 hover:text-blue-500' href='/discord'>공식 디스코드</a>에 참여해주세요</p>
|
<p>더 자세한 설명이 필요할 수 있습니다! <a className='text-blue-600 hover:text-blue-500' href='/discord'>공식 디스코드</a>에 참여해주세요</p>
|
||||||
</Message> : <Formik onSubmit={async (body) => {
|
</Message> : <Formik onSubmit={async (body) => {
|
||||||
const res = await Fetch<null>(`/bots/${data.id}/report`, { method: 'POST', body: JSON.stringify(body) })
|
const res = await Fetch(`/bots/${data.id}/report`, { method: 'POST', body: JSON.stringify(body) })
|
||||||
setReportRes(res)
|
setReportRes(res)
|
||||||
}} validationSchema={ReportSchema} initialValues={{
|
}} validationSchema={ReportSchema} initialValues={{
|
||||||
category: null,
|
category: null,
|
||||||
@ -313,12 +312,19 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
|
|||||||
|
|
||||||
export const getServerSideProps = async (ctx: Context) => {
|
export const getServerSideProps = async (ctx: Context) => {
|
||||||
const parsed = parseCookie(ctx.req)
|
const parsed = parseCookie(ctx.req)
|
||||||
const data = await get.bot.load(ctx.query.id) ?? { id: '' }
|
const data = await get.bot.load(ctx.query.id)
|
||||||
const desc = await get.botDescSafe(data.id)
|
const desc = await get.botDescSafe(data.id)
|
||||||
const user = await get.Authorization(parsed?.token)
|
const user = await get.Authorization(parsed?.token)
|
||||||
|
if(data && (checkBotFlag(data.flags, 'trusted') || checkBotFlag(data.flags, 'partnered')) && data?.vanity && data.vanity !== ctx.query.id) {
|
||||||
|
ctx.res.statusCode = 301
|
||||||
|
ctx.res.setHeader('Location', `/bots/${data.vanity}`)
|
||||||
|
return {
|
||||||
|
props: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
data,
|
data: data ?? { id: '' },
|
||||||
desc,
|
desc,
|
||||||
date: SnowflakeUtil.deconstruct(data.id ?? '0').date.toJSON(),
|
date: SnowflakeUtil.deconstruct(data.id ?? '0').date.toJSON(),
|
||||||
user: await get.user.load(user || ''),
|
user: await get.user.load(user || ''),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user