瀏覽代碼

:memo: https://github.com/Vanessa219/vditor/pull/1101

Vanessa 4 年之前
父節點
當前提交
ce22c41273
共有 4 個文件被更改,包括 6 次插入5 次删除
  1. 1 0
      CHANGELOG.md
  2. 2 2
      README.md
  3. 2 2
      README_en_US.md
  4. 1 1
      src/ts/upload/index.ts

+ 1 - 0
CHANGELOG.md

@@ -97,6 +97,7 @@
 
 ### v3.8.8 / 2021-10-xx
 
+* [1101](https://github.com/Vanessa219/vditor/pull/1101) 支持 options.upload.handler 异步 `改进功能`
 * [1089](https://github.com/Vanessa219/vditor/pull/1089) 解决内存泄漏问题 `开发重构`
 * [158](https://github.com/88250/lute/issues/158) Table 紧跟的上一行不是空行时,SpinVditorSVDOM 会将整个表格过滤掉 `修复缺陷`
 

+ 2 - 2
README.md

@@ -449,9 +449,9 @@ if (xhr.status === 200) {
 | filename(name: string): string | 文件名安全处理 | name => name.replace(/\W/g, '') |
 | accept | 文件上传类型,同[input accept](https://www.w3schools.com/tags/att_input_accept.asp) | - |
 | validate(files: File[]) => string \| boolean | 校验,成功时返回 true 否则返回错误信息 | - |
-| handler(files: File[]) => string \| null | 自定义上传,当发生错误时返回错误信息 | - |
+| handler(files: File[]) => string \| null \| Promise<string> \| Promise<null> | 自定义上传,当发生错误时返回错误信息 | - |
 | format(files: File[], responseText: string): string | 对服务端返回的数据进行转换,以满足内置的数据结构 | - |
-| file(files: File[]): File[] | 将上传的文件处理后再返回 | - |
+| file(files: File[]): File[] \| Promise<File[]> | 将上传的文件处理后再返回 | - |
 | setHeaders(): { [key: string]: string } | 上传前使用返回值设置头 | - |
 | extraData: { [key: string]: string \| Blob } | 为 FormData 添加额外的参数 | - |
 | multiple | 上传文件是否为多个 | true |

+ 2 - 2
README_en_US.md

@@ -403,9 +403,9 @@ xhr.send(JSON.stringify({url: src})); // src is the address of the image outside
 | filename | Sanitizing file names (name: string): string \| name => name.replace(/\W/g, '') |
 | accept | File upload type, same as [input accept](https://www.w3schools.com/tags/att_input_accept.asp) | - |
 | validate | Check, return true if successful, otherwise return error message (files: File[]) => string \| boolean | - |
-| handler | Custom upload, return error message when an error occurs (files: File[]) => string \| null | - |
+| handler(files: File[]) => string \| null \| Promise<string> \| Promise<null> | Custom upload, return error message when an error occurs | - |
 | format | Transform the data returned by the server to meet the built-in data structure (files: File[], responseText: string): string | - |
-| file | Process the uploaded file before returning (files: File[]): File[] | - |
+| file(files: File[]): File[] \| Promise<File[]> | Process the uploaded file before return. | - |
 | setHeaders | Use the return value to set the header before uploading (): { [key: string]: string } | - |
 | extraData | Append data to FormData { [key: string]: string | Blob } | - |
 | multiple | Allow multiple file uploads | true |

+ 1 - 1
src/ts/upload/index.ts

@@ -154,7 +154,7 @@ const uploadFiles =
         }
 
         if (vditor.options.upload.handler) {
-            const isValidate =await vditor.options.upload.handler(fileList);
+            const isValidate = await vditor.options.upload.handler(fileList);
             if (typeof isValidate === "string") {
                 vditor.tip.show(isValidate);
                 return;