refactor: normalize filetree upload target plans

This commit is contained in:
lix-2026
2026-05-25 09:10:41 +08:00
parent 8b27bd45aa
commit c3b1aea30e
3 changed files with 37 additions and 1 deletions
@@ -371,6 +371,22 @@ function fileTreeUploadTargetFallback(detail, deps) {
};
}
function normalizeFileTreeUploadTargetPlan(detail, plan) {
detail = detail || {};
plan = plan && typeof plan === 'object' ? Object.assign({}, plan) : {};
if (Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
plan.targetRelativePath = String(detail.targetRelativePath || '');
}
if (detail.uploadIntent) {
plan.uploadIntent = String(detail.uploadIntent);
} else if (Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
plan.uploadIntent = 'filetree.folder.drop';
} else if (!plan.uploadIntent) {
plan.uploadIntent = 'editor.markdown.attach';
}
return plan;
}
function fileTreeRowsForUploadPreflight(deps) {
deps = deps || {};
var fileTreeRowKind = typeof deps.fileTreeRowKind === 'function' ? deps.fileTreeRowKind : function(row) {
@@ -489,6 +505,7 @@ window.__mnoteFileTreeRuntime = {
revealFileTreeAssetRow: revealFileTreeAssetRow,
appendUploadedAssetRow: appendUploadedAssetRow,
fileTreeUploadTargetFallback: fileTreeUploadTargetFallback,
normalizeFileTreeUploadTargetPlan: normalizeFileTreeUploadTargetPlan,
fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight,
fileTreeDocumentParentsForPreflight: fileTreeDocumentParentsForPreflight,
fileTreeTargetChildrenForPreflight: fileTreeTargetChildrenForPreflight,
@@ -3188,6 +3188,10 @@ const SIDEBAR_TREE_JS: &str = r##"
}
try {
var plan = await preflightFileTreeUploadTarget(detail || {});
var normalizePlanRuntime = fileTreeRuntimeFunction('normalizeFileTreeUploadTargetPlan');
if (normalizePlanRuntime) {
return normalizePlanRuntime(detail || {}, plan);
}
if (detail && Object.prototype.hasOwnProperty.call(detail, 'targetRelativePath')) {
plan.targetRelativePath = String(detail.targetRelativePath || '');
}