Created
August 27, 2017 00:59
-
-
Save Gomah/a26092696d91da4aaede89bea18df689 to your computer and use it in GitHub Desktop.
Login support for uploaded.net
This file contains 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
import axios from 'axios'; | |
import axiosCookieJarSupport from '@3846masa/axios-cookiejar-support'; | |
import tough from 'tough-cookie'; | |
import FormData from 'form-data'; | |
// Add cookie support for axios | |
axiosCookieJarSupport(axios); | |
class Uploaded { | |
constructor(options) { | |
this.config = options.config || {}; | |
this.file = options.file || []; | |
this.cookieJar = new tough.CookieJar(); | |
this.data = new FormData(); | |
} | |
async login(username, password) { | |
this.data.append('id', username); | |
this.data.append('pw', password); | |
try { | |
const resp = await axios.post('https://uploaded.net/io/login', this.data, { | |
headers: { | |
'Content-Type': `multipart/form-data; boundary=${this.data | |
._boundary}`, | |
}, | |
jar: this.cookieJar, | |
withCredentials: false, | |
}); | |
console.log(resp); | |
console.log(this.cookieJar); | |
} catch (err) { | |
console.error(err); | |
console.trace(err); | |
} | |
} | |
} | |
export { Uploaded as default }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment