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

查看分享


控制器:app/controller/share.js

js
	// 查看分享
    async read(){
        const { ctx,app,service } = this;
        let sharedurl = ctx.params.sharedurl
        if(!sharedurl){
            return ctx.apiFail('非法参数');
        }

        let file_id =  ctx.query.file_id

        // 分享是否存在
        let s = await service.share.isExist(sharedurl)

        let where = {
            user_id:s.user_id,
        }

        if(!file_id){
            where.id = s.file_id
        } else {
            where.file_id = file_id
        }

        let rows = await app.model.File.findAll({
            where,
            order: [
                ['isdir', 'desc']
            ]
        });

        ctx.apiSuccess(rows)
    }

服务:app/service/share.js

js
	async isExist(sharedurl,options = {}) {
        let s = await this.app.model.Share.findOne({
            where: {
                sharedurl,
                iscancel:0
            },
            ...options
        });

        if (!s) {
            return this.ctx.throw(404, '该分享已失效');
        }

        return s
    }

路由:app/router.js

js
router.get("/share/:sharedurl", controller.share.read);