const request = require('superagent')

module.exports.decryption = async (ctx, next) => {
   try {
      const { xunruan } = ctx.config
      const { file } = ctx.request
      let url = `${xunruan.host}/uploadSecret`;
      let res_ = await request.post(url).set('Content-Type', 'application/octet-stream')
         .send(file.buffer)
         .responseType('binary')

      ctx.status = 200;
      ctx.body = res_.body
   } catch (error) {
      ctx.status = 400;
      ctx.body = { message: 'decryption error.' };
   }
}
