import _ from 'lodash' ; import RequestMethod from 'constants/requestMethod' ; /**
 * Imgur base API URL.
 */ const BaseUrl = 'https://api.imgur.com/3' ; /**
 * Imgur class.
 */ export default class Imgur { param file return public static async uploadAnonymousFile ( file ) { const data = new FormData ( ) ; data . append ( 'image' , file ) ; const response = await Imgur . fetch ( '/image' , RequestMethod . Post , data ) ; return response . json ( ) ; } param endpoint return private static getUrl ( endpoint ) { return BaseUrl . concat ( endpoint ) ; } param endpoint param method param body return private static async fetch ( endpoint , method = RequestMethod . Get , body ? ) { const url = Imgur . getUrl ( endpoint ) ; const headers = new Headers ( { Authorization : `Client-ID ${ process . env . REACT_APP_IMGUR_CLIENT_ID }` , } ) ; const init = { headers , method } ; if ( ! _ . isNil ( body ) ) { init . body = body ; } const request = new Request ( url , init ) ; const response = await fetch ( request ) ; if ( response . status >= 400 ) { const json = await response . json ( ) ; throw new Error ( _ . get ( json , 'data.error' , 'Something went wrong.' ) ) ; } return response ; } } /**
 * Imgur upload.
 */ export type ImgurUpload = { data : { account_id : number ; account_url : string | null ; ad_type : number ; ad_url : string ; animated : boolean ; bandwidth : number ; datetime : number ; deletehash : string ; description : string | null ; favorite : boolean ; has_sound : boolean ; height : number ; id : string ; in_gallery : boolean ; in_most_viral : boolean ; is_ad : boolean ; link : string ; name : string ; nsfw : boolean ; size : number ; tags : string [ ] ; length : number ; title : string | null ; type : string ; views : number ; vote : number | null ; width : number ; } ; status : number ; success : boolean ; } ;