refactor: split sidebar filetree upload runtime

This commit is contained in:
lix-2026
2026-05-26 02:27:08 +08:00
parent 7909b3f9be
commit bc3b199c32
6 changed files with 348 additions and 270 deletions
+5
View File
@@ -142,6 +142,10 @@ pub fn build_router(state: AppState) -> Router {
"/api/mnote-browser-runtime/sidebar-filetree-command-runtime.js",
get(web_shell::sidebar_filetree_command_runtime_asset),
)
.route(
"/api/mnote-browser-runtime/sidebar-filetree-upload-runtime.js",
get(web_shell::sidebar_filetree_upload_runtime_asset),
)
.route(
"/api/mnote-browser-runtime/sidebar-attachment-open-runtime.js",
get(web_shell::sidebar_attachment_open_runtime_asset),
@@ -603,6 +607,7 @@ mod tests {
"/api/mnote-browser-runtime/sidebar-tree-live-apply-runtime.js",
"/api/mnote-browser-runtime/sidebar-filetree-open-runtime.js",
"/api/mnote-browser-runtime/sidebar-filetree-command-runtime.js",
"/api/mnote-browser-runtime/sidebar-filetree-upload-runtime.js",
"/api/mnote-browser-runtime/sidebar-attachment-open-runtime.js",
"/api/mnote-browser-runtime/sidebar-tree-runtime.js",
"/api/mnote-browser-runtime/tree-live-controller.js",
@@ -798,6 +798,20 @@ pub async fn sidebar_filetree_command_runtime_asset() -> Response {
.unwrap_or_else(|_| Response::new(Body::empty()))
}
pub async fn sidebar_filetree_upload_runtime_asset() -> Response {
const JS: &str = include_str!("../../browser/sidebar-filetree-upload-runtime.js");
Response::builder()
.status(StatusCode::OK)
.header(
header::CONTENT_TYPE,
"application/javascript; charset=utf-8",
)
.header(header::CACHE_CONTROL, "no-store")
.header(HEADER_MNOTE_WEB_OWNER, "mnote-web")
.body(Body::from(JS))
.unwrap_or_else(|_| Response::new(Body::empty()))
}
pub async fn sidebar_attachment_open_runtime_asset() -> Response {
const JS: &str = include_str!("../../browser/sidebar-attachment-open-runtime.js");
Response::builder()
+14 -12
View File
@@ -205,6 +205,8 @@ mod tests {
include_str!("../../../browser/sidebar-filetree-open-runtime.js");
const SIDEBAR_FILETREE_COMMAND_RUNTIME_JS: &str =
include_str!("../../../browser/sidebar-filetree-command-runtime.js");
const SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS: &str =
include_str!("../../../browser/sidebar-filetree-upload-runtime.js");
const SIDEBAR_ATTACHMENT_OPEN_RUNTIME_JS: &str =
include_str!("../../../browser/sidebar-attachment-open-runtime.js");
const SIDEBAR_SHELL_RUNTIME_JS: &str =
@@ -599,15 +601,15 @@ mod tests {
assert!(
SIDEBAR_TREE_RUNTIME_JS.contains("fileTreeRuntimeFunction('appendUploadedAssetRow')")
);
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeUploadTargetFallback')"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeRowsForUploadPreflight')"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeDocumentParentsForPreflight')"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeTargetChildrenForPreflight')"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeDropPreflightRows')"));
assert!(SIDEBAR_TREE_LIVE_APPLY_RUNTIME_JS
.contains("fileTreeRuntimeFunction('readProjection')"));
@@ -741,11 +743,11 @@ mod tests {
assert!(FILETREE_RUNTIME_JS.contains("requestMethod: requestMethod"));
assert!(FILETREE_RUNTIME_JS
.contains("requestBodyHasMindmapCreateOnly: requestBodyHasMindmapCreateOnly"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeDocumentWorkspacesForUploadPreflight')"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRuntimeFunction('fileTreeUploadTargetPreflightBody')"));
assert!(SIDEBAR_TREE_RUNTIME_JS
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS
.contains("fileTreeRowsForUploadPreflight: fileTreeRowsForUploadPreflight"));
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("fileTreeRuntimeFunction('shortMindmapFileName')"));
assert!(
@@ -1023,13 +1025,13 @@ mod tests {
#[test]
fn sidebar_filetree_blocks_readonly_paste_and_drop_with_action_status() {
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("function blockReadonlyFileTreeAction"));
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("data-mnote-filetree-readonly-blocked"));
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("data-mnote-filetree-readonly-message"));
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS.contains("function blockReadonlyFileTreeAction"));
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS.contains("data-mnote-filetree-readonly-blocked"));
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS.contains("data-mnote-filetree-readonly-message"));
assert!(
SIDEBAR_FILETREE_COMMAND_RUNTIME_JS.contains("recordFileTreeActionStatus('blocked'")
);
assert!(SIDEBAR_TREE_RUNTIME_JS.contains("/api/tree/filetree/drop-preflight"));
assert!(SIDEBAR_FILETREE_UPLOAD_RUNTIME_JS.contains("/api/tree/filetree/drop-preflight"));
assert!(
SIDEBAR_FILETREE_COMMAND_RUNTIME_JS.contains("ensureFileTreeWritableTarget('paste'")
);