mirror of https://github.com/sgoudham/carbon.git
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.
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
import axios from 'axios'
|
|
|
|
const gistClient = axios.create({
|
|
baseURL: 'https://api.github.com',
|
|
timeout: 5000,
|
|
headers: {
|
|
Accept: 'application/vnd.github.v3+json',
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
async function uploadImage (encodedImage) {
|
|
// upload image
|
|
const url = 'https://api.imgur.com/3/image'
|
|
|
|
const data = new FormData()
|
|
data.append('image', encodedImage)
|
|
data.append('type', 'base64')
|
|
|
|
const config = {
|
|
headers: {
|
|
Authorization: ` Client-ID 87cc98dcdabcbb3`
|
|
}
|
|
}
|
|
|
|
try {
|
|
const result = await axios.post(url, data, config)
|
|
|
|
console.log('success! ')
|
|
console.log(Object.keys(result.data))
|
|
console.log(result.data)
|
|
} catch (e) {
|
|
console.log('bummer man')
|
|
console.log(e)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|