diff options
author | Vika <vika@fireburn.ru> | 2024-11-13 04:51:52 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-11-13 04:51:52 +0300 |
commit | 3d40cca255d462cc190a602f7fb16c1f4ade821d (patch) | |
tree | 347997b4b032f47c1ac78e6d331a79b133a72318 | |
parent | 5b1318e8ed905eaa1b666cbc8300701ce7b5d061 (diff) | |
download | kittybox-3d40cca255d462cc190a602f7fb16c1f4ade821d.tar.zst |
media endpoint: small code cleanup
Change-Id: I10d8ffd53bd3c02d6de3ba4520ab859c18697c61
-rw-r--r-- | src/media/mod.rs | 11 | ||||
-rw-r--r-- | src/media/storage/mod.rs | 2 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/media/mod.rs b/src/media/mod.rs index 85b3b87..32b8405 100644 --- a/src/media/mod.rs +++ b/src/media/mod.rs @@ -1,7 +1,7 @@ use axum::{ extract::{multipart::Multipart, FromRef, Host, Path, State}, response::{IntoResponse, Response} }; -use axum_extra::headers::{HeaderMapExt, HeaderValue, IfNoneMatch}; +use axum_extra::headers::{ContentLength, HeaderMapExt, HeaderValue, IfNoneMatch}; use axum_extra::TypedHeader; use kittybox_util::micropub::{Error as MicropubError, ErrorKind as ErrorType}; use kittybox_indieauth::Scope; @@ -32,7 +32,7 @@ pub(crate) async fn upload<S: MediaStore, A: AuthBackend>( error_description: "Interacting with the media storage requires the \"media\" scope.".to_owned() }.into_response(); } - let host = user.me.host().unwrap().to_string() + &user.me.port().map(|i| format!(":{}", i)).unwrap_or_default(); + let host = user.me.authority(); let field = match upload.next_field().await { Ok(Some(field)) => field, Ok(None) => { @@ -49,7 +49,7 @@ pub(crate) async fn upload<S: MediaStore, A: AuthBackend>( }, }; let metadata: Metadata = (&field).into(); - match blobstore.write_streaming(&host, metadata, field).await { + match blobstore.write_streaming(host, metadata, field).await { Ok(filename) => IntoResponse::into_response(( axum::http::StatusCode::CREATED, [ @@ -103,10 +103,7 @@ pub(crate) async fn serve<S: MediaStore>( ).unwrap() ); if let Some(length) = metadata.length { - headers.insert( - "Content-Length", - HeaderValue::from_str(&length.to_string()).unwrap() - ); + headers.typed_insert(ContentLength(length.get().try_into().unwrap())); } if let Some(etag) = etag { headers.typed_insert(etag); diff --git a/src/media/storage/mod.rs b/src/media/storage/mod.rs index c2a66ec..b6f6ad7 100644 --- a/src/media/storage/mod.rs +++ b/src/media/storage/mod.rs @@ -164,7 +164,7 @@ pub trait MediaStore: 'static + Send + Sync + Clone { .map_ok(|x| x.unwrap()) ); - return Ok(stream); + Ok(stream) } } /// Read metadata for a file. |