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 anyhow::{Context, Result};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
use std::str::FromStr;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::filetree::node::{Aliases, FileNode, NodeType};
|
use crate::filetree::node::{Aliases, FileNode, NodeType};
|
||||||
@@ -95,7 +96,8 @@ impl FileTree {
|
|||||||
sha256: row.get(4)?,
|
sha256: row.get(4)?,
|
||||||
parent_id: row.get(5)?,
|
parent_id: row.get(5)?,
|
||||||
children,
|
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)?,
|
icon: row.get(8)?,
|
||||||
color: row.get(9)?,
|
color: row.get(9)?,
|
||||||
bg_color: row.get(10)?,
|
bg_color: row.get(10)?,
|
||||||
@@ -290,6 +292,7 @@ impl FileTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new_file_node(
|
pub fn new_file_node(
|
||||||
label: &str,
|
label: &str,
|
||||||
file_uuid: &str,
|
file_uuid: &str,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct FileNode {
|
pub struct FileNode {
|
||||||
@@ -72,13 +73,17 @@ impl NodeType {
|
|||||||
NodeType::DynamicLayer => "dynamic_layer",
|
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 {
|
match s {
|
||||||
"folder" => NodeType::Folder,
|
"folder" => Ok(NodeType::Folder),
|
||||||
"file" => NodeType::File,
|
"file" => Ok(NodeType::File),
|
||||||
"dynamic_layer" => NodeType::DynamicLayer,
|
"dynamic_layer" => Ok(NodeType::DynamicLayer),
|
||||||
_ => NodeType::Folder,
|
_ => Ok(NodeType::Folder), // Default to Folder for unknown types
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use axum::{
|
|||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate::audio;
|
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 parent_id = body["parent_id"].as_str().map(|s| s.to_string());
|
||||||
let node_type = body["node_type"]
|
let node_type = body["node_type"]
|
||||||
.as_str()
|
.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);
|
.unwrap_or(filetree::node::NodeType::Folder);
|
||||||
|
|
||||||
let node = match node_type {
|
let node = match node_type {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
use markbase::filetree::node::NodeType;
|
use markbase::filetree::node::NodeType;
|
||||||
use markbase::filetree::{mode, FileTree};
|
use markbase::filetree::{mode, FileTree};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde_json::json;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
fn temp_db() -> (Connection, String) {
|
fn temp_db() -> (Connection, String) {
|
||||||
@@ -213,7 +212,7 @@ fn test_api_logic_get_modes() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_api_logic_file_info() {
|
fn test_api_logic_file_info() {
|
||||||
let (conn, user_id) = temp_db();
|
let (conn, _user_id) = temp_db();
|
||||||
|
|
||||||
let file_uuid = "test_file_uuid_123";
|
let file_uuid = "test_file_uuid_123";
|
||||||
FileTree::add_location(&conn, file_uuid, "/path/to/file.mp4", Some("origin")).unwrap();
|
FileTree::add_location(&conn, file_uuid, "/path/to/file.mp4", Some("origin")).unwrap();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn test_audio_devices_macos() {
|
|||||||
let (out, inp, co, ci) = audio_devices();
|
let (out, inp, co, ci) = audio_devices();
|
||||||
|
|
||||||
//至少應該有一些輸出裝置(即使是內建的)
|
//至少應該有一些輸出裝置(即使是內建的)
|
||||||
assert!(out.len() > 0 || inp.len() > 0);
|
assert!(!out.is_empty() || !inp.is_empty());
|
||||||
|
|
||||||
// current應該是有效的字符串
|
// current應該是有效的字符串
|
||||||
assert!(!co.is_empty() || !ci.is_empty());
|
assert!(!co.is_empty() || !ci.is_empty());
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ fn test_is_apple_format_ext() {
|
|||||||
fn test_is_document_ext_case_insensitive() {
|
fn test_is_document_ext_case_insensitive() {
|
||||||
//測試小寫(convert.rs使用小寫比較)
|
//測試小寫(convert.rs使用小寫比較)
|
||||||
assert!(is_document_ext("docx"));
|
assert!(is_document_ext("docx"));
|
||||||
assert!(is_document_ext("DOCX") == false); //函數未轉小寫,直接比較
|
assert!(!is_document_ext("DOCX")); //函數未轉小寫,直接比較
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use markbase::filetree::{node::NodeType, FileTree};
|
use markbase::filetree::{node::NodeType, FileTree};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde_json::json;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
fn temp_db() -> (Connection, String) {
|
fn temp_db() -> (Connection, String) {
|
||||||
@@ -207,7 +206,7 @@ fn test_api_build_tree_structure() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_api_add_location() {
|
fn test_api_add_location() {
|
||||||
let (conn, user_id) = temp_db();
|
let (_conn, user_id) = temp_db();
|
||||||
let conn = FileTree::open_user_db(&user_id).unwrap();
|
let conn = FileTree::open_user_db(&user_id).unwrap();
|
||||||
|
|
||||||
let file_uuid = "abc123def456";
|
let file_uuid = "abc123def456";
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use markbase::filetree::node::NodeType;
|
|
||||||
use markbase::filetree::{mode, FileTree};
|
use markbase::filetree::{mode, FileTree};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -102,7 +101,7 @@ fn test_mode_sort_options() {
|
|||||||
let mode = mode::get_mode("list").unwrap();
|
let mode = mode::get_mode("list").unwrap();
|
||||||
let sort_options = mode.sort_options();
|
let sort_options = mode.sort_options();
|
||||||
|
|
||||||
assert!(sort_options.len() > 0, "sort options should not be empty");
|
assert!(!sort_options.is_empty(), "sort options should not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -111,7 +110,7 @@ fn test_mode_filter_options() {
|
|||||||
let filter_options = mode.filter_options();
|
let filter_options = mode.filter_options();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
filter_options.len() > 0,
|
!filter_options.is_empty(),
|
||||||
"filter options should not be empty"
|
"filter options should not be empty"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user