mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 09:48:28 +02:00
Increase gRPC max message sizes
This commit is contained in:
@@ -6,7 +6,10 @@ import { PluginHandle } from './PluginHandle';
|
|||||||
|
|
||||||
const port = process.env.PORT || '50051';
|
const port = process.env.PORT || '50051';
|
||||||
|
|
||||||
const channel = createChannel(`localhost:${port}`);
|
const channel = createChannel(`localhost:${port}`, undefined, {
|
||||||
|
'grpc.max_receive_message_length': Number.MAX_SAFE_INTEGER,
|
||||||
|
'grpc.max_send_message_length': Number.MAX_SAFE_INTEGER,
|
||||||
|
});
|
||||||
const client: PluginRuntimeClient = createClient(PluginRuntimeDefinition, channel);
|
const client: PluginRuntimeClient = createClient(PluginRuntimeDefinition, channel);
|
||||||
|
|
||||||
const events = new EventChannel();
|
const events = new EventChannel();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub struct PluginManager {
|
|||||||
subscribers: Arc<Mutex<HashMap<String, mpsc::Sender<InternalEvent>>>>,
|
subscribers: Arc<Mutex<HashMap<String, mpsc::Sender<InternalEvent>>>>,
|
||||||
plugins: Arc<Mutex<Vec<PluginHandle>>>,
|
plugins: Arc<Mutex<Vec<PluginHandle>>>,
|
||||||
kill_tx: tokio::sync::watch::Sender<bool>,
|
kill_tx: tokio::sync::watch::Sender<bool>,
|
||||||
server: Arc<PluginRuntimeServerImpl>,
|
grpc_service: Arc<PluginRuntimeServerImpl>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -47,13 +47,13 @@ impl PluginManager {
|
|||||||
|
|
||||||
let (client_disconnect_tx, mut client_disconnect_rx) = mpsc::channel(128);
|
let (client_disconnect_tx, mut client_disconnect_rx) = mpsc::channel(128);
|
||||||
let (client_connect_tx, mut client_connect_rx) = tokio::sync::watch::channel(false);
|
let (client_connect_tx, mut client_connect_rx) = tokio::sync::watch::channel(false);
|
||||||
let server =
|
let grpc_service =
|
||||||
PluginRuntimeServerImpl::new(events_tx, client_disconnect_tx, client_connect_tx);
|
PluginRuntimeServerImpl::new(events_tx, client_disconnect_tx, client_connect_tx);
|
||||||
|
|
||||||
let plugin_manager = PluginManager {
|
let plugin_manager = PluginManager {
|
||||||
plugins: Arc::new(Mutex::new(Vec::new())),
|
plugins: Arc::new(Mutex::new(Vec::new())),
|
||||||
subscribers: Arc::new(Mutex::new(HashMap::new())),
|
subscribers: Arc::new(Mutex::new(HashMap::new())),
|
||||||
server: Arc::new(server.clone()),
|
grpc_service: Arc::new(grpc_service.clone()),
|
||||||
kill_tx: kill_server_tx,
|
kill_tx: kill_server_tx,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,15 +78,15 @@ impl PluginManager {
|
|||||||
|
|
||||||
info!("Starting plugin server");
|
info!("Starting plugin server");
|
||||||
|
|
||||||
let svc = PluginRuntimeServer::new(server.to_owned());
|
let svc = PluginRuntimeServer::new(grpc_service.to_owned())
|
||||||
|
.max_encoding_message_size(usize::MAX)
|
||||||
|
.max_decoding_message_size(usize::MAX);
|
||||||
let listen_addr = match option_env!("PORT") {
|
let listen_addr = match option_env!("PORT") {
|
||||||
None => "localhost:0".to_string(),
|
None => "localhost:0".to_string(),
|
||||||
Some(port) => format!("localhost:{port}"),
|
Some(port) => format!("localhost:{port}"),
|
||||||
};
|
};
|
||||||
let listener = tauri::async_runtime::block_on(async move {
|
let listener = tauri::async_runtime::block_on(async move {
|
||||||
TcpListener::bind(listen_addr)
|
TcpListener::bind(listen_addr).await.expect("Failed to bind TCP listener")
|
||||||
.await
|
|
||||||
.expect("Failed to bind TCP listener")
|
|
||||||
});
|
});
|
||||||
let addr = listener.local_addr().expect("Failed to get local address");
|
let addr = listener.local_addr().expect("Failed to get local address");
|
||||||
|
|
||||||
@@ -123,9 +123,7 @@ impl PluginManager {
|
|||||||
|
|
||||||
// 2. Start Node.js runtime and initialize plugins
|
// 2. Start Node.js runtime and initialize plugins
|
||||||
tauri::async_runtime::block_on(async move {
|
tauri::async_runtime::block_on(async move {
|
||||||
start_nodejs_plugin_runtime(&app_handle, addr, &kill_server_rx)
|
start_nodejs_plugin_runtime(&app_handle, addr, &kill_server_rx).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin_manager
|
plugin_manager
|
||||||
@@ -173,10 +171,7 @@ impl PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn uninstall(&self, window_context: WindowContext, dir: &str) -> Result<()> {
|
pub async fn uninstall(&self, window_context: WindowContext, dir: &str) -> Result<()> {
|
||||||
let plugin = self
|
let plugin = self.get_plugin_by_dir(dir).await.ok_or(PluginNotFoundErr(dir.to_string()))?;
|
||||||
.get_plugin_by_dir(dir)
|
|
||||||
.await
|
|
||||||
.ok_or(PluginNotFoundErr(dir.to_string()))?;
|
|
||||||
self.remove_plugin(window_context, &plugin).await
|
self.remove_plugin(window_context, &plugin).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +200,7 @@ impl PluginManager {
|
|||||||
watch: bool,
|
watch: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
info!("Adding plugin by dir {dir}");
|
info!("Adding plugin by dir {dir}");
|
||||||
let maybe_tx = self.server.app_to_plugin_events_tx.lock().await;
|
let maybe_tx = self.grpc_service.app_to_plugin_events_tx.lock().await;
|
||||||
let tx = match &*maybe_tx {
|
let tx = match &*maybe_tx {
|
||||||
None => return Err(ClientNotInitializedErr),
|
None => return Err(ClientNotInitializedErr),
|
||||||
Some(tx) => tx,
|
Some(tx) => tx,
|
||||||
@@ -251,9 +246,8 @@ impl PluginManager {
|
|||||||
warn!("Failed to remove plugin {} {e:?}", d.dir);
|
warn!("Failed to remove plugin {} {e:?}", d.dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Err(e) = self
|
if let Err(e) =
|
||||||
.add_plugin_by_dir(window_context.to_owned(), d.dir.as_str(), d.watch)
|
self.add_plugin_by_dir(window_context.to_owned(), d.dir.as_str(), d.watch).await
|
||||||
.await
|
|
||||||
{
|
{
|
||||||
warn!("Failed to add plugin {} {e:?}", d.dir);
|
warn!("Failed to add plugin {} {e:?}", d.dir);
|
||||||
}
|
}
|
||||||
@@ -307,21 +301,11 @@ impl PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_plugin_by_ref_id(&self, ref_id: &str) -> Option<PluginHandle> {
|
pub async fn get_plugin_by_ref_id(&self, ref_id: &str) -> Option<PluginHandle> {
|
||||||
self.plugins
|
self.plugins.lock().await.iter().find(|p| p.ref_id == ref_id).cloned()
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.iter()
|
|
||||||
.find(|p| p.ref_id == ref_id)
|
|
||||||
.cloned()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_plugin_by_dir(&self, dir: &str) -> Option<PluginHandle> {
|
pub async fn get_plugin_by_dir(&self, dir: &str) -> Option<PluginHandle> {
|
||||||
self.plugins
|
self.plugins.lock().await.iter().find(|p| p.dir == dir).cloned()
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.iter()
|
|
||||||
.find(|p| p.dir == dir)
|
|
||||||
.cloned()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_plugin_by_name(&self, name: &str) -> Option<PluginHandle> {
|
pub async fn get_plugin_by_name(&self, name: &str) -> Option<PluginHandle> {
|
||||||
@@ -340,9 +324,8 @@ impl PluginManager {
|
|||||||
plugin: &PluginHandle,
|
plugin: &PluginHandle,
|
||||||
payload: &InternalEventPayload,
|
payload: &InternalEventPayload,
|
||||||
) -> Result<InternalEvent> {
|
) -> Result<InternalEvent> {
|
||||||
let events = self
|
let events =
|
||||||
.send_to_plugins_and_wait(window_context, payload, vec![plugin.to_owned()])
|
self.send_to_plugins_and_wait(window_context, payload, vec![plugin.to_owned()]).await?;
|
||||||
.await?;
|
|
||||||
Ok(events.first().unwrap().to_owned())
|
Ok(events.first().unwrap().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,8 +335,7 @@ impl PluginManager {
|
|||||||
payload: &InternalEventPayload,
|
payload: &InternalEventPayload,
|
||||||
) -> Result<Vec<InternalEvent>> {
|
) -> Result<Vec<InternalEvent>> {
|
||||||
let plugins = { self.plugins.lock().await.clone() };
|
let plugins = { self.plugins.lock().await.clone() };
|
||||||
self.send_to_plugins_and_wait(window_context, payload, plugins)
|
self.send_to_plugins_and_wait(window_context, payload, plugins).await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_to_plugins_and_wait(
|
async fn send_to_plugins_and_wait(
|
||||||
@@ -440,8 +422,7 @@ impl PluginManager {
|
|||||||
&self,
|
&self,
|
||||||
window: &WebviewWindow<R>,
|
window: &WebviewWindow<R>,
|
||||||
) -> Result<Vec<GetTemplateFunctionsResponse>> {
|
) -> Result<Vec<GetTemplateFunctionsResponse>> {
|
||||||
self.get_template_functions_with_context(WindowContext::from_window(window))
|
self.get_template_functions_with_context(WindowContext::from_window(window)).await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_template_functions_with_context(
|
pub async fn get_template_functions_with_context(
|
||||||
@@ -449,10 +430,7 @@ impl PluginManager {
|
|||||||
window_context: WindowContext,
|
window_context: WindowContext,
|
||||||
) -> Result<Vec<GetTemplateFunctionsResponse>> {
|
) -> Result<Vec<GetTemplateFunctionsResponse>> {
|
||||||
let reply_events = self
|
let reply_events = self
|
||||||
.send_and_wait(
|
.send_and_wait(window_context, &InternalEventPayload::GetTemplateFunctionsRequest)
|
||||||
window_context,
|
|
||||||
&InternalEventPayload::GetTemplateFunctionsRequest,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut all_actions = Vec::new();
|
let mut all_actions = Vec::new();
|
||||||
@@ -471,10 +449,8 @@ impl PluginManager {
|
|||||||
req: CallHttpRequestActionRequest,
|
req: CallHttpRequestActionRequest,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let ref_id = req.plugin_ref_id.clone();
|
let ref_id = req.plugin_ref_id.clone();
|
||||||
let plugin = self
|
let plugin =
|
||||||
.get_plugin_by_ref_id(ref_id.as_str())
|
self.get_plugin_by_ref_id(ref_id.as_str()).await.ok_or(PluginNotFoundErr(ref_id))?;
|
||||||
.await
|
|
||||||
.ok_or(PluginNotFoundErr(ref_id))?;
|
|
||||||
let event = plugin.build_event_to_send(
|
let event = plugin.build_event_to_send(
|
||||||
WindowContext::from_window(window),
|
WindowContext::from_window(window),
|
||||||
&InternalEventPayload::CallHttpRequestActionRequest(req),
|
&InternalEventPayload::CallHttpRequestActionRequest(req),
|
||||||
@@ -500,10 +476,7 @@ impl PluginManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let events = self
|
let events = self
|
||||||
.send_and_wait(
|
.send_and_wait(window_context, &InternalEventPayload::CallTemplateFunctionRequest(req))
|
||||||
window_context,
|
|
||||||
&InternalEventPayload::CallTemplateFunctionRequest(req),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let value = events.into_iter().find_map(|e| match e.payload {
|
let value = events.into_iter().find_map(|e| match e.payload {
|
||||||
@@ -537,9 +510,7 @@ impl PluginManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
None => Err(PluginErr(
|
None => Err(PluginErr("No importers found for file contents".to_string())),
|
||||||
"No importers found for file contents".to_string(),
|
|
||||||
)),
|
|
||||||
Some((resp, ref_id)) => {
|
Some((resp, ref_id)) => {
|
||||||
let plugin = self
|
let plugin = self
|
||||||
.get_plugin_by_ref_id(ref_id.as_str())
|
.get_plugin_by_ref_id(ref_id.as_str())
|
||||||
@@ -613,14 +584,10 @@ fn fix_windows_paths(p: &PathBuf) -> String {
|
|||||||
let safe_path = dunce::simplified(p.as_path()).to_string_lossy().to_string();
|
let safe_path = dunce::simplified(p.as_path()).to_string_lossy().to_string();
|
||||||
|
|
||||||
// 2. Remove the drive letter
|
// 2. Remove the drive letter
|
||||||
let safe_path = Regex::new("^[a-zA-Z]:")
|
let safe_path = Regex::new("^[a-zA-Z]:").unwrap().replace(safe_path.as_str(), "");
|
||||||
.unwrap()
|
|
||||||
.replace(safe_path.as_str(), "");
|
|
||||||
|
|
||||||
// 3. Convert backslashes to forward
|
// 3. Convert backslashes to forward
|
||||||
let safe_path = PathBuf::from(safe_path.to_string())
|
let safe_path = PathBuf::from(safe_path.to_string()).to_slash_lossy().to_string();
|
||||||
.to_slash_lossy()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
safe_path
|
safe_path
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user