@@ -12,7 +12,7 @@ use serde_json::Value;
1212use crate :: {
1313 CONFIG ,
1414 api:: { ApiResult , EmptyResult , JsonResult , Notify , UpdateType } ,
15- auth:: { ClientIp , Headers , Host } ,
15+ auth:: { ClientIp , Headers , Host , SendHeaders } ,
1616 config:: PathType ,
1717 db:: {
1818 DbConn , DbPool ,
@@ -48,7 +48,9 @@ pub fn routes() -> Vec<rocket::Route> {
4848 post_send,
4949 post_send_file,
5050 post_access,
51+ post_access_legacy,
5152 post_access_file,
53+ post_access_file_legacy,
5254 put_send,
5355 delete_send,
5456 put_remove_password,
@@ -371,7 +373,7 @@ pub struct SendFileData {
371373}
372374
373375// https://github.com/bitwarden/server/blob/9ebe16587175b1c0e9208f84397bb75d0d595510/src/Api/Tools/Controllers/SendsController.cs#L195
374- #[ post( "/sends/<send_id>/file/<file_id>" , format = "multipart/form-data" , data = "<data>" ) ]
376+ #[ post( "/sends/<send_id>/file/<file_id>" , format = "multipart/form-data" , data = "<data>" , rank = 2 ) ]
375377async fn post_send_file_v2_data (
376378 send_id : SendId ,
377379 file_id : SendFileId ,
@@ -441,14 +443,23 @@ async fn post_send_file_v2_data(
441443 Ok ( ( ) )
442444}
443445
446+ #[ post( "/sends/access" ) ]
447+ async fn post_access ( headers : SendHeaders , conn : DbConn , nt : Notify < ' _ > ) -> JsonResult {
448+ let Some ( send) = Send :: find_by_uuid ( & headers. send_id , & conn) . await else {
449+ err_code ! ( SEND_INACCESSIBLE_MSG , 404 )
450+ } ;
451+ process_access ( send, conn, nt) . await
452+ }
453+
444454#[ derive( Deserialize ) ]
445455#[ serde( rename_all = "camelCase" ) ]
446456pub struct SendAccessData {
447457 pub password : Option < String > ,
448458}
449459
460+ // Legacy since web-2026.6.0
450461#[ post( "/sends/access/<access_id>" , data = "<data>" ) ]
451- async fn post_access (
462+ async fn post_access_legacy (
452463 access_id : & str ,
453464 data : Json < SendAccessData > ,
454465 conn : DbConn ,
@@ -479,6 +490,13 @@ async fn post_access(
479490 err_code ! ( SEND_INACCESSIBLE_MSG , 404 )
480491 }
481492
493+ // Files are incremented during the download
494+ if send. atype == SendType :: Text as i32 {
495+ send. access_count += 1 ;
496+ }
497+
498+ send. save ( & conn) . await ?;
499+
482500 if send. password_hash . is_some ( ) {
483501 match data. into_inner ( ) . password {
484502 Some ( ref p) if send. check_password ( p) => { /* Nothing to do here */ }
@@ -487,13 +505,10 @@ async fn post_access(
487505 }
488506 }
489507
490- // Files are incremented during the download
491- if send. atype == SendType :: Text as i32 {
492- send. access_count += 1 ;
493- }
494-
495- send. save ( & conn) . await ?;
508+ process_access ( send, conn, nt) . await
509+ }
496510
511+ async fn process_access ( send : Send , conn : DbConn , nt : Notify < ' _ > ) -> JsonResult {
497512 nt. send_send_update (
498513 UpdateType :: SyncSendUpdate ,
499514 & send,
@@ -506,8 +521,23 @@ async fn post_access(
506521 Ok ( Json ( send. to_json_access ( & conn) . await ) )
507522}
508523
509- #[ post( "/sends/<send_id>/ access/file/<file_id>" , data = "<data>" ) ]
524+ #[ post( "/sends/access/file/<file_id>" , rank = 1 ) ]
510525async fn post_access_file (
526+ file_id : SendFileId ,
527+ headers : SendHeaders ,
528+ host : Host ,
529+ conn : DbConn ,
530+ nt : Notify < ' _ > ,
531+ ) -> JsonResult {
532+ let Some ( send) = Send :: find_by_uuid ( & headers. send_id , & conn) . await else {
533+ err_code ! ( SEND_INACCESSIBLE_MSG , 404 )
534+ } ;
535+ process_access_file ( send, file_id, host, conn, nt) . await
536+ }
537+
538+ // Legacy since web-2026.6.0
539+ #[ post( "/sends/<send_id>/access/file/<file_id>" , data = "<data>" ) ]
540+ async fn post_access_file_legacy (
511541 send_id : SendId ,
512542 file_id : SendFileId ,
513543 data : Json < SendAccessData > ,
@@ -551,6 +581,10 @@ async fn post_access_file(
551581
552582 send. save ( & conn) . await ?;
553583
584+ process_access_file ( send, file_id, host, conn, nt) . await
585+ }
586+
587+ async fn process_access_file ( send : Send , file_id : SendFileId , host : Host , conn : DbConn , nt : Notify < ' _ > ) -> JsonResult {
554588 nt. send_send_update (
555589 UpdateType :: SyncSendUpdate ,
556590 & send,
@@ -563,7 +597,7 @@ async fn post_access_file(
563597 Ok ( Json ( json ! ( {
564598 "object" : "send-fileDownload" ,
565599 "id" : file_id,
566- "url" : download_url( & host, & send_id , & file_id) . await ?,
600+ "url" : download_url( & host, & send . uuid , & file_id) . await ?,
567601 } ) ) )
568602}
569603
0 commit comments