Skip to content

Commit 053fb73

Browse files
authored
Merge pull request #18 from seth-shi/feature/decode-content
add: 增加 base64 替换
2 parents 56223e5 + 20d338c commit 053fb73

File tree

17 files changed

+344
-341
lines changed

17 files changed

+344
-341
lines changed

api/api_v2_replies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func (cli *v2exClient) GetReply(ctx context.Context, id int64, page int) tea.Cmd
2222
return errorWrapper("回复", err)
2323
}
2424

25+
res.Pagination.CurrPage = page
2526
return messages.GetReplyResponse{
26-
Data: res,
27-
CurrPage: page,
27+
Data: res,
2828
}
2929
}
3030
}

api/internal/api_topics/api_v2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ func (api *V2TopicApi) requestV2Topics(
212212
// 如果返回了最大页数, 那么返回给前端, 方便后续缓存获取
213213
api.cursorPageState.Store(nodeKey, apiPage)
214214
// 存储分页信息
215+
v2Res.Pagination.CurrPage = apiPage
215216
api.nodePageInfoState.Store(nodeKey, v2Res.Pagination)
216217

217218
res := &v2Resp{

commands/loading.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"sync/atomic"
6+
7+
tea "github.com/charmbracelet/bubbletea"
8+
"github.com/seth-shi/go-v2ex/v2/messages"
9+
)
10+
11+
var (
12+
lastLoadingId int64
13+
LoadingGetToken = newLoadingKey("token 获取中...")
14+
LoadingMe = newLoadingKey("个人信息获取中...")
15+
LoadingRequestTopics = newLoadingKey("主题请求中...")
16+
LoadingRequestDetail = newLoadingKey("内容获取中...")
17+
LoadingRequestReply = newLoadingKey("评论获取中...")
18+
LoadingDecodeContent = newLoadingKey("内容解码中...")
19+
)
20+
21+
type loadingManager struct {
22+
start messages.StartLoading
23+
end messages.EndLoading
24+
loading atomic.Bool
25+
}
26+
27+
func newLoadingKey(text string) loadingManager {
28+
id := nextLoadingId()
29+
return loadingManager{
30+
start: messages.StartLoading{Text: text, ID: id},
31+
end: messages.EndLoading{
32+
ID: id,
33+
},
34+
loading: atomic.Bool{},
35+
}
36+
}
37+
38+
func (s *loadingManager) Run(cmd tea.Cmd) tea.Cmd {
39+
40+
// 加载中的时候, 发出错误
41+
if s.loading.Load() {
42+
return Post(fmt.Errorf("[%s]加载中", s.start.Text))
43+
}
44+
45+
// 开始加载中
46+
return tea.Sequence(
47+
// 标记开始
48+
func() tea.Msg {
49+
s.loading.Store(true)
50+
return s.start
51+
},
52+
cmd,
53+
// 标记结束
54+
func() tea.Msg {
55+
s.loading.Store(false)
56+
return s.end
57+
},
58+
)
59+
}
60+
61+
func nextLoadingId() int {
62+
return int(atomic.AddInt64(&lastLoadingId, 1))
63+
}

consts/keymap.go

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package consts
22

33
import (
4+
"fmt"
5+
46
"github.com/charmbracelet/bubbles/key"
7+
"github.com/seth-shi/go-v2ex/v2/styles"
58
)
69

710
type KeyMap struct {
@@ -34,7 +37,7 @@ func (k KeyMap) FullHelp() [][]key.Binding {
3437
{
3538
k.Up, k.Down, k.Left, k.Right,
3639
k.Tab, k.ShiftTab,
37-
k.KeyE, k.KeyQ, k.KeyR,
40+
k.KeyQ, k.KeyE, k.KeyR,
3841
}, // first column
3942
{
4043
k.CtrlQuit, k.HelpPage, k.SettingPage,
@@ -44,6 +47,13 @@ func (k KeyMap) FullHelp() [][]key.Binding {
4447
}
4548
}
4649

50+
var (
51+
topicPageTitle = styles.Active.Bold(true).Render("[主题页]")
52+
allPageTitle = styles.Active.Underline(true).Render("[任意页]")
53+
detailPageTitle = styles.Err.Bold(true).Render("[详情页]")
54+
settingPageTitle = styles.Err.Underline(true).Render("[配置页]")
55+
)
56+
4757
// AppKeyMap
4858
// vim key bind style : https://github.com/philc/vimium#keyboard-bindings
4959
// ? show the help dialog for a list of all available keys
@@ -54,66 +64,66 @@ func (k KeyMap) FullHelp() [][]key.Binding {
5464
var AppKeyMap = KeyMap{
5565
Up: key.NewBinding(
5666
key.WithKeys("w", "up", "k"),
57-
key.WithHelp("w/↑", "[主题页]列表上一个"),
67+
key.WithHelp("w/↑", fmt.Sprintf("%s列表上一个", topicPageTitle)),
5868
),
5969
Down: key.NewBinding(
6070
key.WithKeys("s", "down", "j"),
61-
key.WithHelp("s/↓", "[主题页]列表下一个"),
71+
key.WithHelp("s/↓", fmt.Sprintf("%s列表下一个", topicPageTitle)),
6272
),
6373
Left: key.NewBinding(
6474
key.WithKeys("a", "left", "h"),
65-
key.WithHelp("a/←", "[主题页]上一页"),
75+
key.WithHelp("a/←", fmt.Sprintf("%s上一页", topicPageTitle)),
6676
),
6777
Right: key.NewBinding(
6878
key.WithKeys("d", "right", "l"),
69-
key.WithHelp("d/→", "[主题页]下一页"),
79+
key.WithHelp("d/→", fmt.Sprintf("%s下一页", topicPageTitle)),
7080
),
7181
KeyQ: key.NewBinding(
7282
key.WithKeys("q", "H"),
73-
key.WithHelp("q", "返回上一页"),
83+
key.WithHelp("q", fmt.Sprintf("%s返回上一页", allPageTitle)),
7484
),
7585
HelpPage: key.NewBinding(
7686
key.WithKeys("?"),
77-
key.WithHelp("?", "查看帮助页面(再按一次返回首页)"),
87+
key.WithHelp("?", fmt.Sprintf("%s查看帮助页面(再按一次返回首页)", allPageTitle)),
7888
),
7989
SettingPage: key.NewBinding(
8090
key.WithKeys("`"),
81-
key.WithHelp("`", "[反引号]进入配置页面(再按一次返回首页)"),
91+
key.WithHelp("`", fmt.Sprintf("%s反引号:查看帮助页面(再按一次返回首页)", allPageTitle)),
8292
),
8393
Tab: key.NewBinding(
8494
key.WithKeys("tab"),
85-
key.WithHelp("tab", "[主题页]下一个节点"),
86-
),
87-
Space: key.NewBinding(
88-
key.WithKeys(" "),
89-
key.WithHelp("空格", "老板键"),
95+
key.WithHelp("tab", fmt.Sprintf("%s下一个节点", topicPageTitle)),
9096
),
9197
ShiftTab: key.NewBinding(
9298
key.WithKeys("shift+tab"),
93-
key.WithHelp("shift+tab", "[主题页]上一个切点"),
99+
key.WithHelp("shift+tab", fmt.Sprintf("%s上一个切点", topicPageTitle)),
100+
),
101+
Space: key.NewBinding(
102+
key.WithKeys(" "),
103+
key.WithHelp("空格", fmt.Sprintf("%s老板键", allPageTitle)),
94104
),
95105
CtrlQuit: key.NewBinding(
96106
key.WithKeys("esc", "ctrl+c"),
97-
key.WithHelp("esc", "退出程序"),
98-
),
99-
KeyE: key.NewBinding(
100-
key.WithKeys("e", "enter", "o"),
101-
key.WithHelp("e/enter", "[主题页]查看主题详情 / [详情页]加载评论"),
107+
key.WithHelp("esc", fmt.Sprintf("%s退出程序", allPageTitle)),
102108
),
103109
SwitchShowMode: key.NewBinding(
104110
key.WithKeys("="),
105-
key.WithHelp("=", "[等于号]切换底部显示隐藏"),
111+
key.WithHelp("=", fmt.Sprintf("%s等于号:切换底部显示隐藏", allPageTitle)),
112+
),
113+
KeyE: key.NewBinding(
114+
key.WithKeys("e", "enter", "o"),
115+
key.WithHelp("e/enter", fmt.Sprintf("%s查看主题详情 / %s加载评论", topicPageTitle, detailPageTitle)),
106116
),
107117
KeyR: key.NewBinding(
108118
key.WithKeys("r"),
109-
key.WithHelp("r", "[主题页]切换接口版本 / [详情页]加载图片"),
119+
key.WithHelp("r", fmt.Sprintf("%s切换接口版本 / %s解码内容(图片/base64)", topicPageTitle, detailPageTitle)),
110120
),
111121
UpgradeApp: key.NewBinding(
112-
key.WithKeys("ctrl+u"),
113-
key.WithHelp("ctrl+u", "更新应用(需要网络可以访问 github)"),
122+
key.WithKeys("u"),
123+
key.WithHelp("u", fmt.Sprintf("%s更新应用", allPageTitle)),
114124
),
115125
F1: key.NewBinding(
116126
key.WithKeys("f1"),
117-
key.WithHelp("f1", "[详情页]打开链接 / [配置页]打开配置文件"),
127+
key.WithHelp("f1", fmt.Sprintf("%s浏览器打开 / %s打开配置文件", topicPageTitle, settingPageTitle)),
118128
),
119129
}

messages/detail.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ type GetDetailResponse struct {
1313
}
1414

1515
type GetReplyResponse struct {
16-
Data response.V2ReplyResponse
17-
CurrPage int
16+
Data response.V2ReplyResponse
1817
}
1918

20-
type GetImageRequest struct {
21-
URL []string
19+
type DecodeDetailContentResult struct {
20+
Result map[string]string
2221
}
2322

24-
type GetImageResult struct {
25-
Result map[string]string
23+
type RenderDetailContentResult struct {
24+
Content string
2625
}

messages/loading.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,5 @@
11
package messages
22

3-
import (
4-
"sync/atomic"
5-
6-
tea "github.com/charmbracelet/bubbletea"
7-
)
8-
9-
var (
10-
lastLoadingId int64
11-
LoadingGetToken = newLoadingKey("获取 token 信息中")
12-
LoadingMe = newLoadingKey("获取个人信息中")
13-
LoadingRequestTopics = newLoadingKey("获取主题中")
14-
LoadingRequestDetail = newLoadingKey("获取内容中")
15-
LoadingRequestReply = newLoadingKey("获取评论中")
16-
LoadingRequestImage = newLoadingKey("获取图片中")
17-
)
18-
19-
func newLoadingKey(text string) loadingManager {
20-
id := nextLoadingId()
21-
return loadingManager{
22-
start: StartLoading{Text: text, ID: id},
23-
end: EndLoading{
24-
ID: id,
25-
},
26-
loading: atomic.Bool{},
27-
}
28-
}
29-
303
type StartLoading struct {
314
Text string
325
ID int
@@ -35,36 +8,3 @@ type StartLoading struct {
358
type EndLoading struct {
369
ID int
3710
}
38-
39-
func (s *loadingManager) PostStart() tea.Cmd {
40-
41-
if s.loading.Load() {
42-
return nil
43-
}
44-
45-
return func() tea.Msg {
46-
s.loading.Store(true)
47-
return s.start
48-
}
49-
}
50-
51-
func (s *loadingManager) Loading() bool {
52-
return s.loading.Load()
53-
}
54-
55-
func (s *loadingManager) PostEnd() tea.Cmd {
56-
return func() tea.Msg {
57-
s.loading.Store(false)
58-
return s.end
59-
}
60-
}
61-
62-
type loadingManager struct {
63-
start StartLoading
64-
end EndLoading
65-
loading atomic.Bool
66-
}
67-
68-
func nextLoadingId() int {
69-
return int(atomic.AddInt64(&lastLoadingId, 1))
70-
}

pages/boss.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ func (m bossPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6565
switch msg := msg.(type) {
6666
case tea.KeyMsg:
6767
switch {
68-
case key.Matches(msg, consts.AppKeyMap.KeyQ):
69-
return m, commands.RedirectPop()
7068
case key.Matches(msg, consts.AppKeyMap.F1):
7169
return m, func() tea.Msg {
7270
return g.Config.Save(

0 commit comments

Comments
 (0)