-
Notifications
You must be signed in to change notification settings - Fork 520
/
Copy pathindex.ts
58 lines (49 loc) · 1.66 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import StatisticsLogger from './statisticsLog'
import createUploadManager, { Extra, Config, UploadOptions, UploadProgress } from './upload'
import { Observable, IObserver } from './observable'
import { CustomError } from './utils'
import { UploadCompleteData } from './api'
import compressImage from './compress'
const statisticsLogger = new StatisticsLogger()
/**
* @param file 上传文件
* @param key 目标文件名
* @param token 上传凭证
* @param putExtra 上传文件的相关资源信息配置
* @param config 上传任务的配置
* @returns 返回用于上传任务的可观察对象
*/
function upload(
file: File,
key: string,
token: string,
putExtra?: Partial<Extra>,
config?: Partial<Config>
): Observable<UploadProgress, CustomError, UploadCompleteData> {
const options: UploadOptions = {
file,
key,
token,
putExtra,
config
}
return new Observable((observer: IObserver<UploadProgress, CustomError, UploadCompleteData>) => {
const manager = createUploadManager(options, {
onData: (data: UploadProgress) => observer.next(data),
onError: (err: CustomError) => observer.error(err),
onComplete: (res: any) => observer.complete(res)
}, statisticsLogger)
manager.putFile()
return manager.stop.bind(manager)
})
}
export {
getHeadersForMkFile,
getHeadersForChunkUpload
} from './utils'
export { urlSafeBase64Encode, urlSafeBase64Decode } from './base64'
export { CompressResult } from './compress'
export { deleteUploadedChunks, getUploadUrl } from './api'
export { imageMogr2, watermark, imageInfo, exif, pipeline } from './image'
export { region } from './config'
export { upload, compressImage }