Browse Source

:sparkles: add options.upload.setHeaders

Liyuan Li 5 years ago
parent
commit
3f1c4bfbcc
3 changed files with 7 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 3 0
      src/ts/upload/setHeaders.ts
  3. 3 0
      types/index.d.ts

+ 1 - 0
CHANGELOG.md

@@ -88,6 +88,7 @@
   * `options.counter` 修改为 `counter?: { enable: boolean; max?: number; type: "md" | "text"; }`
   * counter 位置移动到 toolbar 上
   * `options.hideToolbar` 修改为 `toolbarConfig: { hide?: boolean, pin?: boolean }`
+  * 添加 `options.upload.setHeaders: { [key: string]: string }`
 
 ### v3.0.12 / 2020-04-06
 

+ 3 - 0
src/ts/upload/setHeaders.ts

@@ -1,4 +1,7 @@
 export const setHeaders = (vditor: IVditor, xhr: XMLHttpRequest) => {
+    if (vditor.options.upload.setHeaders) {
+        vditor.options.upload.headers =  vditor.options.upload.setHeaders();
+    }
     if (vditor.options.upload.headers) {
         Object.keys(vditor.options.upload.headers).forEach((key) => {
             xhr.setRequestHeader(key, vditor.options.upload.headers[key]);

+ 3 - 0
types/index.d.ts

@@ -138,6 +138,9 @@ interface IUpload {
     /** 请求头设置 */
     headers?: { [key: string]: string };
 
+    /** 每次上传前都会重新设置请求头 */
+    setHeaders(): { [key: string]: string };
+
     /** 上传成功回调 */
     success?(editor: HTMLPreElement, msg: string): void;