Download template PDF and zip file with good file names

This commit is contained in:
James Allen 2014-08-12 12:02:09 +01:00
parent 2aa421233c
commit 3348249dcd
3 changed files with 20 additions and 4 deletions

View file

@ -36,7 +36,17 @@ module.exports = TemplatesWebController =
proxyToTemplatesApi: (req, res)-> proxyToTemplatesApi: (req, res)->
url = req.url url = req.url
logger.log url:url, "proxying request to templates api"
name = req.query.name or "Template"
if req.query.inline?
disposition = "inline"
else
disposition = "attachment"
console.log "HEADER", "#{disposition}; filename=#{name};"
res.header({"content-disposition": "#{disposition}; filename=#{name}.#{req.params.file_type};"})
logger.log url:url, template_name: name, disposition: disposition, "proxying request to templates api"
getReq = request.get("#{settings.apis.templates_api.url}#{url}") getReq = request.get("#{settings.apis.templates_api.url}#{url}")
getReq.pipe(res) getReq.pipe(res)
getReq.on "error", (error) -> getReq.on "error", (error) ->

View file

@ -20,8 +20,8 @@ block content
.col-md-6 .col-md-6
.entry .entry
.row .row
.col-md-12 .col-md-12.template-large-pdf-preview
a(href=template.pdfUrl) a(href="#{template.pdfUrl}?inline=true&name=#{template.name}")
img(src="#{template.previewUrl}") img(src="#{template.previewUrl}")
.col-md-6 .col-md-6
@ -33,7 +33,7 @@ block content
|   |  
a.btn.btn-default( a.btn.btn-default(
href=template.zipUrl, href="#{template.zipUrl}?name=#{template.name}",
rel='nofollow', rel='nofollow',
ng-click='downloadZip()', ng-click='downloadZip()',
tooltip-placement="bottom", tooltip-placement="bottom",

View file

@ -56,4 +56,10 @@
max-width: 100%; max-width: 100%;
height: auto; height: auto;
} }
}
.template-large-pdf-preview {
img {
max-width: 100%;
}
} }