From 09d6e279d038491dee5a6af2a6a4929bb135bba4 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Thu, 25 Apr 2024 13:00:13 +0200 Subject: [PATCH] fix clippy errors --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- ffplayout-api/src/main.rs | 8 ++------ ffplayout-api/src/sse/mod.rs | 8 +++++++- ffplayout-api/src/sse/routes.rs | 10 ++++------ ffplayout-api/src/utils/system.rs | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cd55bb8..ac231a67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1293,7 +1293,7 @@ checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "ffplayout" -version = "0.21.3" +version = "0.22.0" dependencies = [ "chrono", "clap", @@ -1315,7 +1315,7 @@ dependencies = [ [[package]] name = "ffplayout-api" -version = "0.21.3" +version = "0.22.0" dependencies = [ "actix-files", "actix-multipart", @@ -1358,7 +1358,7 @@ dependencies = [ [[package]] name = "ffplayout-lib" -version = "0.21.3" +version = "0.22.0" dependencies = [ "chrono", "crossbeam-channel", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "tests" -version = "0.21.3" +version = "0.22.0" dependencies = [ "chrono", "crossbeam-channel", diff --git a/Cargo.toml b/Cargo.toml index 15993ce8..00dbb1c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["ffplayout-api", "ffplayout-engine", "tests"] resolver = "2" [workspace.package] -version = "0.21.3" +version = "0.22.0" license = "GPL-3.0" repository = "https://github.com/ffplayout/ffplayout" authors = ["Jonathan Baecker "] diff --git a/ffplayout-api/src/main.rs b/ffplayout-api/src/main.rs index 981c460f..c3e52737 100644 --- a/ffplayout-api/src/main.rs +++ b/ffplayout-api/src/main.rs @@ -1,9 +1,4 @@ -use std::{ - collections::HashSet, - env, - process::exit, - sync::{Arc, Mutex}, -}; +use std::{collections::HashSet, env, process::exit, sync::Arc}; use actix_files::Files; use actix_web::{ @@ -17,6 +12,7 @@ use actix_web_static_files::ResourceFiles; use path_clean::PathClean; use simplelog::*; +use tokio::sync::Mutex; use ffplayout_api::{ api::{auth, routes::*}, diff --git a/ffplayout-api/src/sse/mod.rs b/ffplayout-api/src/sse/mod.rs index e2545c8b..834573ea 100644 --- a/ffplayout-api/src/sse/mod.rs +++ b/ffplayout-api/src/sse/mod.rs @@ -1,9 +1,9 @@ use std::{ collections::HashSet, - sync::Mutex, time::{Duration, SystemTime}, }; +use tokio::sync::Mutex; use uuid::Uuid; use crate::utils::errors::ServiceError; @@ -26,6 +26,12 @@ impl UuidData { } } +impl Default for UuidData { + fn default() -> Self { + Self::new() + } +} + pub struct AuthState { pub uuids: Mutex>, } diff --git a/ffplayout-api/src/sse/routes.rs b/ffplayout-api/src/sse/routes.rs index 665ca9b1..a33bf02b 100644 --- a/ffplayout-api/src/sse/routes.rs +++ b/ffplayout-api/src/sse/routes.rs @@ -28,7 +28,7 @@ impl User { #[post("/generate-uuid")] #[protect(any("Role::Admin", "Role::User"), ty = "Role")] async fn generate_uuid(data: web::Data) -> Result { - let mut uuids = data.uuids.lock().map_err(|e| e.to_string())?; + let mut uuids = data.uuids.lock().await; let new_uuid = UuidData::new(); let user_auth = User::new(String::new(), new_uuid.uuid.to_string()); @@ -49,7 +49,7 @@ async fn validate_uuid( data: web::Data, user: web::Query, ) -> Result { - let mut uuids = data.uuids.lock().map_err(|e| e.to_string())?; + let mut uuids = data.uuids.lock().await; match check_uuid(&mut uuids, user.uuid.as_str()) { Ok(s) => Ok(web::Json(s)), @@ -70,11 +70,9 @@ async fn event_stream( id: web::Path, user: web::Query, ) -> Result { - let mut uuids = data.uuids.lock().map_err(|e| e.to_string())?; + let mut uuids = data.uuids.lock().await; - if let Err(e) = check_uuid(&mut uuids, user.uuid.as_str()) { - return Err(e); - } + check_uuid(&mut uuids, user.uuid.as_str())?; let (config, _) = playout_config(&pool.clone().into_inner(), &id).await?; diff --git a/ffplayout-api/src/utils/system.rs b/ffplayout-api/src/utils/system.rs index 3feb2e47..f52f35e2 100644 --- a/ffplayout-api/src/utils/system.rs +++ b/ffplayout-api/src/utils/system.rs @@ -1,4 +1,4 @@ -// use std::cmp; +use std::fmt; use local_ip_address::list_afinet_netifas; use serde::Serialize; @@ -71,9 +71,9 @@ pub struct SystemStat { pub system: MySystem, } -impl SystemStat { - pub fn to_string(&self) -> String { - serde_json::to_string(&self).unwrap() +impl fmt::Display for SystemStat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", serde_json::to_string(self).unwrap()) } }