Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

49 lines
976B

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "net/url"
  6. )
  7. func crmcache(w http.ResponseWriter, r *http.Request) {
  8. // if !checkSignature(r) {
  9. // w.WriteHeader(http.StatusUnauthorized)
  10. // fmt.Fprintf(w, "Expired or invalid link")
  11. // }
  12. v, err := url.ParseQuery(r.URL.RawQuery)
  13. if err != nil {
  14. w.WriteHeader(http.StatusNotFound)
  15. fmt.Fprintf(w, "parse query not valid")
  16. return
  17. }
  18. attachmentid, ok := v["a"]
  19. if !ok {
  20. w.WriteHeader(http.StatusNotFound)
  21. fmt.Fprintf(w, "reference number is not found")
  22. return
  23. }
  24. id := attachmentid[0]
  25. path := crmcacheFileName(id)
  26. err = crmDownloadAttachmentAs(id, path)
  27. if err != nil {
  28. w.WriteHeader(http.StatusNotFound)
  29. fmt.Fprintf(w, "reference number is not right")
  30. }
  31. if isFileExist(path) {
  32. http.ServeFile(w, r, path)
  33. return
  34. }
  35. w.WriteHeader(http.StatusInternalServerError)
  36. fmt.Fprintf(w, "cannot build reference cache")
  37. }
  38. func crmcacheFileName(id string) string {
  39. return CRMConfig.AttachmentCache + id
  40. }