@@ -100,6 +100,7 @@ func Start() {
100100 mux .HandleFunc ("/changePassword" , requireLogin (changePassword , true , true ))
101101 mux .HandleFunc ("/d" , showDownload )
102102 mux .HandleFunc ("/downloadFile" , downloadFile )
103+ mux .HandleFunc ("/downloadPresigned" , requireLogin (downloadPresigned , false , false ))
103104 mux .HandleFunc ("/e2eSetup" , requireLogin (showE2ESetup , true , false ))
104105 mux .HandleFunc ("/error" , showError )
105106 mux .HandleFunc ("/error-auth" , showErrorAuth )
@@ -909,6 +910,33 @@ func downloadFile(w http.ResponseWriter, r *http.Request) {
909910 serveFile (id , true , w , r )
910911}
911912
913+ // Handling of /downloadPresigned
914+ // Outputs the file to the user and reduces the download remaining count for the file, if requested
915+ func downloadPresigned (w http.ResponseWriter , r * http.Request ) {
916+ id , ok := r .URL .Query ()["id" ]
917+ if ! ok || len (id [0 ]) < configuration .Get ().LengthId {
918+ responseError (w , storage .ErrorFileNotFound )
919+ return
920+ }
921+ presignKey , ok := r .URL .Query ()["key" ]
922+ if ! ok {
923+ responseError (w , storage .ErrorInvalidPresign )
924+ return
925+ }
926+ presign , ok := database .GetPresignedUrl (presignKey [0 ])
927+ if ! ok || presign .Expiry < time .Now ().Unix () || presign .FileId != id [0 ] {
928+ responseError (w , storage .ErrorInvalidPresign )
929+ return
930+ }
931+ savedFile , ok := storage .GetFile (presign .FileId )
932+ if ! ok {
933+ responseError (w , storage .ErrorFileNotFound )
934+ return
935+ }
936+ database .DeletePresignedUrl (presign .Id )
937+ storage .ServeFile (savedFile , w , r , true , false )
938+ }
939+
912940func serveFile (id string , isRootUrl bool , w http.ResponseWriter , r * http.Request ) {
913941 addNoCacheHeader (w )
914942 savedFile , ok := storage .GetFile (id )
0 commit comments