選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

50 行
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. if isFileExist(path) {
  29. http.ServeFile(w, r, path)
  30. return
  31. }
  32. err = crmDownloadAttachmentAs(id, path)
  33. if err != nil {
  34. w.WriteHeader(http.StatusNotFound)
  35. fmt.Fprintf(w, "reference number is not right")
  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. }