import { getConfig , ConfigProperties } from '../configs' ; import { ImgChr , IImgChrOption } from './Imgchr' ; import { TencentOSS , TencentOSSOption } from './TencentOSS' ; enum UploadType { imgchr = 'imgchr' , tencentoss = 'tencentoss' } export interface Uploader { upload ( file ) : Promise < string > ; } export async function upload ( filePath ) { if ( ! getConfig < boolean > ( ConfigProperties . upload ) ) { return ; } const type = getConfig < UploadType > ( ConfigProperties . uploadType ) ; let uploader = null ; switch ( type ) { case UploadType . imgchr : uploader = new ImgChr ( getConfig < IImgChrOption > ( ConfigProperties . imgChr ) ! ) ; break ; case UploadType . tencentoss : uploader = new TencentOSS ( getConfig < TencentOSSOption > ( ConfigProperties . tencentOSS ) ! ) ; default : break ; } if ( uploader ) { return await uploader . upload ( filePath ) ; } }