diff --git a/src/ipfs/mod.rs b/src/ipfs/mod.rs index d47b553..752f9d8 100644 --- a/src/ipfs/mod.rs +++ b/src/ipfs/mod.rs @@ -1,9 +1,9 @@ use std::time::Duration; -use axum::{body::Bytes, http::request}; +use axum::body::Bytes; use reqwest::{ multipart::{Form, Part}, - Body, Client, Response, Url, + Client, Response, Url, }; use serde::{Deserialize, Serialize}; @@ -69,7 +69,7 @@ impl IpfsClient { .post(self.url.join("/api/v0/pin/add")?) .query(&PinQuery::new(cid)) .timeout(Duration::from_secs(60)); - let response = request.send().await?; + request.send().await?; Ok(()) } } diff --git a/src/v1/error.rs b/src/v1/error.rs index a386a37..7c9de30 100644 --- a/src/v1/error.rs +++ b/src/v1/error.rs @@ -24,6 +24,8 @@ pub enum APIError { Unauthorized(String), #[error("{0}")] Forbidden(String), + #[error("{0}")] + Internal(String), #[error("IPFS error: {0}")] IPFS(#[from] IPFSError), } @@ -53,6 +55,9 @@ impl IntoResponse for APIError { APIError::BadRequest(err) => ErrorResponse::new(StatusCode::BAD_REQUEST, Some(err)), APIError::Unauthorized(err) => ErrorResponse::new(StatusCode::UNAUTHORIZED, Some(err)), APIError::Forbidden(err) => ErrorResponse::new(StatusCode::FORBIDDEN, Some(err)), + APIError::Internal(err) => { + ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Some(err)) + } APIError::IPFS(_) => ErrorResponse::new(StatusCode::INTERNAL_SERVER_ERROR, None), }; let status = res.status.clone(); diff --git a/src/v1/routes.rs b/src/v1/routes.rs index 5f58d2c..5d86efc 100644 --- a/src/v1/routes.rs +++ b/src/v1/routes.rs @@ -147,6 +147,11 @@ async fn upload( for f in files { let res = cat.add_meme(&user, &f, &ip, &db_pool).await?; + + if res != 1 { + return Err(APIError::Internal("Database insertion error".to_string())); + } + ipfs.pin(f.hash).await?; links.push(format!( "{}/{}/{}", diff --git a/src/v1/upload.rs b/src/v1/upload.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/v1/upload.rs @@ -0,0 +1 @@ +