import * as fs from 'fs-extra' ; import PicGo from 'picgo' ; import { Response } from 'request' ; export function isUrl ( url ) { return url . startsWith ( 'http://' ) || url . startsWith ( 'https://' ) ; } export async function fetch ( ctx , url ) { return await ctx . Request . request ( { method : 'GET' , url , encoding : null } ) . on ( 'response' , ( response ) : void => { const contentType = response . headers [ 'content-type' ] ; if ( contentType && ! contentType . includes ( 'image' ) ) { throw new Error ( `${ url } is not image` ) ; } } ) ; } export function getImageBuffer ( ctx , imageUrl ) { if ( isUrl ( imageUrl ) ) { return fetch ( ctx , imageUrl ) ; } else { return fs . readFile ( imageUrl ) ; } }