-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDownloadController.groovy
48 lines (40 loc) · 1.41 KB
/
DownloadController.groovy
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
41
42
43
44
45
46
47
48
package au.org.ala.merit
import grails.core.GrailsApplication
import javax.servlet.http.HttpServletResponse
class DownloadController {
private List DOWNLOAD_EXTENSIONS = ['xls', 'xlsx', 'zip', 'json', 'xml', 'pdf', 'csv']
GrailsApplication grailsApplication
WebService webService
UserService userService
/**
* Deliberately not add .format in urlMapping to support file.extension on purpose
* @param id - including extension
* @return
*/
def get(String id) {
if (!userService.userIsSiteAdmin() && !userService.userHasReadOnlyAccess()) {
redirect(controller:'home')
return
}
if (!id) {
response.setStatus(400)
render "A download ID is required"
} else {
String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}" +'download/'+id
String extension = params.fileExtension ?: params.format
if (fileExtensionValid(extension)) {
url += "."+extension
}
def resp = webService.proxyGetRequest(response, url, true, true, 120000)
if (resp.status != 200) {
render view:'/error', model:[error:resp.error]
}
else {
return null
}
}
}
private boolean fileExtensionValid(String fileExtension) {
fileExtension in DOWNLOAD_EXTENSIONS
}
}