add download handler
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{{ define "content" }}
|
||||
<h3>A simple API to store, search and download books.</h3>
|
||||
<h3>A simple API to store, search and download books, articles, etc...</h3>
|
||||
<div>No extra JS, CSS or fancy stuff. You click, you search, you found, you're happy.</div>
|
||||
<form action="/home" method="post" enctype="multipart/form-data">
|
||||
<div class="main-container">
|
||||
@@ -27,17 +27,19 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Editor</th>
|
||||
<th>Authors</th>
|
||||
<th>Year</th>
|
||||
</tr>
|
||||
{{range .Results}}
|
||||
<tr>
|
||||
<td><div style="margin: 10px;">{{.Name}}</div></td>
|
||||
<td><div style="margin: 10px; word-wrap: break-word; width: 300px;">{{.Name}}</div></td>
|
||||
<td><div style="margin: 10px; word-wrap: break-word; width: 300px;">{{.Description | noDesc}}</div></td>
|
||||
<td style="text-align: center;"><div style="margin: 10px;">{{.Editor}}</div></td>
|
||||
<td style="text-align: center;"><div style="margin: 10px;">{{.Authors | join }}</div></td>
|
||||
<td style="text-align: center; word-wrap: break-word; width: 300px;"><div style="margin: 10px;">{{.Authors | join }}</div></td>
|
||||
<td><div style="margin: 20px;">{{.Year}}</div></td>
|
||||
<td><div style="margin: 20px;">{{.Path | bookUrl}}</div></td>
|
||||
<td><div style="margin: 20px;"><a target="_blank" href="{{.Path | bookUrl}}">Download</a></div></td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
|
||||
@@ -39,7 +39,7 @@ var funcMap = template.FuncMap{
|
||||
if len(s) == 0 {
|
||||
return ""
|
||||
} else {
|
||||
return strings.Join(s, ",")
|
||||
return strings.Join(s, ", ")
|
||||
}
|
||||
},
|
||||
"filename": func(h *multipart.FileHeader) string {
|
||||
@@ -56,7 +56,13 @@ var funcMap = template.FuncMap{
|
||||
},
|
||||
"bookUrl": func(path string) string {
|
||||
_, filename := filepath.Split(path)
|
||||
return fmt.Sprintf("https://books.thegux.fr/downloads/%s", filename)
|
||||
return fmt.Sprintf("/download?file=%s", filename)
|
||||
},
|
||||
"noDesc": func(desc *string) string {
|
||||
if desc == nil {
|
||||
return ""
|
||||
}
|
||||
return *desc
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user