refactor: extract mindmap fetch helpers

This commit is contained in:
lix-2026
2026-05-25 09:38:50 +08:00
parent 812504924f
commit 863e68b126
3 changed files with 141 additions and 24 deletions
+45 -9
View File
@@ -3133,16 +3133,24 @@ const SIDEBAR_TREE_JS: &str = r##"
}
async function preflightFileTreeUploadTarget(detail) {
var workspaceId = String(detail && detail.workspaceId || resolveWorkspaceId(document.body) || '').trim();
var body = {
workspaceId: workspaceId || null,
targetDocumentId: detail && detail.documentId ? String(detail.documentId) : null,
targetRowId: detail && detail.targetRowId ? String(detail.targetRowId) : null,
var bodyRuntime = fileTreeRuntimeFunction('fileTreeUploadTargetPreflightBody');
var body = bodyRuntime ? bodyRuntime(detail || {}, Object.assign({}, fileTreeRuntimeDeps(), {
focusedRowId: sidebarFileTreeSelection.focusedRowId || null,
activeDocumentId: currentDocumentId() || null,
rows: fileTreeRowsForUploadPreflight(),
documentWorkspaces: fileTreeDocumentWorkspacesForUploadPreflight(workspaceId)
};
fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight,
currentDocumentId: currentDocumentId,
resolveWorkspaceId: resolveWorkspaceId
})) : (function() {
var workspaceId = String(detail && detail.workspaceId || resolveWorkspaceId(document.body) || '').trim();
return {
workspaceId: workspaceId || null,
targetDocumentId: detail && detail.documentId ? String(detail.documentId) : null,
targetRowId: detail && detail.targetRowId ? String(detail.targetRowId) : null,
focusedRowId: sidebarFileTreeSelection.focusedRowId || null,
activeDocumentId: currentDocumentId() || null,
rows: fileTreeRowsForUploadPreflight(),
documentWorkspaces: fileTreeDocumentWorkspacesForUploadPreflight(workspaceId)
};
})();
var response = await fetch('/api/tree/filetree/upload-target-preflight', {
method: 'POST',
credentials: 'include',
@@ -3743,6 +3751,8 @@ const SIDEBAR_TREE_JS: &str = r##"
}
function shortMindmapFileName(mindmapId) {
var runtimeFn = fileTreeRuntimeFunction('shortMindmapFileName');
if (runtimeFn) return runtimeFn(mindmapId);
var raw = String(mindmapId || '').trim();
var pathName = raw.indexOf('/') >= 0 ? raw.split('/').pop() : raw;
if (/\.json$/i.test(pathName)) return pathName;
@@ -3752,6 +3762,8 @@ const SIDEBAR_TREE_JS: &str = r##"
}
function parseMindmapApiTarget(input) {
var runtimeFn = fileTreeRuntimeFunction('parseMindmapApiTarget');
if (runtimeFn) return runtimeFn(input);
try {
var rawUrl = typeof input === 'string'
? input
@@ -3793,6 +3805,8 @@ const SIDEBAR_TREE_JS: &str = r##"
}
function requestMethod(input, init) {
var runtimeFn = fileTreeRuntimeFunction('requestMethod');
if (runtimeFn) return runtimeFn(input, init);
return String(
init && init.method
? init.method
@@ -3803,6 +3817,8 @@ const SIDEBAR_TREE_JS: &str = r##"
}
function requestBodyHasMindmapCreateOnly(init) {
var runtimeFn = fileTreeRuntimeFunction('requestBodyHasMindmapCreateOnly');
if (runtimeFn) return runtimeFn(init);
var body = init && typeof init.body === 'string' ? init.body : '';
if (!body) return false;
try {
@@ -11195,6 +11211,11 @@ mod tests {
assert!(
FILETREE_RUNTIME_JS.contains("function fileTreeDocumentWorkspacesForUploadPreflight")
);
assert!(FILETREE_RUNTIME_JS.contains("function fileTreeUploadTargetPreflightBody"));
assert!(FILETREE_RUNTIME_JS.contains("function shortMindmapFileName"));
assert!(FILETREE_RUNTIME_JS.contains("function parseMindmapApiTarget"));
assert!(FILETREE_RUNTIME_JS.contains("function requestMethod"));
assert!(FILETREE_RUNTIME_JS.contains("function requestBodyHasMindmapCreateOnly"));
assert!(FILETREE_RUNTIME_JS.contains("function readProjection"));
assert!(FILETREE_RUNTIME_JS.contains("function readSidebarDataset"));
assert!(FILETREE_RUNTIME_JS.contains("function readDatasetProjection"));
@@ -11229,10 +11250,25 @@ mod tests {
assert!(FILETREE_RUNTIME_JS.contains(
"fileTreeDocumentWorkspacesForUploadPreflight: fileTreeDocumentWorkspacesForUploadPreflight"
));
assert!(FILETREE_RUNTIME_JS
.contains("fileTreeUploadTargetPreflightBody: fileTreeUploadTargetPreflightBody"));
assert!(FILETREE_RUNTIME_JS.contains("shortMindmapFileName: shortMindmapFileName"));
assert!(FILETREE_RUNTIME_JS.contains("parseMindmapApiTarget: parseMindmapApiTarget"));
assert!(FILETREE_RUNTIME_JS.contains("requestMethod: requestMethod"));
assert!(FILETREE_RUNTIME_JS
.contains("requestBodyHasMindmapCreateOnly: requestBodyHasMindmapCreateOnly"));
assert!(SIDEBAR_TREE_JS
.contains("fileTreeRuntimeFunction('fileTreeDocumentWorkspacesForUploadPreflight')"));
assert!(SIDEBAR_TREE_JS
.contains("fileTreeRuntimeFunction('fileTreeUploadTargetPreflightBody')"));
assert!(SIDEBAR_TREE_JS
.contains("fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight"));
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('shortMindmapFileName')"));
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('parseMindmapApiTarget')"));
assert!(SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('requestMethod')"));
assert!(
SIDEBAR_TREE_JS.contains("fileTreeRuntimeFunction('requestBodyHasMindmapCreateOnly')")
);
assert!(FILETREE_RUNTIME_JS
.contains("uploadIntent: String(detail.uploadIntent || 'filetree.folder.drop')"));
assert!(FILETREE_RUNTIME_JS