import axios from 'axios'
export default class CKUploadAdapter {
  constructor(loader) {
    this.loader = loader
  }
  upload() {
    return this.loader.file
      .then(uploadedFile => {
        return new Promise((resolve, reject) => {
          const data = new FormData()
          data.append('file', uploadedFile)
          let myAxios = axios.create({
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          })
          myAxios.post('/api/file/uploadCkeditor', data).then(
            (res) => {
              if (res) {
                console.log(res)
                alert(res.data.data.url)
                resolve({
                  // url: res.data.data.url,
                  // uploaded: res.data.data.uploaded
                  default: res.data.data.url
                })
              } else {
                reject()
              }
            },
            (err) => {
              console.log(err)
            }
          )
        })
      })
  }
  abort() {
  }
}
