On this page
创建视频
控制器:app/controller/video_detail.js
js
let rules = {
title: {
type: 'string',
required: true,
desc: '视频标题'
},
url: {
type: 'string',
required: true,
desc: '视频地址'
},
video_id: {
type: 'int',
required: true,
desc: '所属视频ID'
},
desc: {
type: 'string',
required: true,
desc: '描述'
},
}
// 发布视频
async save() {
let { ctx, app } = this;
let currentUser = ctx.authUser;
ctx.validate(rules);
let {
title,
url,
video_id,
desc,
} = ctx.request.body;
// 所属作品不存在
let video = await app.model.Video.findOne({
where: {
id: video_id,
user_id: currentUser.id
}
});
if (!video) {
ctx.throw(404, '所属作品不存在');
}
let vd = await app.model.VideoDetail.create({
title,
url,
video_id,
desc,
});
ctx.apiSuccess(vd);
}
路由:app/router.js
js
router.post("/video_detail", controller.videoDetail.save);