Refactor and clean up code across multiple modules

- Simplified token type assignment in OAuth service.
- Removed unused session_lock module and re-exported Session from zesdex_entities.
- Cleaned up session entity by removing unnecessary comments and code.
- Consolidated session handling in HTTP handlers for better readability.
- Improved formatting and readability in OAuth repository tests.
- Enhanced session lock repository with clearer match statements.
- Streamlined session repository error handling.
- Refined RNG tests for better clarity.
- Adjusted module visibility and organization in lib.rs.
- Updated IPC client and connection code for better error handling and clarity.
- Improved frame handling in IPC for better readability.
- Organized module imports and added test utilities for IPC.
- Enhanced database connection error handling.
- Simplified JWT token creation error handling.
- Improved password verification error handling.
- Cleaned up state management code for better readability.
- Refactored middleware for session authentication and rate limiting.
- Simplified clipboard utility for better error handling.
- Enhanced logging initialization for better error reporting.
- Improved pagination utility with clearer method annotations.
- Cleaned up sanitization functions for filenames and paths.
- Enhanced slug generation functions for better clarity and usability.
This commit is contained in:
asepharyana
2026-07-17 09:08:41 +07:00
parent 22dd6fdda7
commit 1f0ae9f551
95 changed files with 1792 additions and 2131 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
use super::super::resolve_path;
use super::super::Tool;
use super::super::ToolCtx;
use super::helpers::arg_str;
use crate::tool::arg_str;
use anyhow::{anyhow, Result};
use serde_json::{json, Value};
use std::fs;
+2 -1
View File
@@ -9,7 +9,8 @@ use super::super::check_graduated_checks;
use super::super::resolve_path;
use super::super::Tool;
use super::super::ToolCtx;
use super::helpers::{self, arg_str};
use super::helpers;
use crate::tool::arg_str;
use anyhow::{anyhow, Result};
use serde_json::{json, Value};
use similar::TextDiff;
+1 -40
View File
@@ -1,19 +1,8 @@
//! Shared helpers for filesystem tools: extracting string arguments from JSON
//! and producing user-friendly "not found" diagnostics.
use anyhow::{anyhow, Result};
use serde_json::Value;
use std::path::Path;
/// Extract a required string argument from a JSON args map.
///
/// Return: the value as `String` if present and a string type; `Err` if missing
/// or of a different JSON type (null, number, boolean, array, object).
pub fn arg_str(args: &Value, name: &str) -> Result<String> {
args.get(name)
.and_then(|v| v.as_str())
.map(std::string::ToString::to_string)
.ok_or_else(|| anyhow!("missing required argument: {name}"))
}
/// Produce a user-friendly diagnostic string when a path doesn't resolve or exist.
///
@@ -70,35 +59,7 @@ mod tests {
use super::*;
use serde_json::json;
#[test]
fn test_arg_str_found() {
let args = json!({"key": "value"});
assert_eq!(arg_str(&args, "key").unwrap(), "value");
}
#[test]
fn test_arg_str_missing() {
let args = json!({"other": "value"});
assert!(arg_str(&args, "key").is_err());
}
#[test]
fn test_arg_str_empty_string() {
let args = json!({"key": ""});
assert_eq!(arg_str(&args, "key").unwrap(), "");
}
#[test]
fn test_arg_str_wrong_type() {
let args = json!({"key": 42});
assert!(arg_str(&args, "key").is_err());
}
#[test]
fn test_arg_str_null() {
let args = json!({"key": null});
assert!(arg_str(&args, "key").is_err());
}
#[test]
fn test_truncate_diff_under_limit_unchanged() {
+2 -1
View File
@@ -8,7 +8,8 @@
use super::super::resolve_path;
use super::super::Tool;
use super::super::ToolCtx;
use super::helpers::{arg_str, not_found_help};
use super::helpers::not_found_help;
use crate::tool::arg_str;
use anyhow::{anyhow, Result};
use serde_json::{json, Value};
use std::fs;
+2 -1
View File
@@ -3,7 +3,8 @@ use super::super::check_graduated_checks;
use super::super::resolve_path;
use super::super::Tool;
use super::super::ToolCtx;
use super::helpers::{self, arg_str};
use super::helpers;
use crate::tool::arg_str;
use anyhow::{anyhow, Result};
use serde_json::{json, Value};
use similar::TextDiff;