Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package main
  2. import (
  3. "net/http"
  4. "os"
  5. "path"
  6. "strings"
  7. "bitbucket.org/taruti/mimemagic"
  8. "github.com/flosch/pongo2"
  9. "github.com/zenazn/goji/web"
  10. )
  11. func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  12. fileName := c.URLParams["name"]
  13. filePath := path.Join(Config.filesDir, fileName)
  14. fileInfo, err := os.Stat(filePath)
  15. if !fileExistsAndNotExpired(fileName) {
  16. notFoundHandler(c, w, r)
  17. return
  18. }
  19. file, _ := os.Open(filePath)
  20. header := make([]byte, 512)
  21. file.Read(header)
  22. file.Close()
  23. mimetype := mimemagic.Match("", header)
  24. var tpl *pongo2.Template
  25. if strings.HasPrefix(mimetype, "image/") {
  26. tpl = Templates["display/image.html"]
  27. } else if strings.HasPrefix(mimetype, "video/") {
  28. tpl = Templates["display/video.html"]
  29. } else if strings.HasPrefix(mimetype, "audio/") {
  30. tpl = Templates["display/audio.html"]
  31. } else if mimetype == "application/pdf" {
  32. tpl = Templates["display/pdf.html"]
  33. } else {
  34. tpl = Templates["display/file.html"]
  35. }
  36. err = tpl.ExecuteWriter(pongo2.Context{
  37. "mime": mimetype,
  38. "filename": fileName,
  39. "size": fileInfo.Size(),
  40. }, w)
  41. if err != nil {
  42. oopsHandler(c, w, r)
  43. }
  44. }