瀏覽代碼

feat: 文件上传和文件处理支持异步进行 (#1101)

文件上传通常是异步进行的,handler应该支持异步结果
文件处理内部已经进行支持异步,但index.d.ts类型未能保持一致
myml 4 年之前
父節點
當前提交
e66320a68b
共有 2 個文件被更改,包括 3 次插入3 次删除
  1. 1 1
      src/ts/upload/index.ts
  2. 2 2
      types/index.d.ts

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

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

+ 2 - 2
types/index.d.ts

@@ -372,7 +372,7 @@ interface IUpload {
     validate?(files: File[]): string | boolean;
 
     /** 自定义上传,当发生错误时返回错误信息 */
-    handler?(files: File[]): string | null;
+    handler?(files: File[]): string | null | Promise<string> | Promise<null>;
 
     /** 对服务端返回的数据进行转换,以满足内置的数据结构 */
     format?(files: File[], responseText: string): string;
@@ -381,7 +381,7 @@ interface IUpload {
     linkToImgFormat?(responseText: string): string;
 
     /** 将上传的文件处理后再返回  */
-    file?(files: File[]): File[];
+    file?(files: File[]): File[] | Promise<File[]>;
 
     /** 图片地址上传后的回调  */
     linkToImgCallback?(responseText: string): void;