From e9d5072d4797fe8f4778f1a86fb2efb16080507e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E9=B9=8F?= Date: Mon, 11 Oct 2021 10:21:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:api=E6=8E=A8=E9=80=81=E7=99=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BlogController.go | 7 +++++-- utils/data_zz.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 utils/data_zz.go diff --git a/controllers/BlogController.go b/controllers/BlogController.go index 7a0297f..75498fa 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -86,6 +86,7 @@ func (this *BlogController) Save() { } this.ServeJSON() userService.CountBlog(uid.(int64)) + utils.PostDataZZ(blog.Id) return } @@ -129,6 +130,7 @@ func (this *BlogController) Edit() { } this.ServeJSON() userService.CountBlog(uid.(int64)) + utils.PostDataZZ(id) return } @@ -138,12 +140,12 @@ func (this *BlogController) Get() { idStr := this.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 10, 64) blog, err := blogService.GetBlog(id) - blog.User.Salt = "" - blog.User.UserPwd = "" if err != nil { this.Redirect("/404", 302) return } + blog.User.Salt = "" + blog.User.UserPwd = "" if uid := this.GetSession("userid"); uid != nil { if blog.UserId == uid.(int64) { this.Data["IsAuthor"] = true @@ -161,6 +163,7 @@ func (this *BlogController) Get() { userService.CountBrows(blog.UserId) blogService.EditBlogBrows(id) } + //utils.PostDataZZ(id) return } diff --git a/utils/data_zz.go b/utils/data_zz.go new file mode 100644 index 0000000..b393c46 --- /dev/null +++ b/utils/data_zz.go @@ -0,0 +1,30 @@ +package utils + +import ( + "io/ioutil" + "net/http" + "strconv" + "strings" +) + +//const baseUrl = "http://localhost/blog/" +const baseUrl = "https://www.aiprose.com/blog/" + +func PostDataZZ(id int64) { + //if len(ids) < 1 { + // return + //} + //dataStr := "" + //for id := range ids{ + // dataStr = dataStr + baseUrl + string(id) + "\n" + //} + dataStr := baseUrl + strconv.FormatInt(id, 10) + url := "http://data.zz.baidu.com/urls?site=www.aiprose.com&token=lO2wHMVqVq8SC9Ag" + res, err := http.Post(url, "text/plain", strings.NewReader(dataStr)) + if err != nil { + println(err) + } + defer res.Body.Close() + content, err := ioutil.ReadAll(res.Body) + println(string(content)) +}