mirror of
https://github.com/eiblog/eiblog.git
synced 2026-03-01 00:34:58 +08:00
ping rpc
This commit is contained in:
2
api.go
2
api.go
@@ -211,6 +211,7 @@ func apiPostAdd(c *gin.Context) {
|
|||||||
cid = int(artc.ID)
|
cid = int(artc.ID)
|
||||||
if publish {
|
if publish {
|
||||||
ElasticIndex(artc)
|
ElasticIndex(artc)
|
||||||
|
DoPings(slug)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -248,6 +249,7 @@ func apiPostAdd(c *gin.Context) {
|
|||||||
GenerateExcerptAndRender(artc)
|
GenerateExcerptAndRender(artc)
|
||||||
// elasticsearch 索引
|
// elasticsearch 索引
|
||||||
ElasticIndex(artc)
|
ElasticIndex(artc)
|
||||||
|
DoPings(slug)
|
||||||
if artc.ID >= setting.Conf.StartID {
|
if artc.ID >= setting.Conf.StartID {
|
||||||
ManageTagsArticle(artc, true, ADD)
|
ManageTagsArticle(artc, true, ADD)
|
||||||
ManageSeriesArticle(artc, true, ADD)
|
ManageSeriesArticle(artc, true, ADD)
|
||||||
|
|||||||
10
conf/app.yml
10
conf/app.yml
@@ -16,8 +16,6 @@ identifier: <!--more-->
|
|||||||
startid: 11
|
startid: 11
|
||||||
# elasticsearch url
|
# elasticsearch url
|
||||||
searchurl: http://elasticsearch:9200
|
searchurl: http://elasticsearch:9200
|
||||||
# superfeedr shortname
|
|
||||||
superfeedr: deepzz
|
|
||||||
# 评论相关
|
# 评论相关
|
||||||
disqus:
|
disqus:
|
||||||
shortname: deepzz
|
shortname: deepzz
|
||||||
@@ -53,6 +51,14 @@ mode:
|
|||||||
domain: deepzz.com
|
domain: deepzz.com
|
||||||
# twitter地址: twitter.com/chenqijing2
|
# twitter地址: twitter.com/chenqijing2
|
||||||
twitter: twitter.com/chenqijing2
|
twitter: twitter.com/chenqijing2
|
||||||
|
# superfeedr url
|
||||||
|
feedrurl: https://deepzz.superfeedr.com/
|
||||||
|
# ping rpcs 地址
|
||||||
|
pingrpcs:
|
||||||
|
- http://ping.baidu.com/ping/RPC2
|
||||||
|
- http://blogsearch.google.com/ping/RPC2
|
||||||
|
- http://rpc.pingomatic.com/
|
||||||
|
|
||||||
# 以下数据初始化用,可在后台修改
|
# 以下数据初始化用,可在后台修改
|
||||||
account:
|
account:
|
||||||
# *后台登录用户名
|
# *后台登录用户名
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ server {
|
|||||||
proxy_hide_header Vary;
|
proxy_hide_header Vary;
|
||||||
proxy_hide_header X-Powered-By;
|
proxy_hide_header X-Powered-By;
|
||||||
|
|
||||||
# proxy_set_header X-Via QingDao.Aliyun;
|
proxy_set_header X-Via QingDao.Aliyun;
|
||||||
proxy_set_header Connection "";
|
proxy_set_header Connection "";
|
||||||
proxy_set_header Host deepzz.com;
|
proxy_set_header Host deepzz.com;
|
||||||
proxy_set_header X-Real_IP $remote_addr;
|
proxy_set_header X-Real_IP $remote_addr;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<link>https://{{.Domain}}</link>
|
<link>https://{{.Domain}}</link>
|
||||||
<description>{{.SubTitle}}</description>
|
<description>{{.SubTitle}}</description>
|
||||||
<atom:link href="https://{{.Domain}}/rss.html" rel="self"/>
|
<atom:link href="https://{{.Domain}}/rss.html" rel="self"/>
|
||||||
<atom:link href="https://{{.Superfeedr}}.superfeedr.com/" rel="hub"/>
|
<atom:link href="{{.FeedrURL}}" rel="hub"/>
|
||||||
<language>zh-CN</language>
|
<language>zh-CN</language>
|
||||||
<lastBuildDate>{{.BuildDate}}</lastBuildDate>
|
<lastBuildDate>{{.BuildDate}}</lastBuildDate>
|
||||||
{{range .Artcs}}
|
{{range .Artcs}}
|
||||||
|
|||||||
9
glide.lock
generated
9
glide.lock
generated
@@ -1,12 +1,12 @@
|
|||||||
hash: 4b70e76a2e830e97033c06d0e5a90c3199985ff5070bdf8364b1feca63d5caa5
|
hash: 4b70e76a2e830e97033c06d0e5a90c3199985ff5070bdf8364b1feca63d5caa5
|
||||||
updated: 2016-11-12T02:35:12.289411301+08:00
|
updated: 2016-11-14T22:09:13.900837801+08:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/boj/redistore
|
- name: github.com/boj/redistore
|
||||||
version: fc113767cd6b051980f260d6dbe84b2740c46ab0
|
version: fc113767cd6b051980f260d6dbe84b2740c46ab0
|
||||||
- name: github.com/eiblog/blackfriday
|
- name: github.com/eiblog/blackfriday
|
||||||
version: c0ec111761ae784fe31cc076f2fa0e2d2216d623
|
version: c0ec111761ae784fe31cc076f2fa0e2d2216d623
|
||||||
- name: github.com/eiblog/utils
|
- name: github.com/eiblog/utils
|
||||||
version: 9ae244bfa2feec3e339a26190a56093fde200288
|
version: 3352fddbea01fcfeeb8d903b72f3b84da9780525
|
||||||
subpackages:
|
subpackages:
|
||||||
- logd
|
- logd
|
||||||
- mgo
|
- mgo
|
||||||
@@ -61,8 +61,11 @@ imports:
|
|||||||
- api
|
- api
|
||||||
- auth/qbox
|
- auth/qbox
|
||||||
- conf
|
- conf
|
||||||
- kodo
|
|
||||||
- kodocli
|
- kodocli
|
||||||
|
- name: qiniupkg.com/api.v7/conf
|
||||||
|
version: ad7023b87b2f5c169812da49fe44900be1c4e5c2
|
||||||
|
- name: qiniupkg.com/api.v7/kodo
|
||||||
|
version: ad7023b87b2f5c169812da49fe44900be1c4e5c2
|
||||||
- name: qiniupkg.com/x
|
- name: qiniupkg.com/x
|
||||||
version: f512abcf45ab4e2ba0fd4784c57b53d495997d66
|
version: f512abcf45ab4e2ba0fd4784c57b53d495997d66
|
||||||
subpackages:
|
subpackages:
|
||||||
|
|||||||
84
ping.go
84
ping.go
@@ -1,30 +1,29 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/xml"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/eiblog/eiblog/setting"
|
||||||
"github.com/eiblog/utils/logd"
|
"github.com/eiblog/utils/logd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Feeder interface {
|
type Pinger interface {
|
||||||
PingFunc(url string)
|
PingFunc(url string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// superfeedr
|
// superfeedr
|
||||||
// http://<your-hub-name>.superfeedr.com/
|
// http://<your-hub-name>.superfeedr.com/
|
||||||
type Superfeedr struct {
|
type superfeedr struct{}
|
||||||
URL string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Superfeedr) PingFunc(urls ...string) {
|
func (_ *superfeedr) PingFunc(slug string) {
|
||||||
vals := url.Values{}
|
vals := url.Values{}
|
||||||
vals.Set("hub.mode", "publish")
|
vals.Set("hub.mode", "publish")
|
||||||
for _, u := range urls {
|
vals.Add("hub.url", "https://"+setting.Conf.Mode.Domain+"/post/"+slug+".html")
|
||||||
vals.Add("hub.url", u)
|
res, err := http.PostForm(setting.Conf.FeedrURL, vals)
|
||||||
}
|
|
||||||
res, err := http.PostForm(f.URL, vals)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logd.Error(err)
|
logd.Error(err)
|
||||||
return
|
return
|
||||||
@@ -39,3 +38,70 @@ func (f *Superfeedr) PingFunc(urls ...string) {
|
|||||||
logd.Error(string(data))
|
logd.Error(string(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// google baidu
|
||||||
|
// params
|
||||||
|
// BlogName string `xml:"param>value>string"`
|
||||||
|
// HomePage string `xml:"param>value>string"`
|
||||||
|
// Article string `xml:"param>value>string"`
|
||||||
|
// RSS_URL string `xml:"param>value>string"`
|
||||||
|
type pingRPC struct {
|
||||||
|
XMLName xml.Name `xml:"methodCall"`
|
||||||
|
MethodName string `xml:"methodName"`
|
||||||
|
Params struct {
|
||||||
|
Param [4]rpcValue `xml:"param"`
|
||||||
|
} `xml:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type rpcValue struct {
|
||||||
|
Value string `xml:"value>string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pingRPC) PingFunc(slug string) {
|
||||||
|
p.Params.Param[1].Value = "https://" + setting.Conf.Mode.Domain + "/post/" + slug + ".html"
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
buf.WriteString(xml.Header)
|
||||||
|
enc := xml.NewEncoder(buf)
|
||||||
|
if err := enc.Encode(p); err != nil {
|
||||||
|
logd.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, url := range setting.Conf.PingRPCs {
|
||||||
|
rep, err := http.Post(url, "text/xml", buf)
|
||||||
|
if err != nil {
|
||||||
|
logd.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer rep.Body.Close()
|
||||||
|
data, err := ioutil.ReadAll(rep.Body)
|
||||||
|
if err != nil {
|
||||||
|
logd.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
logd.Print(string(data))
|
||||||
|
if rep.StatusCode != 200 {
|
||||||
|
logd.Error(string(data))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var Pings []Pinger
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Pings = append(Pings, &superfeedr{})
|
||||||
|
pr := &pingRPC{MethodName: "weblogUpdates.extendedPing"}
|
||||||
|
pr.Params.Param = [4]rpcValue{
|
||||||
|
0: rpcValue{Value: Ei.BTitle},
|
||||||
|
1: rpcValue{Value: "https://" + setting.Conf.Mode.Domain},
|
||||||
|
2: rpcValue{},
|
||||||
|
3: rpcValue{Value: "https://" + setting.Conf.Mode.Domain + "/rss.html"},
|
||||||
|
}
|
||||||
|
Pings = append(Pings, pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DoPings(slug string) {
|
||||||
|
for _, p := range Pings {
|
||||||
|
go p.PingFunc(slug)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
18
ping_test.go
18
ping_test.go
@@ -2,13 +2,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/eiblog/eiblog/setting"
|
"github.com/eiblog/eiblog/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPing(t *testing.T) {
|
func TestSuperFeedr(t *testing.T) {
|
||||||
sf := Superfeedr{URL: fmt.Sprintf("https://%s.superfeedr.com", setting.Conf.Superfeedr)}
|
sf := superfeedr{}
|
||||||
sf.PingFunc("https://deepzz.com/rss.html")
|
sf.PingFunc("https://deepzz.com/rss.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPingRPC(t *testing.T) {
|
||||||
|
pr := pingRPC{
|
||||||
|
MethodName: "weblogUpdates.extendedPing",
|
||||||
|
}
|
||||||
|
pr.Params.Param = [4]rpcValue{
|
||||||
|
rpcValue{Value: Ei.BTitle},
|
||||||
|
rpcValue{Value: "https://" + setting.Conf.Mode.Domain},
|
||||||
|
rpcValue{Value: "https://deepzz.com/post/gdb-debug.html"},
|
||||||
|
rpcValue{Value: "https://deepzz.com/rss.html"},
|
||||||
|
}
|
||||||
|
pr.PingFunc("https://deepzz.com/post/gdb-debug.html")
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package setting
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
"github.com/eiblog/utils/logd"
|
"github.com/eiblog/utils/logd"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
@@ -16,7 +14,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wd, _ = os.Getwd()
|
|
||||||
Conf = new(Config)
|
Conf = new(Config)
|
||||||
BlackIP = make(map[string]bool)
|
BlackIP = make(map[string]bool)
|
||||||
)
|
)
|
||||||
@@ -32,9 +29,7 @@ type Config struct {
|
|||||||
Identifier string // 截取标示
|
Identifier string // 截取标示
|
||||||
Favicon string // icon地址
|
Favicon string // icon地址
|
||||||
StartID int32 // 文章起始id
|
StartID int32 // 文章起始id
|
||||||
Static string // cdn地址
|
|
||||||
SearchURL string // elasticsearch 地址
|
SearchURL string // elasticsearch 地址
|
||||||
Superfeedr string // superfeedr
|
|
||||||
Disqus struct { // 获取文章数量相关
|
Disqus struct { // 获取文章数量相关
|
||||||
ShortName string
|
ShortName string
|
||||||
PublicKey string
|
PublicKey string
|
||||||
@@ -56,13 +51,8 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
Mode RunMode // 运行模式
|
Mode RunMode // 运行模式
|
||||||
Twitter string // twitter地址
|
Twitter string // twitter地址
|
||||||
Blogger struct { // 初始化数据
|
FeedrURL string // superfeedr url
|
||||||
BlogName string
|
PingRPCs []string // ping rpc 地址
|
||||||
SubTitle string
|
|
||||||
BeiAn string
|
|
||||||
BTitle string
|
|
||||||
Copyright string
|
|
||||||
}
|
|
||||||
Account struct {
|
Account struct {
|
||||||
Username string // *
|
Username string // *
|
||||||
Password string // *
|
Password string // *
|
||||||
@@ -70,6 +60,13 @@ type Config struct {
|
|||||||
PhoneNumber string
|
PhoneNumber string
|
||||||
Address string
|
Address string
|
||||||
}
|
}
|
||||||
|
Blogger struct { // 初始化数据
|
||||||
|
BlogName string
|
||||||
|
SubTitle string
|
||||||
|
BeiAn string
|
||||||
|
BTitle string
|
||||||
|
Copyright string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RunMode struct {
|
type RunMode struct {
|
||||||
@@ -84,13 +81,12 @@ type RunMode struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// 初始化配置
|
// 初始化配置
|
||||||
dir := wd + "/conf"
|
data, err := ioutil.ReadFile("conf/app.yml")
|
||||||
data, err := ioutil.ReadFile(path.Join(dir, "app.yml"))
|
|
||||||
checkError(err)
|
checkError(err)
|
||||||
err = yaml.Unmarshal(data, Conf)
|
err = yaml.Unmarshal(data, Conf)
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
||||||
data, err = ioutil.ReadFile(path.Join(dir, "blackip.yml"))
|
data, err = ioutil.ReadFile("conf/blackip.yml")
|
||||||
checkError(err)
|
checkError(err)
|
||||||
err = yaml.Unmarshal(data, BlackIP)
|
err = yaml.Unmarshal(data, BlackIP)
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|||||||
2
xml.go
2
xml.go
@@ -42,7 +42,7 @@ func doFeed() {
|
|||||||
"Title": Ei.BTitle,
|
"Title": Ei.BTitle,
|
||||||
"SubTitle": Ei.SubTitle,
|
"SubTitle": Ei.SubTitle,
|
||||||
"Domain": setting.Conf.Mode.Domain,
|
"Domain": setting.Conf.Mode.Domain,
|
||||||
"Superfeedr": setting.Conf.Superfeedr,
|
"FeedrURL": setting.Conf.FeedrURL,
|
||||||
"BuildDate": buildDate.Format(time.RFC1123Z),
|
"BuildDate": buildDate.Format(time.RFC1123Z),
|
||||||
"Artcs": artcs,
|
"Artcs": artcs,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user