mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
chore: 去除有安全风险的 async 库依赖 (#4051)
* chore: 去除有安全风险的 async 库依赖 * 去掉 console.log
This commit is contained in:
parent
534dc7552a
commit
70b86f556e
@ -105,6 +105,8 @@ order: 21
|
||||
- `chunkApi` 用来接收每个分块上传
|
||||
- `finishChunkApi` 用来收尾分块上传
|
||||
|
||||
还可以通过 `concurrency` 控制并行数量,默认是 3
|
||||
|
||||
### startChunkApi
|
||||
|
||||
用来做分块前的准备工作,一个文件只会调用一次。如果出错了,后续的分块上传就会中断。
|
||||
@ -293,7 +295,7 @@ order: 21
|
||||
| maxSize | `number` | | 默认没有限制,当设置后,文件大小大于此值将不允许上传。单位为`B` |
|
||||
| maxLength | `number` | | 默认没有限制,当设置后,一次只允许上传指定数量文件。 |
|
||||
| multiple | `boolean` | `false` | 是否多选。 |
|
||||
| drag | `boolean` | `false` | 是否为拖拽上传 | |
|
||||
| drag | `boolean` | `false` | 是否为拖拽上传 |
|
||||
| joinValues | `boolean` | `true` | [拼接值](./options#%E6%8B%BC%E6%8E%A5%E5%80%BC-joinvalues) |
|
||||
| extractValue | `boolean` | `false` | [提取值](./options#%E6%8F%90%E5%8F%96%E5%A4%9A%E9%80%89%E5%80%BC-extractvalue) |
|
||||
| delimiter | `string` | `,` | [拼接符](./options#%E6%8B%BC%E6%8E%A5%E7%AC%A6-delimiter) |
|
||||
@ -311,6 +313,7 @@ order: 21
|
||||
| startChunkApi | [API](../../../docs/types/api) | | startChunkApi |
|
||||
| chunkApi | [API](../../../docs/types/api) | | chunkApi |
|
||||
| finishChunkApi | [API](../../../docs/types/api) | | finishChunkApi |
|
||||
| concurrency | `number` | | 分块上传时并行个数 |
|
||||
|
||||
## 事件表
|
||||
|
||||
@ -329,8 +332,9 @@ order: 21
|
||||
| value | `string` | 上传成功后返回的 url |
|
||||
| state | `string` | 文件当前状态,值可为 `pending` `uploaded` `invalid` |
|
||||
| error | `string` | 错误信息 |
|
||||
|
||||
## 动作表
|
||||
|
||||
| 动作名称 | 动作配置 | 说明 |
|
||||
| -------- | -------- | ---- |
|
||||
| clear | - | 清空 |
|
||||
| clear | - | 清空 |
|
||||
|
@ -26,7 +26,6 @@
|
||||
'amis/embed': __moduleId('./embed.tsx'),
|
||||
'amis@@version/embed': __moduleId('./embed.tsx'),
|
||||
'prop-types': __moduleId('prop-types'),
|
||||
'async/mapLimit': __moduleId('async/mapLimit'),
|
||||
'qs': __moduleId('qs'),
|
||||
'path-to-regexp': __moduleId('path-to-regexp'),
|
||||
'history': __moduleId('history')
|
||||
|
7
mock/cfc/mock/upload/chunkApi.json
Normal file
7
mock/cfc/mock/upload/chunkApi.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"status": 0,
|
||||
"msg": "",
|
||||
"data": {
|
||||
"eTag": "016bd9b68ddd5cd7318875da3ea28207"
|
||||
}
|
||||
}
|
7
mock/cfc/mock/upload/finishChunkApi.json
Normal file
7
mock/cfc/mock/upload/finishChunkApi.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"status": 0,
|
||||
"msg": "",
|
||||
"data": {
|
||||
"value": "https://xxxx.cdn.bcebos.com/images/JSSDK_page-xxxxx.zip"
|
||||
}
|
||||
}
|
8
mock/cfc/mock/upload/startChunkApi.json
Normal file
8
mock/cfc/mock/upload/startChunkApi.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"status": 0,
|
||||
"msg": "",
|
||||
"data": {
|
||||
"key": "images/JSSDK_page-xxxx.zip",
|
||||
"uploadId": "036f64cd5dd95750d4bcb33556b629c6"
|
||||
}
|
||||
}
|
@ -45,7 +45,6 @@
|
||||
"dependencies": {
|
||||
"amis-formula": "^1.3.13",
|
||||
"ansi-to-react": "^6.1.6",
|
||||
"async": "2.6.0",
|
||||
"attr-accept": "2.2.2",
|
||||
"blueimp-canvastoblob": "2.1.0",
|
||||
"classnames": "2.3.1",
|
||||
|
@ -2,8 +2,6 @@ import React from 'react';
|
||||
import {FormItem, FormControlProps, FormBaseControl} from './Item';
|
||||
import find from 'lodash/find';
|
||||
import isPlainObject from 'lodash/isPlainObject';
|
||||
// @ts-ignore
|
||||
import mapLimit from 'async/mapLimit';
|
||||
import ImageControl from './InputImage';
|
||||
import {Payload, ApiObject, ApiString, Action} from '../../types';
|
||||
import {filter} from '../../utils/tpl';
|
||||
@ -83,6 +81,11 @@ export interface FileControlSchema extends FormBaseControl {
|
||||
*/
|
||||
chunkSize?: number;
|
||||
|
||||
/**
|
||||
* 分块上传的并发数
|
||||
*/
|
||||
concurrency?: number;
|
||||
|
||||
/**
|
||||
* 分割符
|
||||
*/
|
||||
@ -302,6 +305,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
startChunkApi: '/api/upload/startChunk',
|
||||
chunkApi: '/api/upload/chunk',
|
||||
finishChunkApi: '/api/upload/finishChunk',
|
||||
concurrency: 3,
|
||||
accept: '',
|
||||
multiple: false,
|
||||
autoUpload: true,
|
||||
@ -979,6 +983,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
onProgress: (progress: number) => void
|
||||
): Promise<Payload> {
|
||||
const chunkSize = config.chunkSize || 5 * 1024 * 1024;
|
||||
const concurrency = this.props.concurrency;
|
||||
const self = this;
|
||||
let startProgress = 0.2;
|
||||
let endProgress = 0.9;
|
||||
@ -1020,7 +1025,7 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
|
||||
self._send(file, startApi).then(startChunk).catch(reject);
|
||||
|
||||
function startChunk(ret: Payload) {
|
||||
async function startChunk(ret: Payload) {
|
||||
onProgress(startProgress);
|
||||
const tasks = getTasks(file);
|
||||
progressArr = tasks.map(() => 0);
|
||||
@ -1036,18 +1041,25 @@ export default class FileControl extends React.Component<FileProps, FileState> {
|
||||
total: tasks.length
|
||||
};
|
||||
|
||||
mapLimit(
|
||||
tasks,
|
||||
3,
|
||||
uploadPartFile(state, config),
|
||||
function (err: any, results: any) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
finishChunk(results, state);
|
||||
}
|
||||
}
|
||||
);
|
||||
let results: any[] = [];
|
||||
while (tasks.length) {
|
||||
const res = await Promise.all(
|
||||
tasks.splice(0, concurrency).map(async task => {
|
||||
return await uploadPartFile(state, config)(
|
||||
task,
|
||||
(err: any, value: any) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
throw new Error(err);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
results = results.concat(res);
|
||||
}
|
||||
finishChunk(results, state);
|
||||
}
|
||||
|
||||
function updateProgress(partNumber: number, progress: number) {
|
||||
|
Loading…
Reference in New Issue
Block a user