Bläddra i källkod

serve crm cache file

master
Patrick Peng Sun 8 år sedan
förälder
incheckning
46b3d70ae6
2 ändrade filer med 49 tillägg och 0 borttagningar
  1. +48
    -0
      crmcache.go
  2. +1
    -0
      main.go

+ 48
- 0
crmcache.go Visa fil

@@ -0,0 +1,48 @@
package main

import (
"fmt"
"net/http"
"net/url"
)

func crmcache(w http.ResponseWriter, r *http.Request) {
// if !checkSignature(r) {
// w.WriteHeader(http.StatusUnauthorized)
// fmt.Fprintf(w, "Expired or invalid link")
// }

v, err := url.ParseQuery(r.URL.RawQuery)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "parse query not valid")
return
}
attachmentid, ok := v["a"]
if !ok {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "reference number is not found")
return
}
id := attachmentid[0]
path := crmcacheFileName(id)

err = crmDownloadAttachmentAs(id, path)

if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "reference number is not right")
}

if isFileExist(path) {
http.ServeFile(w, r, path)
return
}

w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "cannot build reference cache")
}

func crmcacheFileName(id string) string {
return CRMConfig.AttachmentCache + id
}

+ 1
- 0
main.go Visa fil

@@ -64,6 +64,7 @@ func setupHTTPHandler() {
http.HandleFunc("/iapi/getAccessToken", supplyAccessToken)
http.HandleFunc("/iapi/createWechatQr", iapiCreateWechatQrCode)
http.HandleFunc("/crmpixel.png", crmpixel) //tracking pixel.
http.HandleFunc("/crmcache", crmcache)
http.ListenAndServe(":65500", nil)
}


Laddar…
Avbryt
Spara