'use strict'; function searchMeta(opts) { return async function (ctx, next) { let errMsg = { message: '搜索元数据失败' } try { const models = ctx.fs.dc.models; const { keywords } = ctx.query; const where = {}; if (keywords) { where['$or'] = [{ name: { $iLike: `%${keywords}%` } } ] } const findObj = { include: [ { model: models.TagDatabase, include: [{ model: models.Tag, }] }], where: where } const rslt = await models.MetadataDatabase.findAndCountAll(findObj); ctx.status = 200; ctx.body = rslt; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = errMsg } } } module.exports = { searchMeta }