package contented
import (
"fmt"
"html"
"log"
"net/http"
"os"
"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
}
log.Println(err.Error())
http.Error(w, "Internal error", 500)
return
}
tmpl := `
` + html.EscapeString(this.opts.ServerPublicProperties.AppTitle) + `
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)) + `
`
if this.opts.EnableHomepage {
tmpl += `
`
}
tmpl += `
`
w.Header().Set(`Content-Type`, `text/html; charset=UTF-8`)
w.Header().Set(`Content-Length`, fmt.Sprintf("%d", len(tmpl)))
w.WriteHeader(200)
w.Write([]byte(tmpl))
}