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.

59 lines
1.2 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
  1. package main
  2. import (
  3. "net/http"
  4. "os"
  5. "path"
  6. "strings"
  7. "github.com/flosch/pongo2"
  8. "github.com/rakyll/magicmime"
  9. "github.com/zenazn/goji/web"
  10. )
  11. var imageTpl = pongo2.Must(pongo2.FromCache("templates/display/image.html"))
  12. var videoTpl = pongo2.Must(pongo2.FromCache("templates/display/video.html"))
  13. var fileTpl = pongo2.Must(pongo2.FromCache("templates/display/file.html"))
  14. func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  15. fileName := c.URLParams["name"]
  16. filePath := path.Join(Config.filesDir, fileName)
  17. fileInfo, err := os.Stat(filePath)
  18. if os.IsNotExist(err) {
  19. notFoundHandler(c, w, r)
  20. return
  21. }
  22. if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE |
  23. magicmime.MAGIC_SYMLINK |
  24. magicmime.MAGIC_ERROR); err != nil {
  25. oopsHandler(c, w, r)
  26. }
  27. defer magicmime.Close()
  28. mimetype, err := magicmime.TypeByFile(filePath)
  29. if err != nil {
  30. oopsHandler(c, w, r)
  31. }
  32. var tpl *pongo2.Template
  33. if strings.HasPrefix(mimetype, "image/") {
  34. tpl = imageTpl
  35. } else if strings.HasPrefix(mimetype, "video/") {
  36. tpl = videoTpl
  37. } else {
  38. tpl = fileTpl
  39. }
  40. err = tpl.ExecuteWriter(pongo2.Context{
  41. "mime": mimetype,
  42. "filename": fileName,
  43. "size": fileInfo.Size(),
  44. }, w)
  45. if err != nil {
  46. oopsHandler(c, w, r)
  47. }
  48. }