All files / exp/app/controller/common oss.js

92.31% Statements 12/13
100% Branches 6/6
100% Functions 1/1
92.31% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38    3x                                 3x 4x 4x   4x 1x   4x 1x   4x 2x   2x 2x        
'use strict'
 
const aliyunOSS = require('../../../libs/aliyun-oss')
 
/**
 * @api {post} common/uploadFileOss 上传文件到OSS
 * @apiDescription 作者:samy
 *
 * @apiGroup common
 * @apiName uploadFileOss
 * @apiSampleRequest common/uploadFileOss
 * @apiPermission user
 *
 * @apiParam {String} key 待上传文件的唯一标识
 * @apiParam {Binnary} file 待上传文件的路径
 *
 * @apiUse Header
 * @apiUse Response
 */
exports.uploadFileOss = async(req, res, next) => {
  let body = req.body
  try {
    let msg
    if (!body.key) {
      msg = '文件唯一标识不能为空'
    }
    if (!body.file) {
      msg = '文件不能为空'
    }
    if (msg) {
      return res.resMid.resBody(res, 422, msg)
    }
    await aliyunOSS.addOss(body.key, body.file)
    res.resMid.resBody(res, '', '上传成功')
  } catch (err) {
    res.throw(err)
  }
}