fix: repair resource tab and slash menu regressions
This commit is contained in:
@@ -223,6 +223,13 @@ fn onlyoffice_internal_candidates() -> Vec<String> {
|
||||
candidates
|
||||
}
|
||||
|
||||
fn onlyoffice_document_url_base_js() -> String {
|
||||
env_or_dotenv("ONLYOFFICE_DOCUMENT_URL_BASE")
|
||||
.or_else(|| env_or_dotenv("MNOTE_WEB_ONLYOFFICE_INTERNAL_BASE_URL"))
|
||||
.and_then(|value| normalize_http_origin(&value))
|
||||
.unwrap_or_else(|| "http://host.docker.internal:3000".into())
|
||||
}
|
||||
|
||||
async fn resolve_onlyoffice_internal_url() -> String {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_millis(2_500))
|
||||
@@ -349,6 +356,7 @@ pub async fn page(Query(query): Query<OnlyOfficePageQuery>) -> Result<Response,
|
||||
Some("view") => "view",
|
||||
_ => "edit",
|
||||
};
|
||||
let document_url_base = onlyoffice_document_url_base_js();
|
||||
|
||||
let html = format!(
|
||||
r#"<!doctype html>
|
||||
@@ -384,7 +392,8 @@ pub async fn page(Query(query): Query<OnlyOfficePageQuery>) -> Result<Response,
|
||||
}};
|
||||
const MNOTE_AGENT_PLUGIN_GUID = "asc.{{05F87DDF-7B42-4C6F-9F2B-9C77A8D5F4E2}}";
|
||||
const pageLocal = location.hostname === "127.0.0.1" || location.hostname === "localhost";
|
||||
const proxyOrigin = pageLocal ? "http://host.docker.internal:3000" : location.origin;
|
||||
const documentUrlBase = {document_url_base};
|
||||
const proxyOrigin = pageLocal ? documentUrlBase : location.origin;
|
||||
const callbackOrigin = proxyOrigin;
|
||||
|
||||
function showError(message) {{
|
||||
@@ -592,6 +601,7 @@ pub async fn page(Query(query): Query<OnlyOfficePageQuery>) -> Result<Response,
|
||||
window.__MNOTE_ONLYOFFICE_DEBUG__ = {{
|
||||
pageOrigin: location.origin,
|
||||
baseUrl: "/onlyoffice-server",
|
||||
documentUrlBase,
|
||||
proxyOrigin,
|
||||
callbackOrigin,
|
||||
fileUrlInput: fileState.effectiveFileUrl,
|
||||
@@ -640,6 +650,7 @@ pub async fn page(Query(query): Query<OnlyOfficePageQuery>) -> Result<Response,
|
||||
document_id = json_string(&document_id),
|
||||
user_id = json_string(&user_id),
|
||||
mode = json_string(mode),
|
||||
document_url_base = json_string(&document_url_base),
|
||||
);
|
||||
|
||||
Ok(Html(html).into_response())
|
||||
@@ -1441,6 +1452,32 @@ mod tests {
|
||||
assert!(candidates.contains(&DEFAULT_ONLYOFFICE_INTERNAL_URL.to_string()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn onlyoffice_page_exposes_documentserver_fetch_base_for_local_files() {
|
||||
let response = page(Query(OnlyOfficePageQuery {
|
||||
file_url: Some(
|
||||
"http://localhost:3000/api/local-folder/files/open?rootUri=file:///tmp&path=Page/report.docx"
|
||||
.into(),
|
||||
),
|
||||
file_name: Some("report.docx".into()),
|
||||
file_type: Some("docx".into()),
|
||||
asset_id: Some("local-file:Page/report.docx".into()),
|
||||
document_id: Some("local-md:Page".into()),
|
||||
user_id: None,
|
||||
mode: Some("view".into()),
|
||||
}))
|
||||
.await
|
||||
.expect("onlyoffice page");
|
||||
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
||||
.await
|
||||
.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("documentUrlBase,"));
|
||||
assert!(html.contains("resolvedFileUrl: fileState.resolvedFileUrl"));
|
||||
}
|
||||
|
||||
fn test_state(legacy_next_base_url: Option<String>) -> AppState {
|
||||
AppState::new(AppConfig {
|
||||
service_name: "mnote-web".into(),
|
||||
|
||||
Reference in New Issue
Block a user