mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:44:12 +01:00
Add body type to request and tab dropdown
This commit is contained in:
@@ -8,6 +8,8 @@ windows_subsystem = "windows"
|
||||
extern crate objc;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::env::current_dir;
|
||||
use std::fs::create_dir_all;
|
||||
|
||||
use http::header::{ACCEPT, HeaderName, USER_AGENT};
|
||||
@@ -202,7 +204,7 @@ async fn create_request(
|
||||
let pool = &*db_instance.lock().await;
|
||||
let headers = Vec::new();
|
||||
let created_request =
|
||||
models::upsert_request(None, workspace_id, name, "GET", None, "", headers, pool)
|
||||
models::upsert_request(None, workspace_id, name, "GET", None, None, "", headers, pool)
|
||||
.await
|
||||
.expect("Failed to create request");
|
||||
|
||||
@@ -237,6 +239,7 @@ async fn update_request(
|
||||
request.name.as_str(),
|
||||
request.method.as_str(),
|
||||
body,
|
||||
request.body_type,
|
||||
request.url.as_str(),
|
||||
request.headers.0,
|
||||
pool,
|
||||
@@ -359,7 +362,11 @@ fn main() {
|
||||
Ok(())
|
||||
})
|
||||
.setup(|app| {
|
||||
let dir = app.path_resolver().app_data_dir().unwrap();
|
||||
let dir = match is_dev() {
|
||||
true => current_dir().unwrap(),
|
||||
false => app.path_resolver().app_data_dir().unwrap(),
|
||||
};
|
||||
|
||||
create_dir_all(dir.clone()).expect("Problem creating App directory!");
|
||||
let p = dir.join("db.sqlite");
|
||||
let p_string = p.to_string_lossy().replace(' ', "%20");
|
||||
@@ -431,3 +438,8 @@ fn main() {
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
fn is_dev() -> bool {
|
||||
let env = option_env!("YAAK_ENV");
|
||||
env.unwrap_or("production") == "development"
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ pub struct HttpRequest {
|
||||
pub url: String,
|
||||
pub method: String,
|
||||
pub body: Option<String>,
|
||||
pub body_type: Option<String>,
|
||||
pub headers: Json<Vec<HttpRequestHeader>>,
|
||||
}
|
||||
|
||||
@@ -116,6 +117,7 @@ pub async fn upsert_request(
|
||||
name: &str,
|
||||
method: &str,
|
||||
body: Option<&str>,
|
||||
body_type: Option<String>,
|
||||
url: &str,
|
||||
headers: Vec<HttpRequestHeader>,
|
||||
pool: &Pool<Sqlite>,
|
||||
@@ -131,14 +133,25 @@ pub async fn upsert_request(
|
||||
let headers_json = Json(headers);
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO http_requests (id, workspace_id, name, url, method, body, headers, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
INSERT INTO http_requests (
|
||||
id,
|
||||
workspace_id,
|
||||
name,
|
||||
url,
|
||||
method,
|
||||
body,
|
||||
body_type,
|
||||
headers,
|
||||
updated_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
updated_at = CURRENT_TIMESTAMP,
|
||||
name = excluded.name,
|
||||
method = excluded.method,
|
||||
headers = excluded.headers,
|
||||
body = excluded.body,
|
||||
body_type = excluded.body_type,
|
||||
url = excluded.url
|
||||
"#,
|
||||
id,
|
||||
@@ -147,6 +160,7 @@ pub async fn upsert_request(
|
||||
url,
|
||||
method,
|
||||
body,
|
||||
body_type,
|
||||
headers_json,
|
||||
)
|
||||
.execute(pool)
|
||||
@@ -162,7 +176,17 @@ pub async fn find_requests(
|
||||
sqlx::query_as!(
|
||||
HttpRequest,
|
||||
r#"
|
||||
SELECT id, workspace_id, created_at, updated_at, deleted_at, name, url, method, body,
|
||||
SELECT
|
||||
id,
|
||||
workspace_id,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at,
|
||||
name,
|
||||
url,
|
||||
method,
|
||||
body,
|
||||
body_type,
|
||||
headers AS "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>"
|
||||
FROM http_requests
|
||||
WHERE workspace_id = ?
|
||||
@@ -177,7 +201,17 @@ pub async fn get_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, s
|
||||
sqlx::query_as!(
|
||||
HttpRequest,
|
||||
r#"
|
||||
SELECT id, workspace_id, created_at, updated_at, deleted_at, name, url, method, body,
|
||||
SELECT
|
||||
id,
|
||||
workspace_id,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at,
|
||||
name,
|
||||
url,
|
||||
method,
|
||||
body,
|
||||
body_type,
|
||||
headers AS "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>"
|
||||
FROM http_requests
|
||||
WHERE id = ?
|
||||
|
||||
Reference in New Issue
Block a user