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.3 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. "github.com/flosch/pongo2"
  8. "github.com/rakyll/magicmime"
  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. if err := magicmime.Open(magicmime.MAGIC_MIME_TYPE |
  20. magicmime.MAGIC_SYMLINK |
  21. magicmime.MAGIC_ERROR); err != nil {
  22. oopsHandler(c, w, r)
  23. }
  24. defer magicmime.Close()
  25. mimetype, err := magicmime.TypeByFile(filePath)
  26. if err != nil {
  27. oopsHandler(c, w, r)
  28. }
  29. var tpl *pongo2.Template
  30. if strings.HasPrefix(mimetype, "image/") {
  31. tpl = Templates["display/image.html"]
  32. } else if strings.HasPrefix(mimetype, "video/") {
  33. tpl = Templates["display/video.html"]
  34. } else if strings.HasPrefix(mimetype, "audio/") {
  35. tpl = Templates["display/audio.html"]
  36. } else if mimetype == "application/pdf" {
  37. tpl = Templates["display/pdf.html"]
  38. } else {
  39. tpl = Templates["display/file.html"]
  40. }
  41. err = tpl.ExecuteWriter(pongo2.Context{
  42. "mime": mimetype,
  43. "filename": fileName,
  44. "size": fileInfo.Size(),
  45. }, w)
  46. if err != nil {
  47. oopsHandler(c, w, r)
  48. }
  49. }