import request from '@/H5Public/utils/request';
import config from '@/config/config';
import { getToken } from '@/H5Public/utils/authority';


function getFileUrl(params = {}, url) {
  return request(config.folderServer + url, {
    method: 'POST',
    body: params,
  });
}

export const uploadFile = (params ={}) => {
  return getFileUrl(params, '/uploadFileApi/upload');
};

export function uploadOnestopFile(file) {
  let url = config.sqlFormsServer + '/upload';
  const formData = new FormData();
  formData.append('file', file);
  formData.append('token', getToken());
  return fetch(url, {
    method: 'POST',
    headers: {
      Authorization: `bearer ${getToken()}`,
      Accept: '*/*',
      env: process.env.NODE_ENV === 'development' ? 'test' : undefined,
    },
    body: formData,
  }).then(response => response.text());
}

