@@ -38,8 +38,6 @@ use rocket_cors::{AllowedOrigins, CorsOptions};
3838use serde:: { Deserialize , Serialize } ;
3939use store:: { FileState , Store } ;
4040
41- const CHUNK_SIZE : u64 = ( 1024 * 1024 ) * 5 ; // 5 MB
42-
4341#[ derive( Serialize , Deserialize ) ]
4442struct InitBody {
4543 recipient : String ,
@@ -301,7 +299,7 @@ async fn upload_chunk(
301299 ) ) ) ;
302300 }
303301
304- if end - start > CHUNK_SIZE {
302+ if end - start > config . chunk_size ( ) {
305303 return Err ( Error :: BadRequest ( Some (
306304 "File chunk too large; the maximum is 1 MB" . to_owned ( ) ,
307305 ) ) ) ;
@@ -329,7 +327,7 @@ async fn upload_chunk(
329327
330328 let byte_stream = data. into_inner ( ) ;
331329
332- let part_number = ( start / CHUNK_SIZE + 1 ) as i32 ;
330+ let part_number = ( start / config . chunk_size ( ) + 1 ) as i32 ;
333331 let upload_part_res = client
334332 . upload_part ( )
335333 . bucket ( bucket_name)
@@ -469,7 +467,7 @@ async fn upload_finalize(
469467 . into_async_read ( )
470468 . compat ( ) ;
471469 } else {
472- // read with the s3 client so it's the same type as above but still works for local files
470+ // read with the s3 client, so it's the same type as above but still works for local files
473471 file = aws_sdk_s3:: primitives:: ByteStream :: from_path ( Path :: new ( config. data_dir ( ) ) . join ( uuid) )
474472 . await
475473 . map_err ( |_| Error :: InternalServerError ( Some ( "could not open file" . to_string ( ) ) ) ) ?
@@ -500,7 +498,7 @@ async fn upload_finalize(
500498}
501499
502500#[ get( "/<uuid>" ) ]
503- async fn s3fileServer (
501+ async fn s3_file_server (
504502 _config : & State < CryptifyConfig > ,
505503 _store : & State < Store > ,
506504 s3_client : & State < Option < store:: S3Client > > ,
@@ -575,8 +573,8 @@ async fn rocket() -> _ {
575573
576574 // conditionally mount the file download routes
577575 if s3_client. is_some ( ) {
578- rocket = rocket. mount ( "/filedownload" , routes ! [ s3fileServer ] ) ;
579- if CHUNK_SIZE < 5 * 1024 * 1024 {
576+ rocket = rocket. mount ( "/filedownload" , routes ! [ s3_file_server ] ) ;
577+ if config . chunk_size ( ) < 5 * 1024 * 1024 { // 5 MB is the usual minimum for S3 multipart uploads
580578 log:: warn!( "S3 storage is enabled, but CHUNK_SIZE is less than 5 MB. This may lead to failing uploads." ) ;
581579 }
582580 } else {
0 commit comments