Compare commits

..

2 Commits

Author SHA1 Message Date
skinmaker1345
bb7e283218 chore: bump version 2025-04-13 13:29:11 +09:00
skinmaker1345
5132c2243a fix: seperate schema depending on perks 2025-04-13 13:28:58 +09:00
4 changed files with 84 additions and 75 deletions

View File

@ -1,6 +1,6 @@
{
"name": "koreanbots",
"version": "2.10.0",
"version": "2.10.1",
"private": true,
"scripts": {
"dev": "next dev",

View File

@ -10,8 +10,8 @@ import {
AddBotSubmit,
AddBotSubmitSchema,
CsrfCaptcha,
getManageBotSchema,
ManageBot,
ManageBotSchema,
} from '@utils/Yup'
import RequestHandler from '@utils/RequestHandler'
import { User } from '@types'
@ -197,6 +197,10 @@ const Bots = RequestHandler()
if (!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
const user = await get.Authorization(req.cookies.token)
if (!user) return ResponseWrapper(res, { code: 401 })
const isPerkAvailable =
checkBotFlag(bot.flags, 'partnered') || checkBotFlag(bot.flags, 'trusted')
const userInfo = await get.user.load(user)
if (
['reported', 'blocked', 'archived'].includes(bot.state) &&
@ -215,7 +219,7 @@ const Bots = RequestHandler()
const csrfValidated = checkToken(req, res, req.body._csrf)
if (!csrfValidated) return
const validated: ManageBot = await ManageBotSchema.validate(req.body, { abortEarly: false })
const validated: ManageBot = await getManageBotSchema(isPerkAvailable).validate(req.body, { abortEarly: false })
.then((el) => el)
.catch((e) => {
ResponseWrapper(res, { code: 400, errors: e.errors })
@ -223,11 +227,7 @@ const Bots = RequestHandler()
})
if (!validated) return
if (
!checkBotFlag(bot.flags, 'trusted') &&
!checkBotFlag(bot.flags, 'partnered') &&
(validated.vanity || validated.banner || validated.bg)
)
if (!isPerkAvailable && (validated.vanity || validated.banner || validated.bg))
return ResponseWrapper(res, {
code: 403,
message: '해당 봇은 특전을 이용할 권한이 없습니다.',
@ -260,7 +260,7 @@ const Bots = RequestHandler()
},
],
color: Colors.Blue,
}
},
],
})
}

View File

@ -10,7 +10,7 @@ import { getJosaPicker } from 'josa'
import { get } from '@utils/Query'
import { checkBotFlag, checkUserFlag, cleanObject, makeBotURL, parseCookie, redirectTo } from '@utils/Tools'
import { ManageBot, ManageBotSchema } from '@utils/Yup'
import { ManageBot, getManageBotSchema } from '@utils/Yup'
import { botCategories, botCategoryDescription, library } from '@utils/Constants'
import { Bot, Theme, User } from '@types'
import { getToken } from '@utils/Csrf'
@ -93,7 +93,7 @@ const ManageBotPage: NextPage<ManageBotProps> = ({ bot, user, csrfToken, theme }
bg: isPerkAvailable && bot.bg,
_csrf: csrfToken,
})}
validationSchema={ManageBotSchema}
validationSchema={getManageBotSchema(isPerkAvailable)}
onSubmit={submitBot}
>
{({ errors, touched, values, setFieldTouched, setFieldValue }) => (

View File

@ -263,7 +263,8 @@ export interface Report {
_csrf: string
}
export const ManageBotSchema: Yup.SchemaOf<ManageBot> = Yup.object({
export function getManageBotSchema(perkAvailable = false) {
const common = {
prefix: Yup.string()
.matches(Prefix, '접두사는 띄어쓰기로 시작할 수 없습니다.')
.min(1, '접두사는 최소 1자여야합니다.')
@ -302,6 +303,10 @@ export const ManageBotSchema: Yup.SchemaOf<ManageBot> = Yup.object({
.min(100, '봇 설명은 최소 100자여야합니다.')
.max(1500, '봇 설명은 최대 1500자여야합니다.')
.required('봇 설명은 필수 항목입니다.'),
_csrf: Yup.string().required(),
}
const perk = {
vanity: Yup.string()
.matches(Vanity, '커스텀 URL은 영문만 포함할 수 있습니다.')
.when('id', {
@ -325,8 +330,12 @@ export const ManageBotSchema: Yup.SchemaOf<ManageBot> = Yup.object({
.matches(Url, '올바른 배경 URL을 입력해주세요.')
.max(612, 'URL은 최대 612자까지만 가능합니다.')
.nullable(),
_csrf: Yup.string().required(),
})
}
return Yup.object({
...common,
...(perkAvailable ? perk : {}),
}) as Yup.SchemaOf<ManageBot>
}
export interface ManageBot {
prefix: string