refactor: extract mindmap fetch helpers
This commit is contained in:
@@ -490,6 +490,79 @@ function fileTreeDocumentWorkspacesForUploadPreflight(workspaceId, deps) {
|
||||
});
|
||||
}
|
||||
|
||||
function fileTreeUploadTargetPreflightBody(detail, deps) {
|
||||
detail = detail || {};
|
||||
deps = deps || {};
|
||||
var resolveWorkspaceId = typeof deps.resolveWorkspaceId === 'function' ? deps.resolveWorkspaceId : function() { return ''; };
|
||||
var currentDocumentId = typeof deps.currentDocumentId === 'function' ? deps.currentDocumentId : function() { return ''; };
|
||||
var workspaceId = String(detail.workspaceId || resolveWorkspaceId(document.body) || '').trim();
|
||||
var rows = typeof deps.fileTreeRowsForUploadPreflight === 'function'
|
||||
? deps.fileTreeRowsForUploadPreflight()
|
||||
: fileTreeRowsForUploadPreflight(deps);
|
||||
var documentWorkspaces = fileTreeDocumentWorkspacesForUploadPreflight(workspaceId, Object.assign({}, deps, {
|
||||
fileTreeRowsForUploadPreflight: function() { return rows; }
|
||||
}));
|
||||
return {
|
||||
workspaceId: workspaceId || null,
|
||||
targetDocumentId: detail.documentId ? String(detail.documentId) : null,
|
||||
targetRowId: detail.targetRowId ? String(detail.targetRowId) : null,
|
||||
focusedRowId: deps.focusedRowId || null,
|
||||
activeDocumentId: currentDocumentId() || null,
|
||||
rows: rows,
|
||||
documentWorkspaces: documentWorkspaces
|
||||
};
|
||||
}
|
||||
|
||||
function shortMindmapFileName(mindmapId) {
|
||||
var raw = String(mindmapId || '').trim();
|
||||
var pathName = raw.indexOf('/') >= 0 ? raw.split('/').pop() : raw;
|
||||
if (/\.json$/i.test(pathName)) return pathName;
|
||||
var digits = raw.match(/(\d{4,})$/);
|
||||
var suffix = digits ? digits[1].slice(-6) : '';
|
||||
return suffix ? '思维导图' + suffix + '.json' : '思维导图.json';
|
||||
}
|
||||
|
||||
function parseMindmapApiTarget(input) {
|
||||
try {
|
||||
var rawUrl = typeof input === 'string'
|
||||
? input
|
||||
: input && typeof input.url === 'string'
|
||||
? input.url
|
||||
: '';
|
||||
if (!rawUrl) return null;
|
||||
var url = new URL(rawUrl, window.location.origin);
|
||||
var match = /^\/api\/mindmap\/([^/]+)\/([^/]+)$/.exec(url.pathname);
|
||||
if (!match) return null;
|
||||
return {
|
||||
documentId: decodeURIComponent(match[1]),
|
||||
mindmapId: decodeURIComponent(match[2])
|
||||
};
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function requestMethod(input, init) {
|
||||
return String(
|
||||
init && init.method
|
||||
? init.method
|
||||
: input && typeof input.method === 'string'
|
||||
? input.method
|
||||
: 'GET'
|
||||
).toUpperCase();
|
||||
}
|
||||
|
||||
function requestBodyHasMindmapCreateOnly(init) {
|
||||
var body = init && typeof init.body === 'string' ? init.body : '';
|
||||
if (!body) return false;
|
||||
try {
|
||||
var payload = JSON.parse(body);
|
||||
return payload && payload.createOnly === true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
window.__mnoteFileTreeRuntime = {
|
||||
readProjection: readProjection,
|
||||
readSidebarDataset: readSidebarDataset,
|
||||
@@ -525,5 +598,10 @@ window.__mnoteFileTreeRuntime = {
|
||||
fileTreeDocumentParentsForPreflight: fileTreeDocumentParentsForPreflight,
|
||||
fileTreeTargetChildrenForPreflight: fileTreeTargetChildrenForPreflight,
|
||||
fileTreeDropPreflightRows: fileTreeDropPreflightRows,
|
||||
fileTreeDocumentWorkspacesForUploadPreflight: fileTreeDocumentWorkspacesForUploadPreflight
|
||||
fileTreeDocumentWorkspacesForUploadPreflight: fileTreeDocumentWorkspacesForUploadPreflight,
|
||||
fileTreeUploadTargetPreflightBody: fileTreeUploadTargetPreflightBody,
|
||||
shortMindmapFileName: shortMindmapFileName,
|
||||
parseMindmapApiTarget: parseMindmapApiTarget,
|
||||
requestMethod: requestMethod,
|
||||
requestBodyHasMindmapCreateOnly: requestBodyHasMindmapCreateOnly
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user