Skip to content

Commit 10d7cfa

Browse files
Run cargo fmt on all Rust source files
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent dc6f027 commit 10d7cfa

File tree

18 files changed

+273
-200
lines changed

18 files changed

+273
-200
lines changed

backend/src/config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ pub fn init_data_dir() {
3131
}
3232

3333
tracing::info!("Data directory: {}", path.display());
34-
DATA_DIR.set(path).expect("Data directory already initialized");
34+
DATA_DIR
35+
.set(path)
36+
.expect("Data directory already initialized");
3537
}
3638

3739
/// Get the resolved data directory path.
3840
pub fn data_dir() -> &'static Path {
39-
DATA_DIR.get().expect("Data directory not initialized. Call config::init_data_dir() first.")
41+
DATA_DIR
42+
.get()
43+
.expect("Data directory not initialized. Call config::init_data_dir() first.")
4044
}

backend/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ async fn main() {
121121
// Small delay to ensure server is ready
122122
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
123123
if let Err(e) = webbrowser::open(&url) {
124-
tracing::warn!("Failed to open browser: {}. Open http://localhost:{} manually.", e, port);
124+
tracing::warn!(
125+
"Failed to open browser: {}. Open http://localhost:{} manually.",
126+
e,
127+
port
128+
);
125129
}
126130
});
127131
}

backend/src/models/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod note;
22
pub mod project;
3-
pub mod task;
3+
pub mod task;

backend/src/routes/assets.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ async fn upload_asset(
7979
if !is_allowed_content_type(&content_type) {
8080
return (
8181
StatusCode::BAD_REQUEST,
82-
format!("Unsupported file type: {}. Only images are allowed.", content_type),
82+
format!(
83+
"Unsupported file type: {}. Only images are allowed.",
84+
content_type
85+
),
8386
)
8487
.into_response();
8588
}
@@ -100,7 +103,10 @@ async fn upload_asset(
100103
if data.len() > MAX_FILE_SIZE {
101104
return (
102105
StatusCode::BAD_REQUEST,
103-
format!("File too large. Maximum size is {} MB.", MAX_FILE_SIZE / 1024 / 1024),
106+
format!(
107+
"File too large. Maximum size is {} MB.",
108+
MAX_FILE_SIZE / 1024 / 1024
109+
),
104110
)
105111
.into_response();
106112
}
@@ -149,7 +155,11 @@ async fn upload_asset(
149155

150156
/// Validate that a path component doesn't contain directory traversal
151157
fn validate_path_component(component: &str) -> Result<(), String> {
152-
if component.contains("..") || component.contains('/') || component.contains('\\') || component.is_empty() {
158+
if component.contains("..")
159+
|| component.contains('/')
160+
|| component.contains('\\')
161+
|| component.is_empty()
162+
{
153163
return Err("Invalid path component".to_string());
154164
}
155165
Ok(())
@@ -199,12 +209,7 @@ async fn get_asset(Path((project, filename)): Path<(String, String)>) -> impl In
199209
let stream = ReaderStream::new(file);
200210
let body = Body::from_stream(stream);
201211

202-
(
203-
StatusCode::OK,
204-
[(header::CONTENT_TYPE, content_type)],
205-
body,
206-
)
207-
.into_response()
212+
(StatusCode::OK, [(header::CONTENT_TYPE, content_type)], body).into_response()
208213
}
209214

210215
fn is_allowed_content_type(content_type: &str) -> bool {
@@ -220,11 +225,7 @@ fn is_allowed_content_type(content_type: &str) -> bool {
220225
}
221226

222227
fn get_content_type(filename: &str) -> &'static str {
223-
let ext = filename
224-
.rsplit('.')
225-
.next()
226-
.unwrap_or("")
227-
.to_lowercase();
228+
let ext = filename.rsplit('.').next().unwrap_or("").to_lowercase();
228229

229230
match ext.as_str() {
230231
"jpg" | "jpeg" => "image/jpeg",
@@ -248,7 +249,13 @@ fn generate_unique_filename(dir: &StdPath, original: &str) -> String {
248249
// Sanitize filename
249250
let sanitized_name: String = name
250251
.chars()
251-
.map(|c| if c.is_alphanumeric() || c == '-' || c == '_' { c } else { '_' })
252+
.map(|c| {
253+
if c.is_alphanumeric() || c == '-' || c == '_' {
254+
c
255+
} else {
256+
'_'
257+
}
258+
})
252259
.collect();
253260

254261
let base_filename = format!("{}{}", sanitized_name, ext);

backend/src/routes/daily.rs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
use axum::{
2-
body::Bytes,
3-
extract::Path,
4-
http::StatusCode,
5-
response::IntoResponse,
6-
routing::get,
7-
Json, Router,
2+
body::Bytes, extract::Path, http::StatusCode, response::IntoResponse, routing::get, Json,
3+
Router,
84
};
95
use chrono::{NaiveDate, Utc};
106
use serde::{Deserialize, Serialize};
117
use std::fs;
128

13-
use crate::services::filesystem;
149
use crate::config;
10+
use crate::services::filesystem;
1511
use crate::services::frontmatter;
1612

1713
#[derive(Debug, Serialize)]
@@ -35,7 +31,12 @@ pub fn router() -> Router {
3531
Router::new()
3632
.route("/", get(list_daily_notes))
3733
.route("/today", get(get_or_create_today))
38-
.route("/{date}", get(get_daily_note).post(create_daily_note).put(update_daily_note))
34+
.route(
35+
"/{date}",
36+
get(get_daily_note)
37+
.post(create_daily_note)
38+
.put(update_daily_note),
39+
)
3940
}
4041

4142
/// List all daily notes
@@ -52,7 +53,7 @@ async fn list_daily_notes() -> impl IntoResponse {
5253

5354
fn list_daily_notes_impl() -> Result<Vec<DailyNoteSummary>, String> {
5455
let daily_dir = config::data_dir().join("daily");
55-
56+
5657
// Create directory if it doesn't exist
5758
if !daily_dir.exists() {
5859
fs::create_dir_all(&daily_dir).map_err(|e| e.to_string())?;
@@ -70,7 +71,7 @@ fn list_daily_notes_impl() -> Result<Vec<DailyNoteSummary>, String> {
7071
}
7172

7273
let filename = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
73-
74+
7475
// Validate date format
7576
if NaiveDate::parse_from_str(filename, "%Y-%m-%d").is_err() {
7677
continue;
@@ -102,7 +103,7 @@ fn list_daily_notes_impl() -> Result<Vec<DailyNoteSummary>, String> {
102103
/// Get or create today's daily note
103104
async fn get_or_create_today() -> impl IntoResponse {
104105
let today = Utc::now().format("%Y-%m-%d").to_string();
105-
106+
106107
match get_daily_note_impl(&today) {
107108
Ok(note) => Json(note).into_response(),
108109
Err(_) => {
@@ -123,14 +124,16 @@ async fn get_or_create_today() -> impl IntoResponse {
123124
async fn get_daily_note(Path(date): Path<String>) -> impl IntoResponse {
124125
// Validate date format
125126
if NaiveDate::parse_from_str(&date, "%Y-%m-%d").is_err() {
126-
return (StatusCode::BAD_REQUEST, "Invalid date format. Use YYYY-MM-DD").into_response();
127+
return (
128+
StatusCode::BAD_REQUEST,
129+
"Invalid date format. Use YYYY-MM-DD",
130+
)
131+
.into_response();
127132
}
128133

129134
match get_daily_note_impl(&date) {
130135
Ok(note) => Json(note).into_response(),
131-
Err(err) if err.contains("not found") => {
132-
(StatusCode::NOT_FOUND, err).into_response()
133-
}
136+
Err(err) if err.contains("not found") => (StatusCode::NOT_FOUND, err).into_response(),
134137
Err(err) => (
135138
StatusCode::INTERNAL_SERVER_ERROR,
136139
format!("Failed to get daily note: {}", err),
@@ -171,16 +174,18 @@ async fn create_daily_note(
171174
) -> impl IntoResponse {
172175
// Validate date format
173176
if NaiveDate::parse_from_str(&date, "%Y-%m-%d").is_err() {
174-
return (StatusCode::BAD_REQUEST, "Invalid date format. Use YYYY-MM-DD").into_response();
177+
return (
178+
StatusCode::BAD_REQUEST,
179+
"Invalid date format. Use YYYY-MM-DD",
180+
)
181+
.into_response();
175182
}
176183

177184
let content = body.and_then(|b| b.content.clone());
178185

179186
match create_daily_note_impl(&date, content.as_deref()) {
180187
Ok(note) => (StatusCode::CREATED, Json(note)).into_response(),
181-
Err(err) if err.contains("already exists") => {
182-
(StatusCode::CONFLICT, err).into_response()
183-
}
188+
Err(err) if err.contains("already exists") => (StatusCode::CONFLICT, err).into_response(),
184189
Err(err) => (
185190
StatusCode::INTERNAL_SERVER_ERROR,
186191
format!("Failed to create daily note: {}", err),
@@ -191,7 +196,7 @@ async fn create_daily_note(
191196

192197
fn create_daily_note_impl(date: &str, initial_content: Option<&str>) -> Result<DailyNote, String> {
193198
let daily_dir = config::data_dir().join("daily");
194-
199+
195200
// Create directory if it doesn't exist
196201
if !daily_dir.exists() {
197202
fs::create_dir_all(&daily_dir).map_err(|e| e.to_string())?;
@@ -204,10 +209,9 @@ fn create_daily_note_impl(date: &str, initial_content: Option<&str>) -> Result<D
204209
}
205210

206211
let now = Utc::now().to_rfc3339();
207-
212+
208213
// Parse date for display
209-
let parsed_date = NaiveDate::parse_from_str(date, "%Y-%m-%d")
210-
.map_err(|e| e.to_string())?;
214+
let parsed_date = NaiveDate::parse_from_str(date, "%Y-%m-%d").map_err(|e| e.to_string())?;
211215
let display_date = parsed_date.format("%A, %B %d, %Y").to_string();
212216

213217
// Create frontmatter
@@ -238,14 +242,12 @@ fn create_daily_note_impl(date: &str, initial_content: Option<&str>) -> Result<D
238242
);
239243

240244
// Use provided content or default template
241-
let body = initial_content
242-
.map(|c| c.to_string())
243-
.unwrap_or_else(|| {
244-
format!(
245-
"# {}\n\n## Today's Focus\n\n- \n\n## Notes\n\n\n\n## Tasks\n\n- [ ] \n",
246-
display_date
247-
)
248-
});
245+
let body = initial_content.map(|c| c.to_string()).unwrap_or_else(|| {
246+
format!(
247+
"# {}\n\n## Today's Focus\n\n- \n\n## Notes\n\n\n\n## Tasks\n\n- [ ] \n",
248+
display_date
249+
)
250+
});
249251

250252
let content = frontmatter::serialize_frontmatter(&fm, &body)?;
251253

@@ -261,22 +263,21 @@ fn create_daily_note_impl(date: &str, initial_content: Option<&str>) -> Result<D
261263
}
262264

263265
/// Update a daily note's content
264-
async fn update_daily_note(
265-
Path(date): Path<String>,
266-
body: Bytes,
267-
) -> impl IntoResponse {
266+
async fn update_daily_note(Path(date): Path<String>, body: Bytes) -> impl IntoResponse {
268267
// Validate date format
269268
if NaiveDate::parse_from_str(&date, "%Y-%m-%d").is_err() {
270-
return (StatusCode::BAD_REQUEST, "Invalid date format. Use YYYY-MM-DD").into_response();
269+
return (
270+
StatusCode::BAD_REQUEST,
271+
"Invalid date format. Use YYYY-MM-DD",
272+
)
273+
.into_response();
271274
}
272275

273276
let content = String::from_utf8_lossy(&body).to_string();
274277

275278
match update_daily_note_impl(&date, &content) {
276279
Ok(note) => Json(note).into_response(),
277-
Err(err) if err.contains("not found") => {
278-
(StatusCode::NOT_FOUND, err).into_response()
279-
}
280+
Err(err) if err.contains("not found") => (StatusCode::NOT_FOUND, err).into_response(),
280281
Err(err) => (
281282
StatusCode::INTERNAL_SERVER_ERROR,
282283
format!("Failed to update daily note: {}", err),

backend/src/routes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pub mod git;
44
pub mod notes;
55
pub mod projects;
66
pub mod search;
7-
pub mod tasks;
7+
pub mod tasks;

backend/src/routes/notes.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
use axum::{
2-
extract::Path,
3-
http::StatusCode,
4-
response::IntoResponse,
5-
routing::get,
6-
Json, Router,
7-
};
1+
use axum::{extract::Path, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
82

93
use crate::models::note::{Note, NoteSummary};
104
use crate::services::filesystem;
115

126
pub fn router() -> Router {
13-
Router::new()
14-
.route("/{id}", get(get_note).put(update_note).delete(delete_note))
7+
Router::new().route("/{id}", get(get_note).put(update_note).delete(delete_note))
158
}
169

1710
pub async fn list_notes() -> impl IntoResponse {
@@ -50,10 +43,7 @@ pub async fn create_note() -> impl IntoResponse {
5043
}
5144
}
5245

53-
async fn update_note(
54-
Path(id): Path<String>,
55-
body: String,
56-
) -> impl IntoResponse {
46+
async fn update_note(Path(id): Path<String>, body: String) -> impl IntoResponse {
5747
match filesystem::update_note(&id, &body) {
5848
Ok(note) => Json::<Note>(note).into_response(),
5949
Err(err) if err.starts_with("Note not found") => {

0 commit comments

Comments
 (0)