@@ -77,16 +77,15 @@ async fn upload_file(
7777 let username_hash = hex:: encode ( hasher. finalize ( ) ) ;
7878
7979 // Path to files storage
80- let storage_path = std:: env:: var ( "FILES_STORAGE_PATH" ) . unwrap ( ) ;
81- let path = format ! ( "{}/{}/{}" , storage_path, username_hash, form. json. filename. clone( ) ) ;
80+ let path = format ! ( "{}/{}/{}" , data. storage_dir, username_hash, form. json. filename. clone( ) ) ;
8281
8382 // Check if file already exists
8483 if Path :: new ( path. as_str ( ) ) . exists ( ) {
8584 debug ! ( "File [{}] already exists" , path) ;
8685 return Err ( AppError :: BadRequest { msg : "File with this name already exists" . to_string ( ) } ) ;
8786 }
8887
89- let dir_path = format ! ( "{}/{}" , storage_path , username_hash) ;
88+ let dir_path = format ! ( "{}/{}" , data . storage_dir , username_hash) ;
9089
9190 // Create dirs for file of don't exist
9291 fs:: create_dir_all ( & dir_path) . await
@@ -170,7 +169,7 @@ async fn download_shared_file(share_code: web::Path<String>, req: HttpRequest, d
170169 } ) ?;
171170
172171 // Validate the share code
173- let file_id = match conn. get :: < _ , Option < i32 > > ( share_code. clone ( ) ) . await {
172+ let file_id: i32 = match conn. get ( share_code. clone ( ) ) . await {
174173 Ok ( Some ( id) ) => {
175174 debug ! ( "File ID valid: {}" , id) ;
176175 id
@@ -268,7 +267,7 @@ async fn share_file(file_id: web::Path<i32>, req: HttpRequest, data: web::Data<A
268267 AppError :: InternalServerError { msg : "Connection to Redis lost" . to_string ( ) }
269268 } ) ?;
270269
271- // Delete the previous code if exists
270+ // Delete the previous code if exists
272271 if let Ok ( Some ( old_code) ) = conn. get :: < _ , Option < String > > ( file_id) . await {
273272 // Delete old code key
274273 let _: ( ) = conn. del ( & old_code) . await . map_err ( |_| {
@@ -295,15 +294,15 @@ async fn share_file(file_id: web::Path<i32>, req: HttpRequest, data: web::Data<A
295294 Some ( _) => { /* Key already exists, continue */ } ,
296295 None => {
297296 // Code is unique, add it to redis with 5 minutes expiration time
298- conn . set_ex :: < _ , _ , ( ) > ( key, file_id, 5 * 60 ) . await
297+ let _ : ( ) = conn . set_ex ( key, file_id, 5 * 60 ) . await
299298 . map_err ( |_| {
300299 warn ! ( "Failed to save share code [{}]" , share_code) ;
301300 AppError :: InternalServerError { msg : "Failed to save share code" . to_string ( ) }
302301 } ) ?;
303302
304303 // Reverse map, for accessing current share code for a file.
305304 // Overwrites previous data.
306- conn . set_ex :: < _ , _ , ( ) > ( file_id, key, 5 * 60 ) . await
305+ let _ : ( ) = conn . set_ex ( file_id, key, 5 * 60 ) . await
307306 . map_err ( |_| {
308307 warn ! ( "Failed to save reverse mapping for share code [{}]" , share_code) ;
309308 AppError :: InternalServerError { msg : "Failed to save reverse mapping for share code" . to_string ( ) }
0 commit comments