Skip to content
关注公众号,获取新课通知

修改视频


控制器:app/controller/video_detail.js

js
	async update() {
        let { ctx, app } = this;
        let currentUser = ctx.authUser;

        ctx.validate({
            id: {
                type: "int",
                required: true,
                desc: "视频ID"
            },
            ...rules
        });

        let {
            title,
            url,
            video_id,
            desc,
        } = ctx.request.body;

        let { id } = ctx.params;

        // 所属作品是否存在
        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.findOne({
            where: {
                id,
                video_id
            }
        });

        if (!vd) {
            ctx.throw(404, '当前记录不存在');
        }

        let res = await vd.update({
            title,
            url,
            video_id,
            desc,
        });

        ctx.apiSuccess(res);
    }

路由:app/router.js

js
router.post("/video_detail/:id", controller.videoDetail.update);