feat: consolidate local-first mnote web runtime
This commit is contained in:
@@ -2,24 +2,24 @@ use crate::app::AppState;
|
||||
use crate::context::RequestContext;
|
||||
use crate::error::WebError;
|
||||
use crate::routes::command_support::{
|
||||
execute_runtime_command_via_convex_with_artifacts, runtime_context,
|
||||
execute_runtime_command_via_legacy_cloud_with_artifacts, runtime_context,
|
||||
};
|
||||
use crate::routes::local_folder_source::{
|
||||
ensure_local_workspace_access, execute_local_tree_command,
|
||||
};
|
||||
use crate::transport::convex::{
|
||||
execute_convex_mutation_by_name, execute_convex_query_by_name,
|
||||
execute_retired_mutation_by_name, execute_retired_query_by_name,
|
||||
persist_runtime_command_artifacts,
|
||||
};
|
||||
use axum::Json;
|
||||
use axum::extract::{Extension, Path, Query, State};
|
||||
use axum::http::{HeaderMap, HeaderName, HeaderValue, StatusCode};
|
||||
use axum::Json;
|
||||
use bridge_runtime::{
|
||||
build_runtime_command_artifact_plan, RuntimeActorWire, RuntimeCommandEnvelopeWire,
|
||||
RuntimeCommandExecutionPlan, RuntimeSourceWire, RuntimeTargetWire,
|
||||
RuntimeActorWire, RuntimeCommandEnvelopeWire, RuntimeCommandExecutionPlan, RuntimeSourceWire,
|
||||
RuntimeTargetWire, build_runtime_command_artifact_plan,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
use time::{Duration, OffsetDateTime};
|
||||
|
||||
@@ -118,7 +118,7 @@ async fn current_user_id(state: &AppState, context: &RequestContext) -> String {
|
||||
})
|
||||
.unwrap_or(false);
|
||||
if has_auth_cookie {
|
||||
if let Ok(user) = execute_convex_query_by_name(
|
||||
if let Ok(user) = execute_retired_query_by_name(
|
||||
state.config(),
|
||||
context,
|
||||
"users:currentUser",
|
||||
@@ -372,7 +372,7 @@ async fn fetch_document_workspace_id(
|
||||
context: &RequestContext,
|
||||
document_id: &str,
|
||||
) -> Option<String> {
|
||||
execute_convex_query_by_name(
|
||||
execute_retired_query_by_name(
|
||||
state.config(),
|
||||
context,
|
||||
"documents:getMeta",
|
||||
@@ -401,7 +401,7 @@ async fn fetch_table_meta(
|
||||
user_id: &str,
|
||||
table_id: &str,
|
||||
) -> Option<Value> {
|
||||
execute_convex_query_by_name(
|
||||
execute_retired_query_by_name(
|
||||
state.config(),
|
||||
context,
|
||||
"tables:get",
|
||||
@@ -479,7 +479,7 @@ async fn fetch_media_asset_meta(
|
||||
user_id: &str,
|
||||
asset_id: &str,
|
||||
) -> Result<Value, WebError> {
|
||||
let assets = execute_convex_query_by_name(
|
||||
let assets = execute_retired_query_by_name(
|
||||
state.config(),
|
||||
context,
|
||||
"mediaAssets:listByIds",
|
||||
@@ -606,7 +606,7 @@ pub async fn media_batch(
|
||||
body.new_name.as_deref().unwrap_or_default(),
|
||||
"newName",
|
||||
)?;
|
||||
execute_convex_mutation_by_name(
|
||||
execute_retired_mutation_by_name(
|
||||
state.config(),
|
||||
&context,
|
||||
"mediaAssets:patchById",
|
||||
@@ -629,7 +629,7 @@ pub async fn media_batch(
|
||||
body.target_document_id.as_deref().unwrap_or_default(),
|
||||
"targetDocumentId",
|
||||
)?;
|
||||
execute_convex_mutation_by_name(
|
||||
execute_retired_mutation_by_name(
|
||||
state.config(),
|
||||
&context,
|
||||
"mediaAssets:patchById",
|
||||
@@ -646,7 +646,7 @@ pub async fn media_batch(
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
let command_result = execute_runtime_command_via_convex_with_artifacts(
|
||||
let command_result = execute_runtime_command_via_legacy_cloud_with_artifacts(
|
||||
&state,
|
||||
&context,
|
||||
workspace_id.as_deref(),
|
||||
@@ -712,7 +712,7 @@ pub async fn media_purge(
|
||||
"assetId": asset_id,
|
||||
}),
|
||||
);
|
||||
let execution = execute_runtime_command_via_convex_with_artifacts(
|
||||
let execution = execute_runtime_command_via_legacy_cloud_with_artifacts(
|
||||
&state,
|
||||
&context,
|
||||
workspace_id.as_deref(),
|
||||
@@ -729,7 +729,7 @@ pub async fn media_empty_trash(
|
||||
) -> Result<(StatusCode, HeaderMap, Json<Value>), WebError> {
|
||||
let user_id = current_user_id(&state, &context).await;
|
||||
let workspace_id = require_id(&context, &body.workspace_id, "workspaceId")?;
|
||||
let result = execute_convex_mutation_by_name(
|
||||
let result = execute_retired_mutation_by_name(
|
||||
state.config(),
|
||||
&context,
|
||||
"mediaAssets:emptyTrashByWorkspace",
|
||||
@@ -812,7 +812,7 @@ pub async fn mindmap_delete(
|
||||
"mindmapId": mindmap_id,
|
||||
}),
|
||||
);
|
||||
let execution = execute_runtime_command_via_convex_with_artifacts(
|
||||
let execution = execute_runtime_command_via_legacy_cloud_with_artifacts(
|
||||
&state,
|
||||
&context,
|
||||
workspace_id.as_deref(),
|
||||
@@ -897,7 +897,7 @@ pub async fn mindmap_trash_action(
|
||||
"mindmapId": mindmap_id,
|
||||
}),
|
||||
);
|
||||
let execution = execute_runtime_command_via_convex_with_artifacts(
|
||||
let execution = execute_runtime_command_via_legacy_cloud_with_artifacts(
|
||||
&state,
|
||||
&context,
|
||||
workspace_id.as_deref(),
|
||||
@@ -916,7 +916,7 @@ pub async fn mindmap_empty_trash(
|
||||
Json(body): Json<WorkspaceTrashRequest>,
|
||||
) -> Result<(StatusCode, HeaderMap, Json<Value>), WebError> {
|
||||
let workspace_id = require_id(&context, &body.workspace_id, "workspaceId")?;
|
||||
let result = execute_convex_mutation_by_name(
|
||||
let result = execute_retired_mutation_by_name(
|
||||
state.config(),
|
||||
&context,
|
||||
"mindmaps:emptyTrashByWorkspace",
|
||||
@@ -980,7 +980,7 @@ pub async fn table_create(
|
||||
.with_context(&context)
|
||||
.with_header(HEADER_MNOTE_WEB_OWNER, "mnote-web")
|
||||
})?;
|
||||
let result = execute_convex_mutation_by_name(
|
||||
let result = execute_retired_mutation_by_name(
|
||||
state.config(),
|
||||
&context,
|
||||
"tables:create",
|
||||
@@ -1087,7 +1087,7 @@ async fn table_action(
|
||||
"tableId": table_id,
|
||||
}),
|
||||
);
|
||||
let execution = execute_runtime_command_via_convex_with_artifacts(
|
||||
let execution = execute_runtime_command_via_legacy_cloud_with_artifacts(
|
||||
&state,
|
||||
&context,
|
||||
workspace_id.as_deref(),
|
||||
@@ -1108,7 +1108,7 @@ pub async fn table_empty_trash(
|
||||
) -> Result<(StatusCode, HeaderMap, Json<Value>), WebError> {
|
||||
let user_id = current_user_id(&state, &context).await;
|
||||
let workspace_id = require_id(&context, &body.workspace_id, "workspaceId")?;
|
||||
let result = execute_convex_mutation_by_name(
|
||||
let result = execute_retired_mutation_by_name(
|
||||
state.config(),
|
||||
&context,
|
||||
"tables:emptyTrashByWorkspace",
|
||||
@@ -1148,8 +1148,8 @@ pub async fn table_empty_trash(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::{build_app, AppConfig, AppState};
|
||||
use axum::body::{to_bytes, Body};
|
||||
use crate::app::{AppConfig, AppState, build_app};
|
||||
use axum::body::{Body, to_bytes};
|
||||
use axum::http::Request;
|
||||
use tower::util::ServiceExt;
|
||||
|
||||
@@ -1311,11 +1311,12 @@ mod tests {
|
||||
);
|
||||
assert_eq!(payload["result"]["sourceKind"], "local_folder");
|
||||
assert!(!root.join("Page").join("map.mindmap.json").exists());
|
||||
assert!(root
|
||||
.join(".mnote")
|
||||
.join("trash")
|
||||
.join("map.mindmap.json")
|
||||
.exists());
|
||||
assert!(
|
||||
root.join(".mnote")
|
||||
.join("trash")
|
||||
.join("map.mindmap.json")
|
||||
.exists()
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(&markdown_path).expect("read markdown after trash"),
|
||||
original_markdown,
|
||||
@@ -1421,11 +1422,13 @@ mod tests {
|
||||
purged_payload["result"]["canonicalCommand"],
|
||||
"tree.resource.purge"
|
||||
);
|
||||
assert!(!root
|
||||
.join(".mnote")
|
||||
.join("trash")
|
||||
.join("map.mindmap.json")
|
||||
.exists());
|
||||
assert!(
|
||||
!root
|
||||
.join(".mnote")
|
||||
.join("trash")
|
||||
.join("map.mindmap.json")
|
||||
.exists()
|
||||
);
|
||||
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user