fix: resolve clippy warnings and test errors
- Implement FromStr trait for NodeType instead of custom from_str method - Fix redundant_closure warning in server.rs:455 - Add #[allow(clippy::too_many_arguments)] for new_file_node - Fix unused variables in tests (_user_id, _conn) - Remove unused imports (NodeType, serde_json::json) - Replace len() > 0 with !is_empty() for clarity - Replace == false with negation operator - Format code with cargo fmt
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use anyhow::{Context, Result};
|
||||
use rusqlite::Connection;
|
||||
use std::str::FromStr;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::filetree::node::{Aliases, FileNode, NodeType};
|
||||
@@ -95,7 +96,8 @@ impl FileTree {
|
||||
sha256: row.get(4)?,
|
||||
parent_id: row.get(5)?,
|
||||
children,
|
||||
node_type: NodeType::from_str(&row.get::<_, String>(7)?),
|
||||
node_type: NodeType::from_str(&row.get::<_, String>(7)?)
|
||||
.unwrap_or(NodeType::Folder),
|
||||
icon: row.get(8)?,
|
||||
color: row.get(9)?,
|
||||
bg_color: row.get(10)?,
|
||||
@@ -290,6 +292,7 @@ impl FileTree {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_file_node(
|
||||
label: &str,
|
||||
file_uuid: &str,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FileNode {
|
||||
@@ -72,13 +73,17 @@ impl NodeType {
|
||||
NodeType::DynamicLayer => "dynamic_layer",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
impl FromStr for NodeType {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"folder" => NodeType::Folder,
|
||||
"file" => NodeType::File,
|
||||
"dynamic_layer" => NodeType::DynamicLayer,
|
||||
_ => NodeType::Folder,
|
||||
"folder" => Ok(NodeType::Folder),
|
||||
"file" => Ok(NodeType::File),
|
||||
"dynamic_layer" => Ok(NodeType::DynamicLayer),
|
||||
_ => Ok(NodeType::Folder), // Default to Folder for unknown types
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use axum::{
|
||||
Router,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::audio;
|
||||
@@ -452,7 +453,9 @@ async fn create_node(
|
||||
let parent_id = body["parent_id"].as_str().map(|s| s.to_string());
|
||||
let node_type = body["node_type"]
|
||||
.as_str()
|
||||
.map(|s| filetree::node::NodeType::from_str(s))
|
||||
.map(|s| {
|
||||
filetree::node::NodeType::from_str(s).unwrap_or(filetree::node::NodeType::Folder)
|
||||
})
|
||||
.unwrap_or(filetree::node::NodeType::Folder);
|
||||
|
||||
let node = match node_type {
|
||||
|
||||
Reference in New Issue
Block a user