diff --git a/app/src/protyle/upload/index.ts b/app/src/protyle/upload/index.ts index 6dffba356..8f2699034 100644 --- a/app/src/protyle/upload/index.ts +++ b/app/src/protyle/upload/index.ts @@ -1,5 +1,5 @@ import {insertHTML} from "../util/insertHTML"; -import {showMessage} from "../../dialog/message"; +import {hideMessage, showMessage} from "../../dialog/message"; import {Constants} from "../../constants"; import {destroy} from "../util/destroy"; import {fetchPost} from "../../util/fetch"; @@ -65,12 +65,12 @@ const validateFile = (protyle: IProtyle, files: File[]) => { uploadingStr += `
  • ${filename} ${window.siyuan.languages.uploading}
  • `; } } - + let msgId if (errorTip !== "" || uploadingStr !== "") { - showMessage(``); + msgId = showMessage(``); } - return uploadFileList; + return {files: uploadFileList, msgId}; }; const genUploadedLabel = (responseText: string, protyle: IProtyle) => { @@ -96,7 +96,7 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => { } let succFileText = ""; - const keys = Object.keys(response.data.succMap); + const keys = Object.keys(response.data.succMap); keys.forEach((key, index) => { const path = response.data.succMap[key]; const lastIndex = key.lastIndexOf("."); @@ -130,11 +130,12 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => { }; export const uploadLocalFiles = (files: string[], protyle: IProtyle) => { - showMessage(window.siyuan.languages.uploading, 0); + const id = showMessage(window.siyuan.languages.uploading, 0); fetchPost("/api/asset/insertLocalAssets", { assetPaths: files, id: protyle.block.rootID }, (response) => { + hideMessage(id) genUploadedLabel(JSON.stringify(response), protyle); }); }; @@ -186,7 +187,7 @@ export const uploadFiles = (protyle: IProtyle, files: FileList | DataTransferIte const editorElement = protyle.wysiwyg.element; const validateResult = validateFile(protyle, fileList); - if (validateResult.length === 0) { + if (validateResult.files.length === 0) { if (element) { element.value = ""; } @@ -200,8 +201,8 @@ export const uploadFiles = (protyle: IProtyle, files: FileList | DataTransferIte formData.append(key, extraData[key]); } - for (let i = 0, iMax = validateResult.length; i < iMax; i++) { - formData.append(protyle.options.upload.fieldName, validateResult[i]); + for (let i = 0, iMax = validateResult.files.length; i < iMax; i++) { + formData.append(protyle.options.upload.fieldName, validateResult.files[i]); } formData.append("id", protyle.block.rootID); const xhr = new XMLHttpRequest(); @@ -223,6 +224,7 @@ export const uploadFiles = (protyle: IProtyle, files: FileList | DataTransferIte return; } if (xhr.status === 200) { + hideMessage(validateResult.msgId); if (protyle.options.upload.success) { protyle.options.upload.success(editorElement, xhr.responseText); } else if (successCB) {