mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 23:09:47 +02:00
Url parameters for websocket URLs
This commit is contained in:
@@ -17,6 +17,7 @@ thiserror = "2.0.11"
|
||||
tokio = { version = "1.0", default-features = false, features = ["macros", "time", "test-util"] }
|
||||
tokio-tungstenite = { version = "0.26.1", default-features = false, features = ["rustls-tls-native-roots", "connect"] }
|
||||
yaak-models = { workspace = true }
|
||||
yaak-http = { workspace = true }
|
||||
yaak-plugins = { workspace = true }
|
||||
yaak-templates = { workspace = true }
|
||||
serde_json = "1.0.132"
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use tauri_plugin;
|
||||
const COMMANDS: &[&str] = &[
|
||||
"close",
|
||||
"connect",
|
||||
"close",
|
||||
"delete_connection",
|
||||
"delete_connections",
|
||||
"delete_request",
|
||||
"duplicate_request",
|
||||
"list_connections",
|
||||
"list_events",
|
||||
"list_requests",
|
||||
|
||||
@@ -9,6 +9,12 @@ export function upsertWebsocketRequest(
|
||||
}) as Promise<WebsocketRequest>;
|
||||
}
|
||||
|
||||
export function duplicateWebsocketRequest(requestId: string) {
|
||||
return invoke('plugin:yaak-ws|duplicate_request', {
|
||||
requestId,
|
||||
}) as Promise<WebsocketRequest>;
|
||||
}
|
||||
|
||||
export function deleteWebsocketRequest(requestId: string) {
|
||||
return invoke('plugin:yaak-ws|delete_request', {
|
||||
requestId,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# Automatically generated - DO NOT EDIT!
|
||||
|
||||
"$schema" = "../../schemas/schema.json"
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-duplicate-request"
|
||||
description = "Enables the duplicate_request command without any pre-configured scope."
|
||||
commands.allow = ["duplicate_request"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "deny-duplicate-request"
|
||||
description = "Denies the duplicate_request command without any pre-configured scope."
|
||||
commands.deny = ["duplicate_request"]
|
||||
@@ -7,6 +7,7 @@ Default permissions for the plugin
|
||||
- `allow-delete-connection`
|
||||
- `allow-delete-connections`
|
||||
- `allow-delete-request`
|
||||
- `allow-duplicate-request`
|
||||
- `allow-list-connections`
|
||||
- `allow-list-events`
|
||||
- `allow-list-requests`
|
||||
@@ -181,6 +182,32 @@ Denies the delete_request command without any pre-configured scope.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`yaak-ws:allow-duplicate-request`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Enables the duplicate_request command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`yaak-ws:deny-duplicate-request`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Denies the duplicate_request command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`yaak-ws:allow-list-connections`
|
||||
|
||||
</td>
|
||||
|
||||
@@ -6,6 +6,7 @@ permissions = [
|
||||
"allow-delete-connection",
|
||||
"allow-delete-connections",
|
||||
"allow-delete-request",
|
||||
"allow-duplicate-request",
|
||||
"allow-list-connections",
|
||||
"allow-list-events",
|
||||
"allow-list-requests",
|
||||
|
||||
@@ -354,6 +354,16 @@
|
||||
"type": "string",
|
||||
"const": "deny-delete-request"
|
||||
},
|
||||
{
|
||||
"description": "Enables the duplicate_request command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-duplicate-request"
|
||||
},
|
||||
{
|
||||
"description": "Denies the duplicate_request command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-duplicate-request"
|
||||
},
|
||||
{
|
||||
"description": "Enables the list_connections command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
@@ -6,10 +6,11 @@ use chrono::Utc;
|
||||
use log::{info, warn};
|
||||
use std::str::FromStr;
|
||||
use tauri::http::{HeaderMap, HeaderName};
|
||||
use tauri::{AppHandle, Manager, Runtime, State, WebviewWindow};
|
||||
use tauri::{AppHandle, Manager, Runtime, State, Url, WebviewWindow};
|
||||
use tokio::sync::{mpsc, Mutex};
|
||||
use tokio_tungstenite::tungstenite::http::HeaderValue;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
use yaak_http::apply_path_placeholders;
|
||||
use yaak_models::models::{
|
||||
HttpResponseHeader, WebsocketConnection, WebsocketConnectionState, WebsocketEvent,
|
||||
WebsocketEventType, WebsocketRequest,
|
||||
@@ -33,6 +34,14 @@ pub(crate) async fn upsert_request<R: Runtime>(
|
||||
Ok(queries::upsert_websocket_request(&w, request, &UpdateSource::Window).await?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn duplicate_request<R: Runtime>(
|
||||
request_id: &str,
|
||||
w: WebviewWindow<R>,
|
||||
) -> Result<WebsocketRequest> {
|
||||
Ok(queries::duplicate_websocket_request(&w, request_id, &UpdateSource::Window).await?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn delete_request<R: Runtime>(
|
||||
request_id: &str,
|
||||
@@ -290,7 +299,22 @@ pub(crate) async fn connect<R: Runtime>(
|
||||
});
|
||||
}
|
||||
|
||||
let response = match ws_manager.connect(&connection.id, &request.url, headers, receive_tx).await
|
||||
|
||||
let (url, url_parameters) = apply_path_placeholders(&request.url, request.url_parameters);
|
||||
|
||||
// Add URL parameters to URL
|
||||
let mut url = Url::parse(&url).unwrap();
|
||||
{
|
||||
let mut query_pairs = url.query_pairs_mut();
|
||||
for p in url_parameters.clone() {
|
||||
if !p.enabled || p.name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
query_pairs.append_pair(p.name.as_str(), p.value.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
let response = match ws_manager.connect(&connection.id, url.as_str(), headers, receive_tx).await
|
||||
{
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
@@ -298,6 +322,7 @@ pub(crate) async fn connect<R: Runtime>(
|
||||
&window,
|
||||
&WebsocketConnection {
|
||||
error: Some(format!("{e:?}")),
|
||||
state: WebsocketConnectionState::Closed,
|
||||
..connection
|
||||
},
|
||||
&UpdateSource::Window,
|
||||
|
||||
@@ -5,8 +5,8 @@ mod manager;
|
||||
mod render;
|
||||
|
||||
use crate::cmd::{
|
||||
close, connect, delete_connection, delete_connections, delete_request, list_connections,
|
||||
list_events, list_requests, send, upsert_request,
|
||||
connect, close, delete_connection, delete_connections, delete_request, duplicate_request,
|
||||
list_connections, list_events, list_requests, send, upsert_request,
|
||||
};
|
||||
use crate::manager::WebsocketManager;
|
||||
use tauri::plugin::{Builder, TauriPlugin};
|
||||
@@ -16,11 +16,12 @@ use tokio::sync::Mutex;
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("yaak-ws")
|
||||
.invoke_handler(generate_handler![
|
||||
close,
|
||||
connect,
|
||||
close,
|
||||
delete_connection,
|
||||
delete_connections,
|
||||
delete_request,
|
||||
duplicate_request,
|
||||
list_connections,
|
||||
list_events,
|
||||
list_requests,
|
||||
|
||||
Reference in New Issue
Block a user