On this page
查看指定直播间
控制器:app/controller/api/live.js
js
// 查看指定直播间
async read() {
const { ctx, app } = this;
// 参数验证
ctx.validate({
id: {
required: true,
desc: "直播间ID",
type: "int"
}
})
const id = ctx.params.id;
let live = await app.model.Live.findOne({
where: {
id,
},
include: [{
model: app.model.User,
attributes: ['id', 'username', 'avatar']
}]
});
if (!live) {
return ctx.apiFail('当前直播间不存在');
}
// 生成签名
let sign = this.sign(live.key);
live = JSON.parse(JSON.stringify(live))
ctx.apiSuccess({
data: live,
sign
})
}
路由:app/router.js
js
// 查看直播间
router.get("/api/live/read/:id", controller.api.live.read);