v0.2.4
This commit is contained in:
parent
e8e3302f82
commit
27a71ae862
|
@ -246,7 +246,7 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "breeze"
|
name = "breeze"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "breeze"
|
name = "breeze"
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -33,6 +33,10 @@ pub struct EngineConfig {
|
||||||
/// Configuration for cache system
|
/// Configuration for cache system
|
||||||
pub cache: CacheConfig,
|
pub cache: CacheConfig,
|
||||||
|
|
||||||
|
/// Maximum size of an upload that will be accepted.
|
||||||
|
/// Files above this size can not be uploaded.
|
||||||
|
pub max_upload_len: Option<usize>,
|
||||||
|
|
||||||
/// Maximum lifetime of a temporary upload
|
/// Maximum lifetime of a temporary upload
|
||||||
#[serde_as(as = "DurationSeconds")]
|
#[serde_as(as = "DurationSeconds")]
|
||||||
pub max_temp_lifetime: Duration,
|
pub max_temp_lifetime: Duration,
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Disk {
|
||||||
/// Create a background I/O task
|
/// Create a background I/O task
|
||||||
pub async fn start_save(&self, saved_name: &str) -> Sender<Bytes> {
|
pub async fn start_save(&self, saved_name: &str) -> Sender<Bytes> {
|
||||||
// start a task that handles saving files to disk (we can save to cache/disk in parallel that way)
|
// start a task that handles saving files to disk (we can save to cache/disk in parallel that way)
|
||||||
let (tx, mut rx): (Sender<Bytes>, Receiver<Bytes>) = mpsc::channel(1);
|
let (tx, mut rx): (Sender<Bytes>, Receiver<Bytes>) = mpsc::channel(256);
|
||||||
|
|
||||||
let p = self.path_for(saved_name);
|
let p = self.path_for(saved_name);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ pub enum ProcessOutcome {
|
||||||
/// We give the user their file's URL
|
/// We give the user their file's URL
|
||||||
Success(String),
|
Success(String),
|
||||||
|
|
||||||
|
/// Occurs when an upload exceeds the chosen maximum file size.
|
||||||
|
UploadTooLarge,
|
||||||
|
|
||||||
/// Occurs when a temporary upload is too big to fit in the cache.
|
/// Occurs when a temporary upload is too big to fit in the cache.
|
||||||
TemporaryUploadTooLarge,
|
TemporaryUploadTooLarge,
|
||||||
|
|
||||||
|
@ -285,6 +288,11 @@ impl Engine {
|
||||||
lifetime: Option<Duration>,
|
lifetime: Option<Duration>,
|
||||||
keep_exif: bool,
|
keep_exif: bool,
|
||||||
) -> Result<ProcessOutcome, anyhow::Error> {
|
) -> Result<ProcessOutcome, anyhow::Error> {
|
||||||
|
// if the upload size is greater than our max file size, deny it now
|
||||||
|
if self.cfg.max_upload_len.is_some_and(|l| provided_len > l) {
|
||||||
|
return Ok(ProcessOutcome::UploadTooLarge);
|
||||||
|
}
|
||||||
|
|
||||||
// if the upload size is smaller than the specified maximum, we use the cache!
|
// if the upload size is smaller than the specified maximum, we use the cache!
|
||||||
let use_cache: bool = self.cache.will_use(provided_len);
|
let use_cache: bool = self.cache.will_use(provided_len);
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ async fn main() {
|
||||||
.await
|
.await
|
||||||
.expect("failed to bind to given `http.listen_on` address! make sure it's valid, and the port isn't already bound");
|
.expect("failed to bind to given `http.listen_on` address! make sure it's valid, and the port isn't already bound");
|
||||||
|
|
||||||
|
info!("starting server.");
|
||||||
axum::serve(listener, app)
|
axum::serve(listener, app)
|
||||||
.with_graceful_shutdown(shutdown_signal())
|
.with_graceful_shutdown(shutdown_signal())
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -81,7 +81,9 @@ pub async fn new(
|
||||||
ProcessOutcome::Success(url) => Ok(url),
|
ProcessOutcome::Success(url) => Ok(url),
|
||||||
|
|
||||||
// 413 Payload Too Large
|
// 413 Payload Too Large
|
||||||
ProcessOutcome::TemporaryUploadTooLarge => Err(StatusCode::PAYLOAD_TOO_LARGE),
|
ProcessOutcome::UploadTooLarge | ProcessOutcome::TemporaryUploadTooLarge => {
|
||||||
|
Err(StatusCode::PAYLOAD_TOO_LARGE)
|
||||||
|
}
|
||||||
|
|
||||||
// 400 Bad Request
|
// 400 Bad Request
|
||||||
ProcessOutcome::TemporaryUploadLifetimeTooLong => Err(StatusCode::BAD_REQUEST),
|
ProcessOutcome::TemporaryUploadLifetimeTooLong => Err(StatusCode::BAD_REQUEST),
|
||||||
|
|
Loading…
Reference in New Issue