content/image 二选一或二选二
This commit is contained in:
父節點
1ebd5aa4aa
當前提交
22dc49adcc
@ -2,7 +2,7 @@ import 'reflect-metadata'
|
||||
import {Container} from "typedi"
|
||||
import {PostService} from "../services/post-service"
|
||||
import express from "express"
|
||||
import {body, query} from "express-validator"
|
||||
import {body, oneOf, query} from "express-validator"
|
||||
import * as Validator from "validator"
|
||||
import {hasValidationErrors} from "../includes"
|
||||
import {JWTUserPayload} from "../types"
|
||||
@ -11,9 +11,13 @@ let postService = Container.get(PostService)
|
||||
|
||||
let postRouter = express.Router()
|
||||
postRouter.post('/submit',
|
||||
body('content').notEmpty().withMessage('请输入内容')
|
||||
oneOf([
|
||||
body('content').exists(),
|
||||
body('image').exists()
|
||||
]),
|
||||
body('content').optional().notEmpty().withMessage('请输入内容')
|
||||
.escape(),
|
||||
body('image').isURL({host_whitelist: [/.*\.360buyimg\.com/]}).withMessage('仅支援*.360buyimg.com下的图片'),
|
||||
body('image').optional().isURL({host_whitelist: [/.*\.360buyimg\.com/]}).withMessage('仅支援*.360buyimg.com下的图片'),
|
||||
async (req: express.Request, res: express.Response) => {
|
||||
if (hasValidationErrors(req, res)) return
|
||||
res.json(await postService.submit(req.user as JWTUserPayload, req.body.content, req.body.image))
|
||||
|
載入中…
x
新增問題並參考
Block a user