refactor: delegate media asset upload runtime

This commit is contained in:
lix-2026
2026-05-25 02:24:48 +08:00
parent a3abeadfe8
commit d22c45dfa5
4 changed files with 92 additions and 2 deletions
@@ -4014,6 +4014,25 @@ const SIDEBAR_TREE_JS: &str = r##"
}
async function uploadFileToMediaAsset(file, plan, options) {
var runtimeFn = localUploadRuntimeFunction('uploadFileToMediaAsset');
if (runtimeFn) {
return await runtimeFn(file, plan, options || {}, {
currentSourceKind: currentSourceKind,
currentRootUri: currentRootUri,
currentDocumentId: currentDocumentId,
editorRootFromUploadOptions: editorRootFromUploadOptions,
appendUploadedAssetRow: appendUploadedAssetRow,
refreshLocalFolderSidebarSnapshot: refreshLocalFolderSidebarSnapshot,
dispatchEvent: function(event) { return window.dispatchEvent(event); },
CustomEvent: CustomEvent,
buildOnlyOfficeAssetOpenUrl: buildOnlyOfficeAssetOpenUrl,
fetchCurrentOnlyOfficeUserId: fetchCurrentOnlyOfficeUserId,
buildOnlyOfficeOpenPath: buildOnlyOfficeOpenPath,
inferOnlyOfficeFileType: inferOnlyOfficeFileType,
enhanceEditorAttachmentLinks: enhanceEditorAttachmentLinks,
cssEscape: cssEscape
});
}
if (currentSourceKind() === 'local_folder') {
var rootUri = currentRootUri();
var documentId = String(plan && plan.targetDocumentId || currentDocumentId() || '').trim();
@@ -10972,6 +10991,7 @@ mod tests {
assert!(
SIDEBAR_TREE_JS.contains("localUploadRuntimeFunction('insertUploadedAssetIntoEditor')")
);
assert!(SIDEBAR_TREE_JS.contains("localUploadRuntimeFunction('uploadFileToMediaAsset')"));
assert!(SIDEBAR_TREE_JS.contains("localUploadRuntimeFunction('uploadMediaAsset')"));
assert!(
SIDEBAR_TREE_JS.contains("localUploadRuntimeFunction('uploadFilesWithResolvedTarget')")
@@ -10993,8 +11013,10 @@ mod tests {
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("function uploadLocalFolderAsset"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("function uploadMediaAsset"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("function insertUploadedAssetIntoEditor"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("function uploadFileToMediaAsset"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("function uploadFilesWithResolvedTarget"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("data-mnote-last-upload-inserted"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("uploadFileToMediaAsset: uploadFileToMediaAsset"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("uploadFilesWithResolvedTarget"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("__mnoteLastEditorUploadRoot"));
}