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.

67 lines
1.5 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
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 audioTpl = pongo2.Must(pongo2.FromCache("templates/display/audio.html"))
  13. var videoTpl = pongo2.Must(pongo2.FromCache("templates/display/video.html"))
  14. var fileTpl = pongo2.Must(pongo2.FromCache("templates/display/file.html"))
  15. var pdfTpl = pongo2.Must(pongo2.FromCache("templates/display/pdf.html"))
  16. func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  17. fileName := c.URLParams["name"]
  18. filePath := path.Join(Config.filesDir, fileName)
  19. fileInfo, err := os.Stat(filePath)
  20. if os.IsNotExist(err) {
  21. notFoundHandler(c, w, r)
  22. return
  23. }
  24. // file expiry checking
  25. if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE |
  26. magicmime.MAGIC_SYMLINK |
  27. magicmime.MAGIC_ERROR); err != nil {
  28. oopsHandler(c, w, r)
  29. }
  30. defer magicmime.Close()
  31. mimetype, err := magicmime.TypeByFile(filePath)
  32. if err != nil {
  33. oopsHandler(c, w, r)
  34. }
  35. var tpl *pongo2.Template
  36. if strings.HasPrefix(mimetype, "image/") {
  37. tpl = imageTpl
  38. } else if strings.HasPrefix(mimetype, "video/") {
  39. tpl = videoTpl
  40. } else if strings.HasPrefix(mimetype, "audio/") {
  41. tpl = audioTpl
  42. } else if mimetype == "application/pdf" {
  43. tpl = pdfTpl
  44. } else {
  45. tpl = fileTpl
  46. }
  47. err = tpl.ExecuteWriter(pongo2.Context{
  48. "mime": mimetype,
  49. "filename": fileName,
  50. "size": fileInfo.Size(),
  51. }, w)
  52. if err != nil {
  53. oopsHandler(c, w, r)
  54. }
  55. }