Leonardo Vannucci
2018-10-01 59454f87bedb0b19b772ea93eabbb2bec910a150
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package it.digione.dg1cloud.controller;
 
import java.io.IOException;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
 
import it.digione.dg1cloud.recaptcha.CaptchaSettings;
import it.digione.dg1cloud.service.Utils;
 
@Controller
public class DownloadFileController {
   
   private static final Logger logger = LoggerFactory.getLogger(DownloadFileController.class);
   
   @Autowired private Utils utils;
   @Autowired CaptchaSettings captchaSettings;
   
   @RequestMapping("/downloadFile")
   public ResponseEntity<InputStreamResource> downloadFile(@RequestParam String fileName,
                                           @RequestParam long id,
                                           @RequestParam(value = "secretKey", required = false) String secretKey) throws IOException {
       
       if ( captchaSettings.isEnabled() == true ) {
           String error = "Download diretto non ammesso. Usare la pagina di download tramite reCaptcha";
           logger.error(error);
           throw new RuntimeException("Download diretto non ammesso. Usare la pagina di download tramite reCaptcha");
       }
       
       return utils.getDownloadResponseEntity(fileName, id, secretKey);
   }
 
   
}