import { fetch, apis } from './request';
import mixStr from './mixStr';

const getToken = () => mixStr(window.localStorage.getItem('test-foobar'))

const uploadImage = fetch(apis.image.upload)

const uploaderProps = {
  name: 'file',
  // action: apis.image.uploadForAnt.url,
  accept: '.png, .jpg, .jpeg, .gif',
  // headers: {
  //   Authorization: `Bearer ${getToken()}`
  // },
  customRequest({
    action,
    file,
    headers,
    onError,
    onProgress,
    onSuccess,
    withCredentials,
  }) {
    const data = new FormData()
    data.append('file', file)

    uploadImage({ data }).then((img) => {
      onSuccess(img, file);
    }).catch(onError);

    return {
      abort() {
        console.log('upload progress is aborted.');
      },
    };
  },
}

export { uploaderProps }
