Last active
April 27, 2020 14:57
-
-
Save AprilSylph/122923bf6f0338f3506cd1f5cfb549d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getResponseText = response => { | |
if (response.ok) { | |
return response.text(); | |
} else { | |
throw Object.assign(new Error(response.status), {response}); | |
} | |
}; | |
const getTumblrFormKey = () => fetch('/neue_web/iframe/new/text') | |
.then(getResponseText) | |
.then(responseText => { | |
const responseDocument = (new DOMParser()).parseFromString(responseText, 'text/html'); | |
return responseDocument.getElementById('tumblr_form_key').getAttribute('content'); | |
}) | |
.catch(console.error); | |
const getSecureFormKey = () => getTumblrFormKey() | |
.then(formKey => fetch('/svc/secure_form_key', { | |
method: 'POST', | |
headers: { 'x-tumblr-form-key': formKey }, | |
})) | |
.then(response => response.headers.get('x-tumblr-secure-form-key')) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment