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.

47 lines
871 B

  1. package main
  2. import (
  3. "net/http"
  4. "os"
  5. "path"
  6. "strings"
  7. "github.com/zenazn/goji/web"
  8. )
  9. func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  10. fileName := c.URLParams["name"]
  11. filePath := path.Join(Config.filesDir, fileName)
  12. if !fileExistsAndNotExpired(fileName) {
  13. notFoundHandler(c, w, r)
  14. return
  15. }
  16. if !Config.allowHotlink {
  17. referer := r.Header.Get("Referer")
  18. if referer != "" && !strings.HasPrefix(referer, Config.siteURL) {
  19. w.WriteHeader(403)
  20. return
  21. }
  22. }
  23. http.ServeFile(w, r, filePath)
  24. }
  25. func fileExistsAndNotExpired(filename string) bool {
  26. filePath := path.Join(Config.filesDir, filename)
  27. _, err := os.Stat(filePath)
  28. if err != nil {
  29. return false
  30. }
  31. if isFileExpired(filename) {
  32. os.Remove(path.Join(Config.filesDir, filename))
  33. os.Remove(path.Join(Config.metaDir, filename))
  34. return false
  35. }
  36. return true
  37. }