Selaa lähdekoodia

serve crm cache file

master
Patrick Peng Sun 8 vuotta sitten
vanhempi
commit
46b3d70ae6
2 muutettua tiedostoa jossa 49 lisäystä ja 0 poistoa
  1. +48
    -0
      crmcache.go
  2. +1
    -0
      main.go

+ 48
- 0
crmcache.go Näytä tiedosto

@@ -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 Näytä tiedosto

@@ -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)
}


Loading…
Peruuta
Tallenna