node-webot / co-wechat-api

Wechat API. Support Async Functions
Other
724 stars 170 forks source link

uploadMedia的Shortcut中的uploadImage被后面的同名方法覆盖掉了 #40

Closed charmer1989 closed 7 years ago

charmer1989 commented 7 years ago
['image', 'voice', 'video', 'thumb'].forEach(function (type) {
  var method = 'upload' + type[0].toUpperCase() + type.substring(1);
  exports[method] = function* (filepath) {
    return yield this.uploadMedia(filepath, type);
  };
});

这里定义了一个exports.uploadImage 被下面这个方法覆盖了

exports.uploadImage = function* (filepath) {
  var token = yield this.ensureAccessToken();
  var stat = yield fs.stat(filepath);
  var form = formstream();
  form.file('media', filepath, path.basename(filepath), stat.size);
  var url = this.prefix + 'media/uploadimg?access_token=' + token.accessToken;
  var opts = {
    method: 'POST',
    timeout: 60000, // 60秒超时
    headers: form.headers(),
    data: form
  };
  opts.headers.Accept = 'application/json';
  return yield this.request(url, opts);
};
JacksonTian commented 7 years ago

fixed by 521eca25e1ceee1c93ed6d171d46650c894b2bd7