mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
🐛 msg upload
This commit is contained in:
parent
cc8e9bc25f
commit
fbaf8edea9
1 changed files with 11 additions and 9 deletions
|
|
@ -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 += `<li>${filename} ${window.siyuan.languages.uploading}</li>`;
|
||||
}
|
||||
}
|
||||
|
||||
let msgId
|
||||
if (errorTip !== "" || uploadingStr !== "") {
|
||||
showMessage(`<ul>${errorTip}${uploadingStr}</ul>`);
|
||||
msgId = showMessage(`<ul>${errorTip}${uploadingStr}</ul>`);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue