You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
carbon/lib/api.js

45 lines
909 B
JavaScript

7 years ago
import axios from 'axios'
7 years ago
const gistClient = axios.create({
baseURL: 'https://api.github.com',
timeout: 5000,
headers: {
Accept: 'application/vnd.github.v3+json',
'Content-Type': 'application/json'
}
});
7 years ago
async function uploadImage (encodedImage) {
// upload image
const url = 'https://api.imgur.com/3/image'
const data = new FormData()
data.append('image', encodedImage)
7 years ago
data.append('type', 'image/png')
7 years ago
const config = {
headers: {
7 years ago
Authorization: `Client-ID 87cc98dcdabcbb3`
7 years ago
}
}
7 years ago
return axios.post(url, data, config)
.then(res => res.data)
.catch(console.log)
7 years ago
}
const getGist = (id) => {
const uid = id.split('/').pop()
return gistClient.get(`/gists/${uid}`)
.then(res => res.data)
.then(gist => gist.files)
.then(files => files[Object.keys(files)[0]])
.then(file => file.content)
}
export default {
uploadImage,
getGist
}