@@ -5,14 +5,14 @@ import ALY from 'aliyun-sdk';
55import AWS from 'aws-sdk' ;
66import COS from 'cos-nodejs-sdk-v5' ;
77import fsextra from 'fs-extra' ;
8- import { logger } from 'kv-logger' ;
8+ import { Logger } from 'kv-logger' ;
99import _ from 'lodash' ;
1010import qiniu from 'qiniu' ;
1111
1212import { AppError } from '../app-error' ;
1313import { config } from '../config' ;
1414
15- function uploadFileToLocal ( key : string , filePath : string ) : Promise < void > {
15+ function uploadFileToLocal ( key : string , filePath : string , logger : Logger ) : Promise < void > {
1616 return new Promise ( ( resolve , reject ) => {
1717 logger . info ( `try uploadFileToLocal` , {
1818 key,
@@ -76,7 +76,7 @@ function uploadFileToLocal(key: string, filePath: string): Promise<void> {
7676 } ) ;
7777}
7878
79- function uploadFileToS3 ( key : string , filePath : string ) : Promise < void > {
79+ function uploadFileToS3 ( key : string , filePath : string , logger : Logger ) : Promise < void > {
8080 return new Promise ( ( resolve , reject ) => {
8181 logger . info ( 'try uploadFileToS3' , { key } ) ;
8282 AWS . config . update ( {
@@ -111,7 +111,7 @@ function uploadFileToS3(key: string, filePath: string): Promise<void> {
111111 } ) ;
112112}
113113
114- function uploadFileToOSS ( key : string , filePath : string ) : Promise < void > {
114+ function uploadFileToOSS ( key : string , filePath : string , logger : Logger ) : Promise < void > {
115115 logger . info ( 'try uploadFileToOSS' , { key } ) ;
116116 const ossStream = ALYOSSStream (
117117 new ALY . OSS ( {
@@ -151,7 +151,7 @@ function getUploadTokenQiniu(mac: qiniu.auth.digest.Mac, bucket: string, key: st
151151 return putPolicy . uploadToken ( mac ) ;
152152}
153153
154- function uploadFileToQiniu ( key : string , filePath : string ) : Promise < void > {
154+ function uploadFileToQiniu ( key : string , filePath : string , logger : Logger ) : Promise < void > {
155155 return new Promise ( ( resolve , reject ) => {
156156 logger . info ( 'try uploadFileToQiniu' , { key } ) ;
157157 const accessKey = _ . get ( config , 'qiniu.accessKey' ) ;
@@ -202,7 +202,7 @@ function uploadFileToQiniu(key: string, filePath: string): Promise<void> {
202202 } ) ;
203203}
204204
205- function uploadFileToTencentCloud ( key : string , filePath : string ) : Promise < void > {
205+ function uploadFileToTencentCloud ( key : string , filePath : string , logger : Logger ) : Promise < void > {
206206 return new Promise ( ( resolve , reject ) => {
207207 logger . info ( 'try uploadFileToTencentCloud' , { key } ) ;
208208 const cosIn = new COS ( {
@@ -228,19 +228,19 @@ function uploadFileToTencentCloud(key: string, filePath: string): Promise<void>
228228 } ) ;
229229}
230230
231- export function uploadFileToStorage ( key : string , filePath : string ) : Promise < void > {
232- const storageType = _ . get ( config , 'common.storageType' ) ;
231+ export function uploadFileToStorage ( key : string , filePath : string , logger : Logger ) : Promise < void > {
232+ const { storageType } = config . common ;
233233 switch ( storageType ) {
234234 case 'local' :
235- return uploadFileToLocal ( key , filePath ) ;
235+ return uploadFileToLocal ( key , filePath , logger ) ;
236236 case 's3' :
237- return uploadFileToS3 ( key , filePath ) ;
237+ return uploadFileToS3 ( key , filePath , logger ) ;
238238 case 'oss' :
239- return uploadFileToOSS ( key , filePath ) ;
239+ return uploadFileToOSS ( key , filePath , logger ) ;
240240 case 'qiniu' :
241- return uploadFileToQiniu ( key , filePath ) ;
241+ return uploadFileToQiniu ( key , filePath , logger ) ;
242242 case 'tencentcloud' :
243- return uploadFileToTencentCloud ( key , filePath ) ;
243+ return uploadFileToTencentCloud ( key , filePath , logger ) ;
244244 default :
245245 throw new AppError ( `${ storageType } storageType does not support.` ) ;
246246 }
0 commit comments