fix local folder upload intent contract

This commit is contained in:
lix-2026
2026-05-24 02:34:52 +08:00
parent 6d9d8ce9cd
commit ae6bbc9656
5 changed files with 136 additions and 29 deletions
+23 -6
View File
@@ -3073,7 +3073,8 @@ const SIDEBAR_TREE_JS: &str = r##"
targetDocumentId: documentId,
targetMindmapId: null,
targetSubPath: null,
targetRelativePath: String(detail.targetRelativePath || '')
targetRelativePath: String(detail.targetRelativePath || ''),
uploadIntent: String(detail.uploadIntent || 'filetree.folder.drop')
};
}
if (!workspaceId || !documentId) {
@@ -3083,7 +3084,8 @@ const SIDEBAR_TREE_JS: &str = r##"
workspaceId: workspaceId,
targetDocumentId: documentId,
targetMindmapId: null,
targetSubPath: null
targetSubPath: null,
uploadIntent: String(detail && detail.uploadIntent || 'editor.markdown.attach')
};
}
@@ -3096,6 +3098,13 @@ const SIDEBAR_TREE_JS: &str = r##"
if (detail && Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
plan.targetRelativePath = String(detail.targetRelativePath || '');
}
if (detail && detail.uploadIntent) {
plan.uploadIntent = String(detail.uploadIntent);
} else if (detail && Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
plan.uploadIntent = 'filetree.folder.drop';
} else if (!plan.uploadIntent) {
plan.uploadIntent = 'editor.markdown.attach';
}
return plan;
} catch (error) {
console.warn('[mnote upload] upload target preflight fallback', error);
@@ -3878,12 +3887,14 @@ const SIDEBAR_TREE_JS: &str = r##"
var rootUri = currentRootUri();
var documentId = String(plan && plan.targetDocumentId || currentDocumentId() || '').trim();
var hasFolderTarget = plan && Object.prototype.hasOwnProperty.call(plan, 'targetRelativePath');
if (!rootUri || (!documentId && !hasFolderTarget)) {
var uploadIntent = String(plan && plan.uploadIntent || (hasFolderTarget ? 'filetree.folder.drop' : 'editor.markdown.attach')).trim();
if (!rootUri || !uploadIntent) {
throw new Error(' Markdown rootUri documentId');
}
var localForm = new FormData();
localForm.append('file', file);
localForm.append('rootUri', rootUri);
localForm.append('uploadIntent', uploadIntent);
if (documentId) localForm.append('documentId', documentId);
if (hasFolderTarget) localForm.append('targetRelativePath', String(plan.targetRelativePath || ''));
localForm.append('kind', file && String(file.type || '').indexOf('image/') === 0 ? 'image' : 'attachment');
@@ -3969,7 +3980,8 @@ const SIDEBAR_TREE_JS: &str = r##"
void uploadFilesWithResolvedTarget(files, {
workspaceId: uploadContext.workspaceId || resolveWorkspaceId(document.body),
documentId: uploadContext.documentId || currentDocumentId(),
targetRowId: null
targetRowId: null,
uploadIntent: 'editor.markdown.attach'
}, {
insertIntoEditor: detail && detail.insertIntoEditor !== false,
editorRoot: uploadContext.root
@@ -4007,7 +4019,8 @@ const SIDEBAR_TREE_JS: &str = r##"
void uploadFilesWithResolvedTarget(files, {
workspaceId: resolveWorkspaceId(document.body),
documentId: currentDocumentId(),
targetRowId: null
targetRowId: null,
uploadIntent: 'editor.markdown.attach'
}, {
insertIntoEditor: true,
editorRoot: editorUploadRootFromElement(editorTarget)
@@ -10026,7 +10039,8 @@ const SIDEBAR_TREE_JS: &str = r##"
assetId: targetRow ? targetRow.getAttribute('data-asset-id') : null,
targetRelativePath: targetRow && (targetRow.getAttribute('data-row-kind') === 'folder' || targetRow.getAttribute('data-row-kind') === 'directory')
? fileTreeRowLocalRelativePath(targetRow)
: null
: null,
uploadIntent: 'filetree.folder.drop'
};
if (activeFileTreeDropRow instanceof HTMLElement) activeFileTreeDropRow.setAttribute('data-drop-target', 'false');
activeFileTreeDropRow = null;
@@ -10871,6 +10885,9 @@ mod tests {
"主编辑器上传应能从当前文档 DOM 回退解析 documentId"
);
assert!(SIDEBAR_TREE_JS.contains("localForm.append('rootUri', rootUri)"));
assert!(SIDEBAR_TREE_JS.contains("localForm.append('uploadIntent', uploadIntent)"));
assert!(SIDEBAR_TREE_JS.contains("uploadIntent: 'editor.markdown.attach'"));
assert!(SIDEBAR_TREE_JS.contains("uploadIntent: 'filetree.folder.drop'"));
assert!(SIDEBAR_TREE_JS.contains("localForm.append('documentId', documentId)"));
assert!(SIDEBAR_TREE_JS.contains("isLocalUploadedAsset(asset)"));
assert!(SIDEBAR_TREE_JS.contains("buildLocalOnlyOfficeOpenUrl"));