No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

51 líneas
1.0KB

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