This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
uploader.ts
122 lines (105 loc) · 2.83 KB
/
uploader.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
export interface Uploader {
/** 名称 全局唯一 */
name: string;
/** SDK 相关文档地址 */
docUrl?: string;
/** 默认配置项 */
defaultOptions: UploaderOptions;
/** 配置项 方法调用时需要调用 changeOptions 方法修改 */
options: UploaderOptions;
/** 改变options */
changeOptions: (newOptions: UploaderOptions, proxy?: string) => void;
/** 批量上传模式 并发和顺序 */
batchUploadMode?: BatchUploadMode;
/** 文件上传 */
upload: (options: UploadOptions) => Promise<UploadResponse>;
/** 获取文件列表 */
getFileList?: (directoryPath?: string) => Promise<FileListResponse>;
/** 删除文件 */
deleteFile?: (fileNames: string[]) => Promise<DeleteFileResponse>;
/** 创建目录 */
createDirectory?: (directoryPath: string) => Promise<CreateDirectoryResponse>;
}
export interface UploadOptions {
/** 文件路径或文件Buffer数据 */
file: string | Buffer;
fileName: string;
directoryPath?: string;
isFromFileManage?: boolean;
[property: string]: any;
}
export type BatchUploadMode = 'Concurrent' | 'Sequence';
export type UploaderOptionValidationRule =
| 'domain'
| 'domainPath'
| 'domainQuery'
| { pattern: RegExp | string; message: string };
export type UploaderOptionValidationRuleArr = UploaderOptionValidationRule[];
export enum UploaderOptionsSpan {
small = 4,
middle = 8,
large = 12
}
interface UploaderOption {
/** 表单字段描述 */
label: string;
/** 表单字段名 */
name: string;
/** 默认值 */
value: any;
/** 值类型 */
valueType: 'input' | 'switch' | 'select';
/** form 控件长度 */
span?: UploaderOptionsSpan | number;
/** select 选项 */
options?: { label: string; value: any }[];
/** 是否必填 */
required?: boolean;
/** 验证规则 */
validationRule?: UploaderOptionValidationRuleArr;
/** 配置项描述 */
desc?: string;
[property: string]: any;
}
export type UploaderOptions = UploaderOption[];
export interface UploadResponseData {
/** 文件名 */
name?: string;
/** 文件url */
url: string;
[property: string]: any;
}
interface UploadSuccessResponse {
success: true;
data: UploadResponseData;
}
interface UploadFailResponse {
success: false;
desc: string;
}
export type UploadResponse = UploadSuccessResponse | UploadFailResponse;
export interface ListFile {
name: string;
size?: number;
url?: string;
lastModified?: Date;
type?: 'directory' | 'normal';
[property: string]: any;
}
interface FileListSuccessResponse {
success: true;
data: ListFile[];
}
interface FileListFailResponse {
success: false;
desc?: string;
}
export type FileListResponse = FileListSuccessResponse | FileListFailResponse;
export interface DeleteFileResponse {
success: boolean;
desc?: string;
}
export interface CreateDirectoryResponse {
success: boolean;
desc?: string;
}