jjallaire/draftpod

Support direct upload to https://magic.flooey.org

Closed this issue · 0 comments

This is unfortunately not currently possible due to https://magic.flooey.org not returning CORS headers (for development purposes you get get Chrome to allow the request by opening it with e.g open -a Google\ Chrome --args --disable-web-security --user-data-dir on OSX).

Here's some prototype code we inserted into DeckDownload::onDownloadDeck:

  let log = this.generateDraftLog();

  draftlog.asMtgoLog(log).then(mtgoLog => {
    
    let draftForm = new FormData();
    draftForm.append("draft", new Blob([mtgoLog], { type: "text/plain"}));
    draftForm.append("deck", new Blob([this.deck_list]), { type: "text/plain" });
    draftForm.append("allowsharing", "true");

    axios({
      method: 'POST',
      url: 'https://magic.flooey.org/draft/upload',
      data: draftForm,
      config: {
        headers: { 
          'Content-Type': `multipart/form-data; boundary=${draftForm._boundary}`,
        },
        withCredentials: true,
      }
    })
    .then(response => {
      let draftURL = response.request.responseURL;
      window.open(draftURL, "_blank");
      console.log(response);
    })
    .catch(error => {
      console.log(error);
    })
    

  });

  event.target.blur();