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.

65 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
  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 !fileExistsAndNotExpired(fileName) {
  21. notFoundHandler(c, w, r)
  22. return
  23. }
  24. if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE |
  25. magicmime.MAGIC_SYMLINK |
  26. magicmime.MAGIC_ERROR); err != nil {
  27. oopsHandler(c, w, r)
  28. }
  29. defer magicmime.Close()
  30. mimetype, err := magicmime.TypeByFile(filePath)
  31. if err != nil {
  32. oopsHandler(c, w, r)
  33. }
  34. var tpl *pongo2.Template
  35. if strings.HasPrefix(mimetype, "image/") {
  36. tpl = imageTpl
  37. } else if strings.HasPrefix(mimetype, "video/") {
  38. tpl = videoTpl
  39. } else if strings.HasPrefix(mimetype, "audio/") {
  40. tpl = audioTpl
  41. } else if mimetype == "application/pdf" {
  42. tpl = pdfTpl
  43. } else {
  44. tpl = fileTpl
  45. }
  46. err = tpl.ExecuteWriter(pongo2.Context{
  47. "mime": mimetype,
  48. "filename": fileName,
  49. "size": fileInfo.Size(),
  50. }, w)
  51. if err != nil {
  52. oopsHandler(c, w, r)
  53. }
  54. }