@@ -406,7 +406,7 @@ pub(crate) async fn group_upload_artifact(
406406 task : StoredTaskModel ,
407407 content_type : ArtifactContentType ,
408408 content_length : u64 ,
409- ) -> Result < String , crate :: error:: Error > {
409+ ) -> Result < ( bool , String ) , crate :: error:: Error > {
410410 let now = TimeDateTimeWithTimeZone :: now_utc ( ) ;
411411 let content_length = content_length as i64 ;
412412 let ( uuid, group_id) = match task {
@@ -425,9 +425,10 @@ pub(crate) async fn group_upload_artifact(
425425 }
426426 let s3_client = pool. s3 . clone ( ) ;
427427 let artifacts_bucket = pool. artifacts_bucket . clone ( ) ;
428- let url = pool
428+ // This returns (exist, url)
429+ let resp = pool
429430 . db
430- . transaction :: < _ , String , Error > ( |txn| {
431+ . transaction :: < _ , ( bool , String ) , Error > ( |txn| {
431432 Box :: pin ( async move {
432433 // Update the task to reflect the artifact upload
433434 match task {
@@ -456,7 +457,7 @@ pub(crate) async fn group_upload_artifact(
456457 let s3_object_key = format ! ( "{uuid}/{content_type}" ) ;
457458 let url: String ;
458459 // Check group storage quota and allocate storage for the artifact
459- match artifact {
460+ let exist = match artifact {
460461 Some ( artifact) => {
461462 let recorded_content_length = content_length. max ( artifact. size ) ;
462463 let new_storage_used =
@@ -486,6 +487,7 @@ pub(crate) async fn group_upload_artifact(
486487 ..Default :: default ( )
487488 } ;
488489 group. update ( txn) . await ?;
490+ true
489491 }
490492 None => {
491493 let new_storage_used = group. storage_used + content_length;
@@ -516,13 +518,14 @@ pub(crate) async fn group_upload_artifact(
516518 ..Default :: default ( )
517519 } ;
518520 group. update ( txn) . await ?;
521+ false
519522 }
520- }
521- Ok ( url)
523+ } ;
524+ Ok ( ( exist , url) )
522525 } )
523526 } )
524527 . await ?;
525- Ok ( url )
528+ Ok ( resp )
526529}
527530
528531pub async fn user_upload_artifact (
@@ -531,7 +534,7 @@ pub async fn user_upload_artifact(
531534 uuid : Uuid ,
532535 content_type : ArtifactContentType ,
533536 content_length : u64 ,
534- ) -> Result < String , crate :: error:: Error > {
537+ ) -> Result < ( bool , String ) , crate :: error:: Error > {
535538 // Find the task and group
536539 let ( group_id, task) = find_task_by_uuid ( pool, uuid) . await ?;
537540 // Check if user has permission to upload artifact to the task
@@ -861,7 +864,7 @@ pub async fn user_upload_attachment(
861864 group_name : String ,
862865 key : String ,
863866 content_length : u64 ,
864- ) -> Result < String , crate :: error:: Error > {
867+ ) -> Result < ( bool , String ) , crate :: error:: Error > {
865868 tracing:: debug!(
866869 "Uploading attachment to group {} with key {} and size {}" ,
867870 group_name,
@@ -880,9 +883,9 @@ pub async fn user_upload_attachment(
880883 let s3_client = pool. s3 . clone ( ) ;
881884 let now = TimeDateTimeWithTimeZone :: now_utc ( ) ;
882885 let attachments_bucket = pool. attachments_bucket . clone ( ) ;
883- let uri = pool
886+ let resp = pool
884887 . db
885- . transaction :: < _ , String , crate :: error:: Error > ( |txn| {
888+ . transaction :: < _ , ( bool , String ) , crate :: error:: Error > ( |txn| {
886889 Box :: pin ( async move {
887890 let group = Group :: Entity :: find ( )
888891 . filter ( Group :: Column :: GroupName . eq ( group_name. clone ( ) ) )
@@ -907,7 +910,7 @@ pub async fn user_upload_attachment(
907910 . one ( txn)
908911 . await ?;
909912 let url: String ;
910- match attachment {
913+ let exist = match attachment {
911914 Some ( attachment) => {
912915 let recorded_content_length = content_length. max ( attachment. size ) ;
913916 let new_storage_used =
@@ -937,6 +940,7 @@ pub async fn user_upload_attachment(
937940 ..Default :: default ( )
938941 } ;
939942 group. update ( txn) . await ?;
943+ true
940944 }
941945 None => {
942946 let new_storage_used = group. storage_used + content_length;
@@ -968,13 +972,14 @@ pub async fn user_upload_attachment(
968972 ..Default :: default ( )
969973 } ;
970974 group. update ( txn) . await ?;
975+ false
971976 }
972- }
973- Ok ( url)
977+ } ;
978+ Ok ( ( exist , url) )
974979 } )
975980 } )
976981 . await ?;
977- Ok ( uri )
982+ Ok ( resp )
978983}
979984
980985// show_pb is used to show progress bar
0 commit comments