v0.0.5
RustBox CI / rustbox (push) Canceled after 0s

This commit is contained in:
Mateusz Gruszczyński committed 2026-10-30 12:06:44 +01:00
1 parent 96a32ea8fb
commit a643e7e3ab
106 files changed
+2223 -4669

No files matched your search

-15
View File
@@ -55,10 +55,6 @@ struct DeleteResponse {
status: String,
}
/// Handler for `POST /api/drafts/{draft_id}/attachments`.
///
/// Accepts a multipart upload containing one or more files. Each file is
/// saved to disk and recorded in the `draft_attachments` table.
pub async fn upload_attachment(
Extension(session): Extension<SessionState>,
Extension(config): Extension<Arc<AppConfig>>,
@@ -69,7 +65,6 @@ pub async fn upload_attachment(
let conn = db::pool::open_user_db(&config.data_dir, &session.user_hash)
.map_err(|e| AppError::InternalError(format!("Failed to open database: {e}")))?;
// Ensure draft exists (create it if not — auto-creates on first attachment upload).
let existing = db::drafts::get_draft(&conn, &draft_id).map_err(AppError::InternalError)?;
if existing.is_none() {
db::drafts::upsert_draft(
@@ -79,7 +74,6 @@ pub async fn upload_attachment(
.map_err(AppError::InternalError)?;
}
// Build the attachment storage directory.
let att_dir = Path::new(&config.data_dir)
.join(&session.user_hash)
.join("attachments")
@@ -186,9 +180,6 @@ pub async fn upload_attachment(
.into_response())
}
/// Handler for `GET /api/drafts/{draft_id}/attachments/{attachment_id}/content`.
///
/// Serves the raw file content of a draft attachment for inline preview.
pub async fn get_attachment_content(
Extension(session): Extension<SessionState>,
Extension(config): Extension<Arc<AppConfig>>,
@@ -217,9 +208,6 @@ pub async fn get_attachment_content(
.unwrap())
}
/// Handler for `DELETE /api/drafts/{draft_id}/attachments/{attachment_id}`.
///
/// Removes an attachment from the database and deletes the file from disk.
pub async fn delete_attachment(
Extension(session): Extension<SessionState>,
Extension(config): Extension<Arc<AppConfig>>,
@@ -229,7 +217,6 @@ pub async fn delete_attachment(
let conn = db::pool::open_user_db(&config.data_dir, &session.user_hash)
.map_err(|e| AppError::InternalError(format!("Failed to open database: {e}")))?;
// Get the attachment record so we can find the file path.
let attachments =
db::drafts::get_draft_attachments(&conn, &draft_id).map_err(AppError::InternalError)?;
@@ -238,13 +225,11 @@ pub async fn delete_attachment(
.find(|a| a.id == attachment_id)
.ok_or_else(|| AppError::NotFound("Attachment not found".to_string()))?;
// Delete file from disk (best-effort).
let file_path = attachment.file_path.clone();
if let Err(e) = tokio::fs::remove_file(&file_path).await {
tracing::warn!(error = %e, path = %file_path, "Failed to delete attachment file from disk");
}
// Delete from DB.
db::drafts::delete_draft_attachment(&conn, &attachment_id).map_err(AppError::InternalError)?;
Ok(Json(DeleteResponse {