"use strict";

exports.__esModule = true;
exports.default = void 0;
var _file = _interopRequireDefault(require("@uni/file"));
var _utils = require("../utils");
var _utils2 = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function request(obj) {
  var task = _file.default.upload({
    url: obj.action,
    formData: obj.data,
    filePath: obj.file,
    withCredentials: obj.withCredentials,
    fileName: obj.filename,
    fileType: obj.fileType,
    header: obj.headers,
    success: function success(res) {
      return obj.onSuccess(res);
    },
    fail: function fail(e) {
      return obj.onError(e);
    }
  });
  if (task && task.onProgressUpdate && !(_utils.isAndroid && _utils.isStrictWechatMiniProgram)) {
    task.onProgressUpdate(function (_ref) {
      var progress = _ref.progress;
      obj.onProgress({
        percent: progress
      });
    });
  } else {
    var percent = 10;
    var timer = setInterval(function () {
      if (percent < 90) {
        percent += 10;
        obj.onProgress({
          percent: percent
        });
      } else {
        clearInterval(timer);
      }
    }, _utils2.UPLOAD_THROTTLE);
  }
  return {
    abort: function abort() {
      if (task && task.abort) {
        task.abort();
      }
    }
  };
}
var _default = request;
exports.default = _default;