preview: support multi-image albums
This commit is contained in:
parent
f27d14aac4
commit
14456e6539
73
preview.go
73
preview.go
@ -6,21 +6,13 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (this *Server) handlePreview(w http.ResponseWriter, fileID string) {
|
||||
m, err := this.Metadata(fileID)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
http.Error(w, "Not found", 404)
|
||||
return
|
||||
}
|
||||
func (this *Server) handlePreview(w http.ResponseWriter, fileIDList string) {
|
||||
|
||||
log.Println(err.Error())
|
||||
http.Error(w, "Internal error", 500)
|
||||
return
|
||||
}
|
||||
fileIDs := strings.Split(fileIDList, `-`)
|
||||
|
||||
tmpl := `<!DOCTYPE html>
|
||||
<html>
|
||||
@ -33,22 +25,59 @@ html, body {
|
||||
color: #F0F0F0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.entry {
|
||||
display: inline-block;
|
||||
margin: 4px;
|
||||
border-radius: 4px;
|
||||
max-width: 340px;
|
||||
}
|
||||
.thumbnail {
|
||||
line-height: 0;
|
||||
width: 340px;
|
||||
text-align: center;
|
||||
}
|
||||
.properties {
|
||||
background: #000;
|
||||
padding: 4px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="properties">
|
||||
<b>Name:</b> ` + html.EscapeString(m.Filename) + `<br>
|
||||
<b>Hash:</b> ` + html.EscapeString(m.FileHash) + `<br>
|
||||
<b>File type:</b> ` + html.EscapeString(m.MimeType) + `<br>
|
||||
<b>Size:</b> ` + html.EscapeString(fmt.Sprintf("%d", m.FileSize)) + `<br>
|
||||
<b>Uploader:</b> ` + html.EscapeString(m.UploadIP) + `<br>
|
||||
<b>Uploaded at:</b> ` + html.EscapeString(m.UploadTime.Format(time.RFC3339)) + `<br>
|
||||
`
|
||||
|
||||
for _, fileID := range fileIDs {
|
||||
m, err := this.Metadata(fileID)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
http.Error(w, "Not found", 404)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(err.Error())
|
||||
http.Error(w, "Internal error", 500)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl += `
|
||||
<div class="entry">
|
||||
<div class="thumbnail">
|
||||
<a href="` + html.EscapeString(`/get/`+fileID) + `"><img src="` + html.EscapeString(`/thumb/m/`+fileID) + `"></a>
|
||||
</div>
|
||||
<div class="properties">
|
||||
<b>Name:</b> ` + html.EscapeString(m.Filename) + `<br>
|
||||
<b>Hash:</b> <span title="` + html.EscapeString(m.FileHash) + `">hover</span><br>
|
||||
<b>File type:</b> ` + html.EscapeString(m.MimeType) + `<br>
|
||||
<b>Size:</b> ` + html.EscapeString(fmt.Sprintf("%d", m.FileSize)) + `<br>
|
||||
<b>Uploader:</b> ` + html.EscapeString(m.UploadIP) + `<br>
|
||||
<b>Uploaded at:</b> ` + html.EscapeString(m.UploadTime.Format(time.RFC3339)) + `<br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="thumbnail">
|
||||
<a href="` + html.EscapeString(`/get/`+fileID) + `"><img src="` + html.EscapeString(`/thumb/m/`+fileID) + `"></a>
|
||||
</div>
|
||||
`
|
||||
`
|
||||
}
|
||||
|
||||
if this.opts.EnableHomepage {
|
||||
tmpl += `
|
||||
<div class="return">
|
||||
|
Loading…
Reference in New Issue
Block a user