allowJs is set to false in tsconfig.json now; please write all future code with typescript. cleanups: - removed platforms/deprecated - removed flow/history/old - see https://github.com/QURIresearch/metaforecast/issues/22 - commented some invalid axios options - minor fixes with mismatching function arguments - commented invalid mongo call in databaseReadWithReadCredentials - {encoding: 'utf-8'} in readFileSync calls
30 lines
859 B
TypeScript
30 lines
859 B
TypeScript
// import fetch from "fetch"
|
|
import axios, { AxiosRequestConfig } from 'axios';
|
|
|
|
export async function uploadToImgur(dataURL, handleGettingImgurlImage) {
|
|
let request: AxiosRequestConfig = {
|
|
method: "post",
|
|
url: "https://api.imgur.com/3/image",
|
|
headers: {
|
|
Authorization: "Bearer 8e9666fb889318515a62208560d4e8393dac26d8",
|
|
},
|
|
data: {
|
|
type: "base64",
|
|
image: dataURL.split(",")[1],
|
|
},
|
|
// redirect: "follow",
|
|
};
|
|
let url;
|
|
try {
|
|
let response = await axios(request).then((response) => response.data);
|
|
// console.log(dataURL)
|
|
// console.log(response)
|
|
url = `https://i.imgur.com/${response.data.id}.png`;
|
|
} catch (error) {
|
|
console.log("error", error);
|
|
}
|
|
let errorImageURL = "https://i.imgur.com/qcThRRz.gif"; // Error image
|
|
url = url || errorImageURL;
|
|
handleGettingImgurlImage(url);
|
|
}
|