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

搜索文件


控制器:app/controller/file.js

js
async search() {
        const { ctx, app } = this;
        const user_id = ctx.authUser.id;

        ctx.validate({
            keyword:{
                required:true,
                type:"string",
                desc:"关键字"
            },
        })

        let { keyword } = ctx.query

        const Op = app.Sequelize.Op

        let rows = await app.model.File.findAll({
            where:{
                name:{
                    [Op.like]:`%${keyword}%`
                },
                isdir:0,
                user_id
            }
        })

        ctx.apiSuccess({
            rows
        })
    }

路由:app/router.js

js
router.get("/file/search", controller.file.search);