Transfer Panel Details Without an Extra Layer of JSON Encoding (#14)
**Rationale:** This made it harder to snoop on the traffic in the network monitor because it was encoded as a string. **Changes:** - Backend now accepts & provides the panel data as a JSON object rather than as a string - Backend now supports compression - Minor improvements to error handling - Some panel structures were getting saved in the JSON when they weren't supposed to be (now this no longer happens) Reviewed-on: #14 Co-authored-by: Sergey Savelyev <sergeysav.nn@gmail.com> Co-committed-by: Sergey Savelyev <sergeysav.nn@gmail.com>
This commit was merged in pull request #14.
This commit is contained in:
@@ -9,7 +9,7 @@ use uuid::Uuid;
|
||||
#[derive(Deserialize)]
|
||||
struct CreateParam {
|
||||
name: String,
|
||||
data: String,
|
||||
data: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::http::backend::setup_backend;
|
||||
use crate::http::websocket::setup_websocket;
|
||||
use crate::panels::PanelService;
|
||||
use crate::telemetry::management_service::TelemetryManagementService;
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::middleware::{Compress, Logger};
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use log::info;
|
||||
use std::sync::Arc;
|
||||
@@ -36,6 +36,7 @@ pub async fn setup(
|
||||
.service(web::scope("/backend").configure(setup_backend))
|
||||
.service(web::scope("/ws").configure(setup_websocket))
|
||||
.service(web::scope("/api").configure(setup_api))
|
||||
.wrap(Compress::default())
|
||||
.wrap(Logger::default())
|
||||
})
|
||||
.bind("localhost:8080")?
|
||||
|
||||
@@ -14,10 +14,12 @@ impl PanelService {
|
||||
Self { pool }
|
||||
}
|
||||
|
||||
pub async fn create(&self, name: &str, data: &str) -> anyhow::Result<Uuid> {
|
||||
pub async fn create(&self, name: &str, data: &serde_json::Value) -> anyhow::Result<Uuid> {
|
||||
let id = Uuid::new_v4();
|
||||
let id_string = id.to_string();
|
||||
|
||||
let data = serde_json::to_string(data)?;
|
||||
|
||||
let mut transaction = self.pool.begin().await?;
|
||||
|
||||
let _ = sqlx::query!(
|
||||
|
||||
@@ -12,11 +12,12 @@ pub struct Panel {
|
||||
#[sqlx(flatten)]
|
||||
#[serde(flatten)]
|
||||
pub header: PanelRequired,
|
||||
pub data: String,
|
||||
#[sqlx(json)]
|
||||
pub data: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
pub struct PanelUpdate {
|
||||
pub name: Option<String>,
|
||||
pub data: Option<String>,
|
||||
pub data: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user