Skip to content

Commit a1648de

Browse files
authored
Merge pull request #11 from seth-shi/feature/optimal
add: v1 v2 接口支持
2 parents a3820f1 + 4227772 commit a1648de

37 files changed

+745
-819
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* 运行 `go-v2ex` 命令即可启动程序。
1919

2020
## 功能特性
21-
- **自动更新**:按`u`键可从`Github`自动更新最新版本
21+
- **自动更新**:按`ctrl+u`键可从`Github`自动更新最新版本
2222
- **支持预览图片**:支持查看图片
2323
- **多节点切换**:支持自定义节点列表
2424
- **主题浏览**:查看最新/热门主题,支持分页翻页
@@ -30,7 +30,6 @@
3030
![列表页](assets/1.gif)
3131
![列表页](assets/2.png)
3232
![详情页](assets/3.png)
33-
![自动更新](assets/upgrade.gif)
3433

3534

3635

@@ -58,7 +57,7 @@
5857
```
5958

6059
## TODO
61-
- [ ] 统一获取配置
60+
- [x] 统一获取配置
6261
- [x] 终端显示图片
6362
- [x] 自动更新应用
6463

api/api_self.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (cli *v2exClient) Me(ctx context.Context) tea.Cmd {
1717
SetResult(&res).
1818
Get("/api/v2/member")
1919
if err != nil {
20-
return err
20+
return errorWrapper("个人信息", err)
2121
}
2222

2323
g.Me.Set(res.Result)

api/api_topics.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
tea "github.com/charmbracelet/bubbletea"
77
"github.com/seth-shi/go-v2ex/g"
88
"github.com/seth-shi/go-v2ex/messages"
9+
"github.com/seth-shi/go-v2ex/response"
910
)
1011

1112
func (cli *v2exClient) GetTopics(
@@ -18,13 +19,35 @@ func (cli *v2exClient) GetTopics(
1819
var (
1920
nodeIndex = g.Config.Get().ActiveTab
2021
node = g.GetGroupNode(nodeIndex)
22+
res []response.TopicResult
23+
total int
24+
err error
2125
)
2226

23-
res, err := cli.topicApi.GetTopicsByGroupNode(ctx, node, page)
27+
// 如果是 myNodes, 那么就去用 V2 的接口
28+
v2 := node.Key == g.NodesMy || g.Session.ChooseApiV2.Load()
29+
// 最新最热, 只能用 v1
30+
if node.Key == g.HotNode || node.Key == g.LatestNode {
31+
v2 = false
32+
}
33+
34+
g.Session.IsApiV2.Store(v2)
35+
if v2 {
36+
res, total, err = cli.v2TopicApi.GetTopicsByGroupNode(ctx, node, page)
37+
} else {
38+
res, total, err = cli.v1TopicApi.GetTopicsByGroupNode(ctx, node, page)
39+
}
40+
2441
if err != nil {
2542
return errorWrapper("主题", err)
2643
}
2744

28-
return messages.GetTopicResponse{Data: res}
45+
return messages.GetTopicResponse{
46+
Data: res,
47+
PageInfo: &response.PerTenPageInfo{
48+
TotalCount: total,
49+
CurrPage: page,
50+
},
51+
}
2952
}
3053
}

api/api_v2_token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (cli *v2exClient) GetToken(ctx context.Context) tea.Cmd {
1818
Get("/api/v2/token")
1919

2020
if err != nil {
21-
return err
21+
return errorWrapper("令牌", err)
2222
}
2323

2424
// 准备过期的话, 发送提醒

api/internal/api_topics/api.go

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

0 commit comments

Comments
 (0)