const fs = require('fs');

const kaskoFetch = require('../../kasko-fetch');

/**
 * @param {string} host
 * @param {string} file
 * @param {string} token
 * @returns {Promise<string>}
 */
function uploadZip(host, file, token) {
  const body = new FormData();
  const blob = new Blob([fs.readFileSync(file)]);
  body.append('file', blob, file);

  return kaskoFetch(`https://upload.${host}/uploads`, {
    method: 'POST',
    body,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  }).then((data) => data.id);
}

module.exports = uploadZip;
