import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

var uploadFileToTransferSh = /*#__PURE__*/function () {
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
    var fileName, fileURL, remote, remoteURL, axios, exactFilePath, fsFileBuffer, uploadedFileURL;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            fileName = _ref.fileName, fileURL = _ref.fileURL, remote = _ref.remote;
            window.remote = remote; // TODO remove

            remoteURL = "https://files.universaldatatool.com/".concat(fileName); ///${hashedFileName}

            axios = remote.require("axios");
            exactFilePath = fileURL.split("file://")[1];
            fsFileBuffer = remote.require("fs").readFileSync(exactFilePath);
            _context.next = 8;
            return axios.put(remoteURL, fsFileBuffer).then(function (response) {
              if (response.status === 200) {
                return response.data;
              }
            });

          case 8:
            uploadedFileURL = _context.sent;
            return _context.abrupt("return", uploadedFileURL.replace("universaldatatool.com/", "universaldatatool.com/get/"));

          case 10:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));

  return function uploadFileToTransferSh(_x) {
    return _ref2.apply(this, arguments);
  };
}();

export default uploadFileToTransferSh;