mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
chore: added put
This commit is contained in:
parent
5769f90fbb
commit
16d440cf69
@ -205,7 +205,7 @@ const Bots: NextPage<BotsProps> = ({ data, date, user, theme, setTheme }) => {
|
||||
}
|
||||
|
||||
export const getServerSideProps = async (ctx: Context) => {
|
||||
const parsed = parseCookie(ctx)
|
||||
const parsed = parseCookie(ctx.req)
|
||||
const data = await get.bot.load(ctx.query.id) ?? { id: '' }
|
||||
const user = await get.Authorization(parsed?.token)
|
||||
return {
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
import { NextPage, NextPageContext } from 'next'
|
||||
import { NextPage } from 'next'
|
||||
import Link from 'next/link'
|
||||
import dynamic from 'next/dynamic'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
import { Bot, User } from '@types'
|
||||
import { Bot, CsrfContext, User } from '@types'
|
||||
import { get } from '@utils/Query'
|
||||
import { makeBotURL, parseCookie, checkBotFlag } from '@utils/Tools'
|
||||
|
||||
import { ParsedUrlQuery } from 'querystring'
|
||||
|
||||
import NotFound from 'pages/404'
|
||||
import { getToken } from '@utils/Csrf'
|
||||
|
||||
|
||||
const Container = dynamic(() => import('@components/Container'))
|
||||
@ -24,7 +25,8 @@ const Advertisement = dynamic(() => import('@components/Advertisement'))
|
||||
const Tooltip = dynamic(() => import('@components/Tooltip'))
|
||||
const Markdown = dynamic(() => import ('@components/Markdown'))
|
||||
|
||||
const VoteBot: NextPage<VoteBotProps> = ({ data }) => {
|
||||
const VoteBot: NextPage<VoteBotProps> = ({ data, user, csrfToken }) => {
|
||||
console.log(csrfToken)
|
||||
const router = useRouter()
|
||||
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}`)
|
||||
@ -54,11 +56,13 @@ const VoteBot: NextPage<VoteBotProps> = ({ data }) => {
|
||||
}
|
||||
|
||||
export const getServerSideProps = async (ctx: Context) => {
|
||||
const parsed = parseCookie(ctx)
|
||||
const parsed = parseCookie(ctx.req)
|
||||
const data = await get.bot.load(ctx.query.id)
|
||||
const user = await get.Authorization(parsed?.token)
|
||||
|
||||
return {
|
||||
props: {
|
||||
csrfToken: getToken(ctx.req, ctx.res),
|
||||
data,
|
||||
user: await get.user.load(user || '')
|
||||
},
|
||||
@ -66,12 +70,13 @@ export const getServerSideProps = async (ctx: Context) => {
|
||||
}
|
||||
|
||||
interface VoteBotProps {
|
||||
csrfToken: string
|
||||
vote: boolean
|
||||
data: Bot
|
||||
user: User
|
||||
}
|
||||
|
||||
interface Context extends NextPageContext {
|
||||
interface Context extends CsrfContext {
|
||||
query: URLQuery
|
||||
}
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ const DiscordCallback:NextPage<DiscordCallbackProps> = ({ data }) => {
|
||||
}
|
||||
|
||||
export const getServerSideProps = async(ctx: NextPageContext) => {
|
||||
const parsed = parseCookie(ctx)
|
||||
const parsed = parseCookie(ctx.req)
|
||||
const token = verify(parsed?.token ?? '')
|
||||
if(!token) return { props: { data: null } }
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ const Panel:NextPage<PanelProps> = ({ logged, user, submits }) => {
|
||||
}
|
||||
|
||||
export const getServerSideProps = async (ctx: NextPageContext) => {
|
||||
const parsed = parseCookie(ctx)
|
||||
const parsed = parseCookie(ctx.req)
|
||||
const user = await get.Authorization(parsed?.token) || ''
|
||||
const submits = await get.botSubmits.load(user)
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import cookie from 'cookie'
|
||||
import { BotFlags, ImageOptions, UserFlags } from '@types'
|
||||
import { KoreanbotsEndPoints, Oauth } from './Constants'
|
||||
import { NextRouter } from 'next/router'
|
||||
import { IncomingMessage } from 'http'
|
||||
|
||||
export function formatNumber(value: number):string {
|
||||
const suffixes = ['', '만', '억', '조','해']
|
||||
@ -95,8 +96,8 @@ export function bufferToStream(binary: Buffer) {
|
||||
return readableInstanceStream
|
||||
}
|
||||
|
||||
export function parseCookie(ctx: NextPageContext): { [key: string]: string } {
|
||||
return cookie.parse(ctx.req.headers.cookie || '')
|
||||
export function parseCookie(req: { headers: { cookie?: string }}): { [key: string]: string } {
|
||||
return cookie.parse(req.headers.cookie || '')
|
||||
}
|
||||
|
||||
export function redirectTo(router: NextRouter, to: string) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user