File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,10 @@ public function downloadAction(int $submitId): Response
242
242
$ submitId ));
243
243
}
244
244
245
+ if ($ this ->submissionService ->getSubmissionFileCount ($ submission ) === 1 ) {
246
+ return $ this ->submissionService ->getSubmissionFileResponse ($ submission );
247
+ }
248
+
245
249
return $ this ->submissionService ->getSubmissionZipResponse ($ submission );
246
250
}
247
251
}
Original file line number Diff line number Diff line change @@ -768,4 +768,31 @@ public function getSubmissionZipResponse(Submission $submission): StreamedRespon
768
768
769
769
return Utils::streamZipFile ($ tmpfname , 's ' . $ submission ->getSubmitid () . '.zip ' );
770
770
}
771
+
772
+ public function getSubmissionFileResponse (Submission $ submission ): StreamedResponse
773
+ {
774
+ /** @var SubmissionFile[] $files */
775
+ $ files = $ submission ->getFiles ();
776
+
777
+ if (count ($ files ) !== 1 ) {
778
+ throw new ServiceUnavailableHttpException (null , 'Submission does not contain exactly one file. ' );
779
+ }
780
+
781
+ $ file = $ files [0 ];
782
+ $ filename = $ file ->getFilename ();
783
+ $ sourceCode = $ file ->getSourcecode ();
784
+
785
+ return new StreamedResponse (function () use ($ sourceCode ) {
786
+ echo $ sourceCode ;
787
+ }, 200 , [
788
+ 'Content-Type ' => 'text/plain ' ,
789
+ 'Content-Disposition ' => 'attachment; filename=" ' . $ filename . '" ' ,
790
+ 'Content-Length ' => strlen ($ sourceCode ),
791
+ ]);
792
+ }
793
+
794
+ public function getSubmissionFileCount (Submission $ submission ): int
795
+ {
796
+ return count ($ submission ->getFiles ());
797
+ }
771
798
}
You can’t perform that action at this time.
0 commit comments