Skip to content

Commit ca6bf07

Browse files
committed
🎨 删除接口
1 parent fe9db2d commit ca6bf07

File tree

5 files changed

+31
-101
lines changed

5 files changed

+31
-101
lines changed

plugin/rsshub/domain/job.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// 1. 获取所有频道
1414
// 2. 遍历所有频道,检查频道是否更新
1515
// 3. 如果更新,获取更新的内容,但是返回的数据
16-
func (repo *rssDomain) syncRss(ctx context.Context) (updated map[int64]*RssClientView, err error) {
16+
func (repo *RssDomain) syncRss(ctx context.Context) (updated map[int64]*RssClientView, err error) {
1717
updated = make(map[int64]*RssClientView)
1818
// 获取所有频道
1919
sources, err := repo.storage.GetSources(ctx)
@@ -73,7 +73,7 @@ func (repo *rssDomain) syncRss(ctx context.Context) (updated map[int64]*RssClien
7373
}
7474

7575
// checkSourceNeedUpdate 检查频道是否需要更新
76-
func (repo *rssDomain) checkSourceNeedUpdate(ctx context.Context, source *RssSource) (needUpdate bool, err error) {
76+
func (repo *RssDomain) checkSourceNeedUpdate(ctx context.Context, source *RssSource) (needUpdate bool, err error) {
7777
var sourceInDB *RssSource
7878
sourceInDB, err = repo.storage.GetSourceByRssHubFeedLink(ctx, source.RssHubFeedPath)
7979
if err != nil {
@@ -92,7 +92,7 @@ func (repo *rssDomain) checkSourceNeedUpdate(ctx context.Context, source *RssSou
9292
}
9393

9494
// processContentsUpdate 处理内容(s)更新
95-
func (repo *rssDomain) processContentsUpdate(ctx context.Context, cv *RssClientView, updateChannelView *RssClientView) error {
95+
func (repo *RssDomain) processContentsUpdate(ctx context.Context, cv *RssClientView, updateChannelView *RssClientView) error {
9696
var err error
9797
for _, content := range cv.Contents {
9898
if content == nil {
@@ -115,7 +115,7 @@ func (repo *rssDomain) processContentsUpdate(ctx context.Context, cv *RssClientV
115115
}
116116

117117
// processContentItemUpdate 处理单个内容更新
118-
func (repo *rssDomain) processContentItemUpdate(ctx context.Context, content *RssContent) (existed bool, err error) {
118+
func (repo *RssDomain) processContentItemUpdate(ctx context.Context, content *RssContent) (existed bool, err error) {
119119
existed, err = repo.storage.IsContentHashIDExist(ctx, content.HashID)
120120
if err != nil {
121121
return

plugin/rsshub/domain/rssHub.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,17 @@ import (
1212
)
1313

1414
// RssDomain RssRepo定义
15-
type RssDomain interface {
16-
// Subscribe 订阅Rss频道
17-
Subscribe(ctx context.Context, gid int64, route string) (rv *RssClientView, isChannelExisted,
18-
isSubExisted bool, err error)
19-
// Unsubscribe 取消订阅Rss频道
20-
Unsubscribe(ctx context.Context, gid int64, route string) (err error)
21-
// GetSubscribedChannelsByGroupID 获取群组订阅的Rss频道
22-
GetSubscribedChannelsByGroupID(ctx context.Context, gid int64) (rv []*RssClientView, err error)
23-
// Sync 同步Rss频道
24-
// 返回群组-频道推送视图 map[群组]推送内容数组
25-
Sync(ctx context.Context) (groupView map[int64][]*RssClientView, err error)
26-
}
27-
28-
// rssDomain RssRepo定义
29-
type rssDomain struct {
30-
storage RepoStorage
15+
type RssDomain struct {
16+
storage *repoStorage
3117
rssHubClient *RssHubClient
3218
}
3319

3420
// NewRssDomain 新建RssDomain,调用方保证单例模式
35-
func NewRssDomain(dbPath string) (RssDomain, error) {
21+
func NewRssDomain(dbPath string) (*RssDomain, error) {
3622
return newRssDomain(dbPath)
3723
}
3824

39-
func newRssDomain(dbPath string) (*rssDomain, error) {
25+
func newRssDomain(dbPath string) (*RssDomain, error) {
4026
if _, err := os.Stat(dbPath); err != nil || os.IsNotExist(err) {
4127
// 生成文件
4228
f, err := os.Create(dbPath)
@@ -50,7 +36,7 @@ func newRssDomain(dbPath string) (*rssDomain, error) {
5036
logrus.Errorf("[rsshub NewRssDomain] open db error: %v", err)
5137
panic(err)
5238
}
53-
repo := &rssDomain{
39+
repo := &RssDomain{
5440
storage: &repoStorage{orm: orm},
5541
rssHubClient: &RssHubClient{Client: http.DefaultClient},
5642
}
@@ -63,7 +49,7 @@ func newRssDomain(dbPath string) (*rssDomain, error) {
6349
}
6450

6551
// Subscribe QQ群订阅Rss频道
66-
func (repo *rssDomain) Subscribe(ctx context.Context, gid int64, feedPath string) (
52+
func (repo *RssDomain) Subscribe(ctx context.Context, gid int64, feedPath string) (
6753
rv *RssClientView, isChannelExisted, isSubExisted bool, err error) {
6854
// 验证
6955
feed, err := repo.rssHubClient.FetchFeed(feedPath)
@@ -118,7 +104,7 @@ func (repo *rssDomain) Subscribe(ctx context.Context, gid int64, feedPath string
118104
}
119105

120106
// Unsubscribe 群组取消订阅
121-
func (repo *rssDomain) Unsubscribe(ctx context.Context, gid int64, feedPath string) (err error) {
107+
func (repo *RssDomain) Unsubscribe(ctx context.Context, gid int64, feedPath string) (err error) {
122108
existedSubscribes, ifExisted, err := repo.storage.GetIfExistedSubscribe(ctx, gid, feedPath)
123109
if err != nil {
124110
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] query sub by route error: %v", err)
@@ -153,7 +139,7 @@ func (repo *rssDomain) Unsubscribe(ctx context.Context, gid int64, feedPath stri
153139
}
154140

155141
// GetSubscribedChannelsByGroupID 获取群对应的订阅的频道信息
156-
func (repo *rssDomain) GetSubscribedChannelsByGroupID(ctx context.Context, gid int64) ([]*RssClientView, error) {
142+
func (repo *RssDomain) GetSubscribedChannelsByGroupID(ctx context.Context, gid int64) ([]*RssClientView, error) {
157143
channels, err := repo.storage.GetSubscribedChannelsByGroupID(ctx, gid)
158144
if err != nil {
159145
logrus.WithContext(ctx).Errorf("[rsshub GetSubscribedChannelsByGroupID] GetSubscribedChannelsByGroupID error: %v", err)
@@ -170,7 +156,7 @@ func (repo *rssDomain) GetSubscribedChannelsByGroupID(ctx context.Context, gid i
170156
}
171157

172158
// Sync 同步任务,按照群组订阅情况做好map切片
173-
func (repo *rssDomain) Sync(ctx context.Context) (groupView map[int64][]*RssClientView, err error) {
159+
func (repo *RssDomain) Sync(ctx context.Context) (groupView map[int64][]*RssClientView, err error) {
174160
groupView = make(map[int64][]*RssClientView)
175161
// 获取所有Rss频道
176162
// 获取所有频道

plugin/rsshub/domain/storageImpl.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

plugin/rsshub/domain/storageRepo.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
// RepoStorage 定义RepoStorage接口
14-
type RepoStorage interface {
15-
RepoContent
16-
RepoSource
17-
RepoSubscribe
18-
RepoMultiQuery
19-
initDB() error
20-
}
21-
2213
// repoStorage db struct for rss
2314
type repoStorage struct {
2415
orm *gorm.DB

plugin/rsshub/main.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
// 初始化 repo
2020
var (
21-
rssRepo domain.RssDomain
21+
rssRepo *domain.RssDomain
2222
initErr error
2323
regexpForSQL = regexp.MustCompile(`[\^<>\[\]%&\*\(\)\{\}\|\=]|(union\s+select|update\s+|delete\s+|drop\s+|truncate\s+|insert\s+|exec\s+|declare\s+)`)
2424
)
@@ -28,11 +28,11 @@ var (
2828
engine = control.Register("rsshub", &ctrl.Options[*zero.Ctx]{
2929
// 默认不启动
3030
DisableOnDefault: false,
31-
Brief: "RssHub订阅姬",
31+
Brief: "rsshub订阅姬",
3232
// 详细帮助
33-
Help: "RssHub订阅姬desu~ \n" +
33+
Help: "rsshub订阅姬desu~ \n" +
3434
"支持的详细订阅列表文档可见:\n" +
35-
"https://rsshub.netlify.app/ \n" +
35+
"https://rsshub.netlify.app/zh/ \n" +
3636
"- 添加rsshub订阅-/bookfere/weekly \n" +
3737
"- 删除rsshub订阅-/bookfere/weekly \n" +
3838
"- 查看rsshub订阅列表 \n" +
@@ -43,10 +43,10 @@ var (
4343
// 插件数据存储路径
4444
PrivateDataFolder: "rsshub",
4545
OnEnable: func(ctx *zero.Ctx) {
46-
ctx.SendChain(message.Text("RssHub订阅姬现在启动了哦"))
46+
ctx.SendChain(message.Text("rsshub订阅姬现在启动了哦"))
4747
},
4848
OnDisable: func(ctx *zero.Ctx) {
49-
ctx.SendChain(message.Text("RssHub订阅姬现在关闭了哦"))
49+
ctx.SendChain(message.Text("rsshub订阅姬现在关闭了哦"))
5050
},
5151
}).ApplySingle(zbpCtxExt.DefaultSingle)
5252
)
@@ -55,7 +55,7 @@ var (
5555
func init() {
5656
rssRepo, initErr = domain.NewRssDomain(engine.DataFolder() + "rsshub.db")
5757
if initErr != nil {
58-
logrus.Errorln("RssHub订阅姬:初始化失败", initErr)
58+
logrus.Errorln("rsshub订阅姬:初始化失败", initErr)
5959
panic(initErr)
6060
}
6161
engine.OnFullMatch("rsshub同步", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
@@ -80,18 +80,18 @@ func init() {
8080
logrus.Debugf("添加rsshub订阅:raw(%s), replaced(%s)", routeStr, input)
8181
rv, _, isSubExisted, err := rssRepo.Subscribe(context.Background(), ctx.Event.GroupID, input)
8282
if err != nil {
83-
ctx.SendChain(message.Text("RssHub订阅姬:添加失败", err.Error()))
83+
ctx.SendChain(message.Text("rsshub订阅姬:添加失败", err.Error()))
8484
return
8585
}
8686
if isSubExisted {
87-
ctx.SendChain(message.Text("RssHub订阅姬:已存在,更新成功"))
87+
ctx.SendChain(message.Text("rsshub订阅姬:已存在,更新成功"))
8888
} else {
89-
ctx.SendChain(message.Text("RssHub订阅姬:添加成功\n", rv.Source.Title))
89+
ctx.SendChain(message.Text("rsshub订阅姬:添加成功\n", rv.Source.Title))
9090
}
9191
// 添加成功,发送订阅源快照
9292
msg, err := newRssDetailsMsg(ctx, rv)
9393
if len(msg) == 0 || err != nil {
94-
ctx.SendPrivateMessage(zero.BotConfig.SuperUsers[0], message.Text("RssHub推送错误", err))
94+
ctx.SendPrivateMessage(zero.BotConfig.SuperUsers[0], message.Text("rsshub推送错误", err))
9595
return
9696
}
9797
if id := ctx.Send(msg).ID(); id == 0 {
@@ -104,21 +104,21 @@ func init() {
104104
logrus.Debugf("删除rsshub订阅:raw(%s), replaced(%s)", routeStr, input)
105105
err := rssRepo.Unsubscribe(context.Background(), ctx.Event.GroupID, input)
106106
if err != nil {
107-
ctx.SendChain(message.Text("RssHub订阅姬:删除失败 ", err.Error()))
107+
ctx.SendChain(message.Text("rsshub订阅姬:删除失败 ", err.Error()))
108108
return
109109
}
110-
ctx.SendChain(message.Text(fmt.Sprintf("RssHub订阅姬:删除%s成功", input)))
110+
ctx.SendChain(message.Text(fmt.Sprintf("rsshub订阅姬:删除%s成功", input)))
111111
})
112112
engine.OnFullMatch("查看rsshub订阅列表", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
113113
rv, err := rssRepo.GetSubscribedChannelsByGroupID(context.Background(), ctx.Event.GroupID)
114114
if err != nil {
115-
ctx.SendChain(message.Text("RssHub订阅姬:查询失败 ", err.Error()))
115+
ctx.SendChain(message.Text("rsshub订阅姬:查询失败 ", err.Error()))
116116
return
117117
}
118118
// 添加成功,发送订阅源信息
119119
msg, err := newRssSourcesMsg(ctx, rv)
120120
if err != nil {
121-
ctx.SendChain(message.Text("RssHub订阅姬:查询失败 ", err.Error()))
121+
ctx.SendChain(message.Text("rsshub订阅姬:查询失败 ", err.Error()))
122122
return
123123
}
124124
if len(msg) == 0 {
@@ -132,7 +132,7 @@ func init() {
132132
// sendRssUpdateMsg 发送Rss更新消息
133133
func sendRssUpdateMsg(ctx *zero.Ctx, groupToFeedsMap map[int64][]*domain.RssClientView) {
134134
for groupID, views := range groupToFeedsMap {
135-
logrus.Infof("RssHub插件在群 %d 触发推送检查", groupID)
135+
logrus.Infof("rsshub插件在群 %d 触发推送检查", groupID)
136136
for _, view := range views {
137137
if view == nil || len(view.Contents) == 0 {
138138
continue
@@ -142,8 +142,8 @@ func sendRssUpdateMsg(ctx *zero.Ctx, groupToFeedsMap map[int64][]*domain.RssClie
142142
ctx.SendPrivateMessage(zero.BotConfig.SuperUsers[0], message.Text(rssHubPushErrMsg, err))
143143
continue
144144
}
145-
logrus.Infof("RssHub插件在群 %d 开始推送 %s", groupID, view.Source.Title)
146-
ctx.SendGroupMessage(groupID, message.Text(fmt.Sprintf("%s\n该RssHub频道下有更新了哦~", view.Source.Title)))
145+
logrus.Infof("rsshub插件在群 %d 开始推送 %s", groupID, view.Source.Title)
146+
ctx.SendGroupMessage(groupID, message.Text(fmt.Sprintf("%s\n该rsshub频道下有更新了哦~", view.Source.Title)))
147147
if res := ctx.SendGroupForwardMessage(groupID, msg); !res.Exists() {
148148
ctx.SendPrivateMessage(zero.BotConfig.SuperUsers[0], message.Text(rssHubPushErrMsg))
149149
}

0 commit comments

Comments
 (0)