jjallaire / draftpod

Draft simulator for Magic the Gathering
https://draftpod.org
MIT License
37 stars 7 forks source link

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

Closed jjallaire closed 4 years ago

jjallaire commented 5 years ago

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();