@@ -114,6 +114,8 @@ common.uploadFileToStorage = function (key, filePath) {
114114 return common . uploadFileToLocal ( key , filePath ) ;
115115 } else if ( _ . get ( config , 'common.storageType' ) === 's3' ) {
116116 return common . uploadFileToS3 ( key , filePath ) ;
117+ } else if ( _ . get ( config , 'common.storageType' ) === 'oss' ) {
118+ return common . uploadFileToOSS ( key , filePath ) ;
117119 }
118120 return common . uploadFileToQiniu ( key , filePath ) ;
119121} ;
@@ -151,6 +153,8 @@ common.getDownloadUrl = function () {
151153 return _ . get ( config , 'local.downloadUrl' ) ;
152154 } else if ( _ . get ( config , 'common.storageType' ) === 's3' ) {
153155 return _ . get ( config , 's3.downloadUrl' ) ;
156+ } else if ( _ . get ( config , 'common.storageType' ) === 'oss' ) {
157+ return _ . get ( config , 'oss.downloadUrl' ) ;
154158 }
155159 return _ . get ( config , 'qiniu.downloadUrl' ) ;
156160}
@@ -216,6 +220,31 @@ common.uploadFileToS3 = function (key, filePath) {
216220 ) ;
217221} ;
218222
223+ common . uploadFileToOSS = function ( key , filePath ) {
224+ var ALY = require ( 'aliyun-sdk' ) ;
225+ var ossStream = require ( 'aliyun-oss-upload-stream' ) ( new ALY . OSS ( {
226+ accessKeyId : _ . get ( config , 'oss.accessKeyId' ) ,
227+ secretAccessKey : _ . get ( config , 'oss.secretAccessKey' ) ,
228+ endpoint : _ . get ( config , 'oss.endpoint' ) ,
229+ apiVersion : '2013-10-15' ,
230+ } ) ) ;
231+ var upload = ossStream . upload ( {
232+ Bucket : _ . get ( config , 'oss.bucketName' ) ,
233+ Key : `${ _ . get ( config , 'oss.prefix' ) } /${ key } ` ,
234+ } ) ;
235+
236+ return new Promise ( function ( resolve , reject ) {
237+ upload . on ( 'error' , function ( error ) {
238+ reject ( error ) ;
239+ } ) ;
240+
241+ upload . on ( 'uploaded' , function ( details ) {
242+ resolve ( details . ETag ) ;
243+ } ) ;
244+ fs . createReadStream ( filePath ) . pipe ( upload ) ;
245+ } ) ;
246+ } ;
247+
219248common . diffCollectionsSync = function ( collection1 , collection2 ) {
220249 var diffFiles = [ ] ;
221250 var collection1Only = [ ] ;
0 commit comments