fix: stabilize local attachment icons and office proxy urls

This commit is contained in:
lix-2026
2026-05-26 09:44:35 +08:00
parent 0a15595066
commit 8cd8b44db3
11 changed files with 564 additions and 14 deletions
@@ -405,10 +405,9 @@ pub async fn page(Query(query): Query<OnlyOfficePageQuery>) -> Result<Response,
mode: {mode}
}};
const MNOTE_AGENT_PLUGIN_GUID = "asc.{{05F87DDF-7B42-4C6F-9F2B-9C77A8D5F4E2}}";
const pageLocal = location.hostname === "127.0.0.1" || location.hostname === "localhost";
const documentUrlBase = {document_url_base};
const proxyOrigin = pageLocal ? documentUrlBase : location.origin;
const callbackOrigin = proxyOrigin;
const proxyOrigin = documentUrlBase;
const callbackOrigin = documentUrlBase;
function showError(message) {{
window.__MNOTE_ONLYOFFICE_ERRLOG__.push({{ kind: "error", message: String(message || "") }});
@@ -1821,7 +1820,11 @@ mod tests {
.expect("body");
let html = String::from_utf8(body.to_vec()).expect("html");
assert!(html.contains("const documentUrlBase = \"http://host.docker.internal:3000\";"));
assert!(html.contains("const proxyOrigin = pageLocal ? documentUrlBase : location.origin;"));
assert!(html.contains("const proxyOrigin = documentUrlBase;"));
assert!(html.contains("const callbackOrigin = documentUrlBase;"));
assert!(
!html.contains("const proxyOrigin = pageLocal ? documentUrlBase : location.origin;")
);
assert!(html.contains("documentUrlBase,"));
assert!(html.contains("resolvedFileUrl: fileState.resolvedFileUrl"));
}
@@ -1927,6 +1927,10 @@ mod tests {
assert!(
conversion_runtime.contains("localizeTiptapAssetUrls(toTiptapDocument(body.content")
);
assert!(conversion_runtime.contains("localAttachmentClassForTiptapHref"));
assert!(conversion_runtime.contains("mnote-uploaded-attachment-code"));
assert!(conversion_runtime
.contains("class: mergeClassNames(mark.attrs.class, attachmentClass)"));
assert!(session_runtime
.contains("const nextTiptapDocument = pageBodyTiptapDocument(nextBody, '', session);"));
assert!(session_runtime.contains(
@@ -2400,6 +2404,9 @@ mod tests {
assert!(
DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("document-tiptap-conversion-runtime.js")
);
assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("enhanceEditorAttachmentLinksSoon"));
assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS
.contains("window.__mnoteEnhanceEditorAttachmentLinks"));
assert!(DOCUMENT_TIPTAP_CONVERSION_RUNTIME_JS.contains("legacyInlineContentToTiptap"));
assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("openSecondaryDocument"));
assert!(DOCUMENT_EDITOR_ADAPTER_RUNTIME_JS.contains("openPrimaryMindmap"));
@@ -575,6 +575,13 @@ 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 dispatchUploadedEditorChange"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("function persistUploadedEditorChange"));
assert!(
LOCAL_UPLOAD_RUNTIME_JS.contains("function persistLocalFolderSelfChangeSuppression")
);
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("editorSource: 'local-upload-runtime'"));
assert!(LOCAL_UPLOAD_RUNTIME_JS.contains("mnote:leptos-tiptap-spike:change"));
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"));
@@ -1211,6 +1218,19 @@ mod tests {
assert!(SIDEBAR_FILETREE_OPEN_RUNTIME_JS
.contains("if (isCodeAttachmentFileName(fileName) && String(asset.document_id"));
assert!(SIDEBAR_FILETREE_OPEN_RUNTIME_JS.contains("await openCodeEditorAttachment({"));
let attachment_class_index = SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS
.find("attachmentClassForFileName(fileName).split")
.expect("editor attachment links apply type-specific classes");
let local_refresh_index = SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS
.find("if (localFilePath && !isOnlyOfficeAttachmentHref(href))")
.expect("local file links refresh existence after enhancement");
assert!(attachment_class_index < local_refresh_index);
assert!(SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS.contains("'mnote:leptos-tiptap-spike:ready'"));
assert!(SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS.contains("window.setTimeout(function()"));
assert!(SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS.contains("[120, 500, 1200, 2500]"));
assert!(
SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS.contains("attachmentInitialEnhanceAttempts >= 120")
);
}
#[test]