更新很多文件

This commit is contained in:
deepzz0
2016-12-23 22:59:26 +08:00
parent 53f7623b22
commit 39509efe92
14 changed files with 161 additions and 23 deletions

View File

@@ -26,7 +26,9 @@ func PostsCount() {
if setting.Conf.Disqus.PostsCount == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" {
return
}
baseUrl := setting.Conf.Disqus.PostsCount + "?api_key=" + setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName + "&"
baseUrl := setting.Conf.Disqus.PostsCount +
"?api_key=" + setting.Conf.Disqus.PublicKey +
"&forum=" + setting.Conf.Disqus.ShortName + "&"
var count, index int
for index < len(Ei.Articles) {
logd.Debugf("count=====%d, index=======%d, length=======%d, bool=========%t\n", count, index, len(Ei.Articles), index < len(Ei.Articles) && count < 50)
@@ -88,6 +90,7 @@ type postsList struct {
Cache string
}
}
Thread string
}
}
@@ -95,9 +98,12 @@ func PostsList(slug, cursor string) *postsList {
if setting.Conf.Disqus.PostsList == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" {
return nil
}
url := setting.Conf.Disqus.PostsList + "?limit=50&api_key=" + setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName + "&cursor=" + cursor + "&thread:ident=post-" + slug
url := setting.Conf.Disqus.PostsList + "?limit=50&api_key=" +
setting.Conf.Disqus.PublicKey + "&forum=" + setting.Conf.Disqus.ShortName +
"&cursor=" + cursor + "&thread:ident=post-" + slug
resp, err := http.Get(url)
if err != nil {
logd.Error(err)
return nil
}
defer resp.Body.Close()
@@ -118,3 +124,63 @@ func PostsList(slug, cursor string) *postsList {
}
return pl
}
type PostCreate struct {
Message string `json:"message"`
Parent string `json:"parent"`
Thread string `json:"thread"`
AuthorEmail string `json:"author_email"`
AuthorName string `json:"autor_name"`
IpAddress string `json:"ip_address"`
Identifier string `json:"identifier"`
UserAgent string `json:"user_agent"`
}
type PostResponse struct {
Code int `json:"code"`
Response struct {
Id string `json:"id"`
} `json:"response"`
}
func PostComment(pc *PostCreate) string {
if setting.Conf.Disqus.PostsList == "" || setting.Conf.Disqus.PublicKey == "" || setting.Conf.Disqus.ShortName == "" {
return ""
}
url := setting.Conf.Disqus.PostCreate +
"?api_key=E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F" +
"&message=" + pc.Message + "&parent=" + pc.Parent +
"&thread=" + pc.Thread + "&author_email=" + pc.AuthorEmail +
"&author_name=" + pc.AuthorName
request, err := http.NewRequest("POST", url, nil)
if err != nil {
logd.Error(err)
return ""
}
request.Header.Set("Referer", "https://disqus.com")
logd.Print(*request)
resp, err := http.DefaultClient.Do(request)
if err != nil {
logd.Error(err)
return ""
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
logd.Error(err)
return ""
}
if resp.StatusCode != http.StatusOK {
logd.Error(string(b))
return ""
}
pr := &PostResponse{}
err = json.Unmarshal(b, pr)
if err != nil {
logd.Error(err)
return ""
}
logd.Print(pr.Response.Id)
return pr.Response.Id
}