Skip to content

Instantly share code, notes, and snippets.

@AprilSylph
Last active April 27, 2020 14:57
Show Gist options
  • Save AprilSylph/122923bf6f0338f3506cd1f5cfb549d1 to your computer and use it in GitHub Desktop.
Save AprilSylph/122923bf6f0338f3506cd1f5cfb549d1 to your computer and use it in GitHub Desktop.
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