Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: https://github.com/siyuan-note/siyuan/issues/5962

Vanessaab4125319286
diff --git a/app/src/protyle/upload/index.ts b/app/src/protyle/upload/index.ts
index 53b1175193..09e7c4168f 100644
--- a/app/src/protyle/upload/index.ts
+++ b/app/src/protyle/upload/index.ts
@@ -124,10 +124,11 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
insertHTML(protyle.lute.SpinBlockDOM(succFileText), protyle);
};
-export const uploadLocalFiles = (files: string[], protyle: IProtyle) => {
+export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload:boolean) => {
const msgId = showMessage(window.siyuan.languages.uploading, 0);
fetchPost("/api/asset/insertLocalAssets", {
assetPaths: files,
+ isUpload,
id: protyle.block.rootID
}, (response) => {
hideMessage(msgId);
@@ -145,7 +146,7 @@ export const uploadFiles = (protyle: IProtyle, files: FileList | DataTransferIte
}
if (0 === fileItem.size && "" === fileItem.type && -1 === fileItem.name.indexOf(".")) {
// 文件夹
- document.execCommand("insertHTML", false, `[${fileItem.name}](file://${fileItem.path})`);
+ uploadLocalFiles([fileItem.path], protyle, false);
} else {
fileList.push(fileItem);
}
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index ac87431c87..e3325765f1 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -706,27 +706,10 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
if (event.dataTransfer.types[0] === "Files") {
const files: string[] = [];
- let isAllFile = true;
for (let i = 0; i < event.dataTransfer.files.length; i++) {
files.push(event.dataTransfer.files[i].path);
- if (event.dataTransfer.files[i].type === "") {
- isAllFile = false;
- }
- }
- if (isAllFile) {
- if (event.altKey) {
- let fileText = "";
- files.forEach((item) => {
- // 拖入文件名包含 `)` 或 `]` 的文件以 `file://` 插入后链接解析错误 https://github.com/siyuan-note/siyuan/issues/5786
- fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
- });
- insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
- } else {
- uploadLocalFiles(files, protyle);
- }
- } else {
- uploadLocalFiles(files, protyle);
}
+ uploadLocalFiles(files, protyle, !event.altKey);
} else {
paste(protyle, event);
}
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index 4fd7fcd33f..0dd2671edf 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -48,11 +48,8 @@ export const pasteAsPlainText = async (protyle:IProtyle) => {
}
}
if (localFiles.length > 0) {
- let fileText = "";
- localFiles.forEach((item) => {
- fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
- });
- insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
+ uploadLocalFiles(localFiles, protyle, false);
+ writeText("");
} else {
insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.InlineMd2BlockDOM(clipboard.readText())), protyle, false, false);
}
@@ -124,7 +121,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
localFiles.push(item.childNodes[0].nodeValue);
});
if (localFiles.length > 0) {
- uploadLocalFiles(localFiles, protyle);
+ uploadLocalFiles(localFiles, protyle, true);
writeText("");
return;
}
@@ -132,7 +129,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
} else {
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
if (xmlString.data.length > 0) {
- uploadLocalFiles(xmlString.data, protyle);
+ uploadLocalFiles(xmlString.data, protyle, true);
writeText("");
return;
}