From 14456e6539362ded3bc60a22f5c2975ceb8e5c6d Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 18 Nov 2017 14:11:20 +1300 Subject: [PATCH] preview: support multi-image albums --- preview.go | 73 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/preview.go b/preview.go index a22a5e5..84f6f6f 100644 --- a/preview.go +++ b/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 := ` @@ -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; +} +
-
- Name: ` + html.EscapeString(m.Filename) + `
- Hash: ` + html.EscapeString(m.FileHash) + `
- File type: ` + html.EscapeString(m.MimeType) + `
- Size: ` + html.EscapeString(fmt.Sprintf("%d", m.FileSize)) + `
- Uploader: ` + html.EscapeString(m.UploadIP) + `
- Uploaded at: ` + html.EscapeString(m.UploadTime.Format(time.RFC3339)) + `
+ ` + + 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 += ` +
+
+ +
+
+ Name: ` + html.EscapeString(m.Filename) + `
+ Hash: hover
+ File type: ` + html.EscapeString(m.MimeType) + `
+ Size: ` + html.EscapeString(fmt.Sprintf("%d", m.FileSize)) + `
+ Uploader: ` + html.EscapeString(m.UploadIP) + `
+ Uploaded at: ` + html.EscapeString(m.UploadTime.Format(time.RFC3339)) + `
+
-
- -
-` + ` + } + if this.opts.EnableHomepage { tmpl += `