mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
This commit is contained in:
parent
8a5293e3f4
commit
7355df4714
@ -76,11 +76,13 @@ const Bots = RequestHandler()
|
||||
return ResponseWrapper(res, { code: 200, data: result })
|
||||
})
|
||||
.delete(async (req: DeleteApiRequest, res) => {
|
||||
const bot = await get.bot.load(req.query.id)
|
||||
if(!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
||||
const user = await get.Authorization(req.cookies.token)
|
||||
if (!user) return ResponseWrapper(res, { code: 401 })
|
||||
const bot = await get.bot.load(req.query.id)
|
||||
if(!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
||||
if((bot.owners as User[])[0].id !== user) return ResponseWrapper(res, { code: 403 })
|
||||
const userInfo = await get.user.load(user)
|
||||
if(['reported', 'blocked', 'archived'].includes(bot.state) && !checkUserFlag(userInfo?.flags, 'staff')) return ResponseWrapper(res, { code: 403, message: '해당 봇은 수정할 수 없습니다.', errors: ['오류라고 생각되면 문의해주세요.'] })
|
||||
const csrfValidated = checkToken(req, res, req.body._csrf)
|
||||
if (!csrfValidated) return
|
||||
const captcha = await CaptchaVerify(req.body._captcha)
|
||||
@ -94,10 +96,10 @@ const Bots = RequestHandler()
|
||||
.patch(patchLimiter).patch(async (req: PatchApiRequest, res) => {
|
||||
const bot = await get.bot.load(req.query.id)
|
||||
if(!bot) return ResponseWrapper(res, { code: 404, message: '존재하지 않는 봇입니다.' })
|
||||
if(['reported', 'blocked', 'archived'].includes(bot.state)) return ResponseWrapper(res, { code: 403, message: '해당 봇은 수정할 수 없습니다.', errors: ['오류라고 생각되면 문의해주세요.'] })
|
||||
const user = await get.Authorization(req.cookies.token)
|
||||
if (!user) return ResponseWrapper(res, { code: 401 })
|
||||
const userInfo = await get.user.load(user)
|
||||
if(['reported', 'blocked', 'archived'].includes(bot.state) && !checkUserFlag(userInfo?.flags, 'staff')) return ResponseWrapper(res, { code: 403, message: '해당 봇은 수정할 수 없습니다.', errors: ['오류라고 생각되면 문의해주세요.'] })
|
||||
if(!(bot.owners as User[]).find(el => el.id === user) && !checkUserFlag(userInfo?.flags, 'staff')) return ResponseWrapper(res, { code: 403 })
|
||||
const csrfValidated = checkToken(req, res, req.body._csrf)
|
||||
if (!csrfValidated) return
|
||||
@ -110,6 +112,7 @@ const Bots = RequestHandler()
|
||||
})
|
||||
|
||||
if (!validated) return
|
||||
console.log(validated)
|
||||
const result = await update.bot(req.query.id, validated)
|
||||
if(result === 0) return ResponseWrapper(res, { code: 400 })
|
||||
else {
|
||||
|
||||
@ -132,7 +132,7 @@ export function redirectTo(router: NextRouter, to: string) {
|
||||
export function cleanObject<T extends Record<any, any>>(obj: T): T {
|
||||
for (const propName in obj) {
|
||||
if (obj[propName] !== 0 && !obj[propName]) {
|
||||
delete obj[propName]
|
||||
obj[propName] = null
|
||||
}
|
||||
}
|
||||
return obj
|
||||
|
||||
27
utils/Yup.ts
27
utils/Yup.ts
@ -141,19 +141,23 @@ export const AddBotSubmitSchema: Yup.SchemaOf<AddBotSubmit> = Yup.object({
|
||||
website: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 웹사이트 URL을 입력해주세요.')
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.'),
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
url: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 초대링크 URL을 입력해주세요.')
|
||||
.max(128, 'URL은 최대 128자까지만 가능합니다.'),
|
||||
.max(128, 'URL은 최대 128자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
git: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 깃 URL을 입력해주세요.')
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.'),
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
discord: Yup.string()
|
||||
.matches(Vanity, '디스코드 초대코드 형식을 지켜주세요.')
|
||||
.min(2, '지원 디스코드는 최소 2자여야합니다.')
|
||||
.max(32, '지원 디스코드는 최대 32자까지만 가능합니다.'),
|
||||
.max(32, '지원 디스코드는 최대 32자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
category: Yup.array(Yup.string().oneOf(categories))
|
||||
.min(1, '최소 한 개의 카테고리를 선택해주세요.')
|
||||
.unique('카테고리는 중복될 수 없습니다.')
|
||||
@ -221,19 +225,23 @@ export const ManageBotSchema: Yup.SchemaOf<ManageBot> = Yup.object({
|
||||
website: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 웹사이트 URL을 입력해주세요.')
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.'),
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
url: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 초대링크 URL을 입력해주세요.')
|
||||
.max(128, 'URL은 최대 128자까지만 가능합니다.'),
|
||||
.max(128, 'URL은 최대 128자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
git: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 깃 URL을 입력해주세요.')
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.'),
|
||||
.max(64, 'URL은 최대 64자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
discord: Yup.string()
|
||||
.matches(Vanity, '디스코드 초대코드 형식을 지켜주세요.')
|
||||
.min(2, '지원 디스코드는 최소 2자여야합니다.')
|
||||
.max(32, '지원 디스코드는 최대 32자까지만 가능합니다.'),
|
||||
.max(32, '지원 디스코드는 최대 32자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
category: Yup.array(Yup.string().oneOf(categories))
|
||||
.min(1, '최소 한 개의 카테고리를 선택해주세요.')
|
||||
.unique('카테고리는 중복될 수 없습니다.')
|
||||
@ -276,7 +284,8 @@ export const DeveloperBotSchema: Yup.SchemaOf<DeveloperBot> = Yup.object({
|
||||
webhook: Yup.string()
|
||||
.matches(HTTPProtocol, 'http:// 또는 https:// 로 시작해야합니다.')
|
||||
.matches(Url, '올바른 웹훅 URL을 입력해주세요.')
|
||||
.max(150, 'URL은 최대 150자까지만 가능합니다.'),
|
||||
.max(150, 'URL은 최대 150자까지만 가능합니다.')
|
||||
.nullable(),
|
||||
_csrf: Yup.string().required(),
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user