Skip to content

Instantly share code, notes, and snippets.

@Gomah
Created August 27, 2017 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gomah/a26092696d91da4aaede89bea18df689 to your computer and use it in GitHub Desktop.
Save Gomah/a26092696d91da4aaede89bea18df689 to your computer and use it in GitHub Desktop.
Login support for uploaded.net
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