Compare commits
1 Commits
feature/ke
...
fix/http
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef4e7854d7 |
@@ -338,8 +338,8 @@ func (a *App) settingSelected(i *menu.Item) {
|
|||||||
|
|
||||||
settings := []settingItem{
|
settings := []settingItem{
|
||||||
{
|
{
|
||||||
name: "设置 HTTP 服务端口",
|
name: "设置 HTTP 服务地址",
|
||||||
description: "配置 HTTP 服务监听的端口",
|
description: "配置 HTTP 服务监听的地址",
|
||||||
action: a.settingHTTPPort,
|
action: a.settingHTTPPort,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -373,17 +373,17 @@ func (a *App) settingHTTPPort() {
|
|||||||
// 实现端口设置逻辑
|
// 实现端口设置逻辑
|
||||||
// 这里可以使用 tview.InputField 让用户输入端口
|
// 这里可以使用 tview.InputField 让用户输入端口
|
||||||
form := tview.NewForm().
|
form := tview.NewForm().
|
||||||
AddInputField("端口", a.ctx.HTTPAddr, 20, nil, func(text string) {
|
AddInputField("地址", a.ctx.HTTPAddr, 20, nil, func(text string) {
|
||||||
a.ctx.SetHTTPAddr(text)
|
a.m.SetHTTPAddr(text)
|
||||||
}).
|
}).
|
||||||
AddButton("保存", func() {
|
AddButton("保存", func() {
|
||||||
a.mainPages.RemovePage("submenu2")
|
a.mainPages.RemovePage("submenu2")
|
||||||
a.showInfo("HTTP 端口已设置为 " + a.ctx.HTTPAddr)
|
a.showInfo("HTTP 地址已设置为 " + a.ctx.HTTPAddr)
|
||||||
}).
|
}).
|
||||||
AddButton("取消", func() {
|
AddButton("取消", func() {
|
||||||
a.mainPages.RemovePage("submenu2")
|
a.mainPages.RemovePage("submenu2")
|
||||||
})
|
})
|
||||||
form.SetBorder(true).SetTitle("设置 HTTP 端口")
|
form.SetBorder(true).SetTitle("设置 HTTP 地址")
|
||||||
|
|
||||||
a.mainPages.AddPage("submenu2", form, true, true)
|
a.mainPages.AddPage("submenu2", form, true, true)
|
||||||
a.SetFocus(form)
|
a.SetFocus(form)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/sjzar/chatlog/internal/chatlog/conf"
|
"github.com/sjzar/chatlog/internal/chatlog/conf"
|
||||||
"github.com/sjzar/chatlog/internal/chatlog/ctx"
|
"github.com/sjzar/chatlog/internal/chatlog/ctx"
|
||||||
@@ -128,6 +129,21 @@ func (m *Manager) StopService() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) SetHTTPAddr(text string) error {
|
||||||
|
var addr string
|
||||||
|
if util.IsNumeric(text) {
|
||||||
|
addr = fmt.Sprintf("0.0.0.0:%s", text)
|
||||||
|
} else if strings.HasPrefix(text, "http://") {
|
||||||
|
addr = strings.TrimPrefix(text, "http://")
|
||||||
|
} else if strings.HasPrefix(text, "https://") {
|
||||||
|
addr = strings.TrimPrefix(text, "https://")
|
||||||
|
} else {
|
||||||
|
addr = text
|
||||||
|
}
|
||||||
|
m.ctx.SetHTTPAddr(addr)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) GetDataKey() error {
|
func (m *Manager) GetDataKey() error {
|
||||||
if m.ctx.Current == nil {
|
if m.ctx.Current == nil {
|
||||||
return fmt.Errorf("未选择任何账号")
|
return fmt.Errorf("未选择任何账号")
|
||||||
|
|||||||
@@ -260,13 +260,13 @@ func (ds *DataSource) GetContacts(ctx context.Context, key string, limit, offset
|
|||||||
|
|
||||||
if key != "" {
|
if key != "" {
|
||||||
// 按照关键字查询
|
// 按照关键字查询
|
||||||
query = `SELECT m_nsUsrName, nickname, IFNULL(m_nsRemark,""), m_uiSex, IFNULL(m_nsAliasName,"")
|
query = `SELECT IFNULL(m_nsUsrName,""), nickname, IFNULL(m_nsRemark,""), m_uiSex, IFNULL(m_nsAliasName,"")
|
||||||
FROM WCContact
|
FROM WCContact
|
||||||
WHERE m_nsUsrName = ? OR nickname = ? OR m_nsRemark = ? OR m_nsAliasName = ?`
|
WHERE m_nsUsrName = ? OR nickname = ? OR m_nsRemark = ? OR m_nsAliasName = ?`
|
||||||
args = []interface{}{key, key, key, key}
|
args = []interface{}{key, key, key, key}
|
||||||
} else {
|
} else {
|
||||||
// 查询所有联系人
|
// 查询所有联系人
|
||||||
query = `SELECT m_nsUsrName, nickname, IFNULL(m_nsRemark,""), m_uiSex, IFNULL(m_nsAliasName,"")
|
query = `SELECT IFNULL(m_nsUsrName,""), nickname, IFNULL(m_nsRemark,""), m_uiSex, IFNULL(m_nsAliasName,"")
|
||||||
FROM WCContact`
|
FROM WCContact`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,13 +314,13 @@ func (ds *DataSource) GetChatRooms(ctx context.Context, key string, limit, offse
|
|||||||
|
|
||||||
if key != "" {
|
if key != "" {
|
||||||
// 按照关键字查询
|
// 按照关键字查询
|
||||||
query = `SELECT m_nsUsrName, nickname, IFNULL(m_nsRemark,""), IFNULL(m_nsChatRoomMemList,""), IFNULL(m_nsChatRoomAdminList,"")
|
query = `SELECT IFNULL(m_nsUsrName,""), nickname, IFNULL(m_nsRemark,""), IFNULL(m_nsChatRoomMemList,""), IFNULL(m_nsChatRoomAdminList,"")
|
||||||
FROM GroupContact
|
FROM GroupContact
|
||||||
WHERE m_nsUsrName = ? OR nickname = ? OR m_nsRemark = ?`
|
WHERE m_nsUsrName = ? OR nickname = ? OR m_nsRemark = ?`
|
||||||
args = []interface{}{key, key, key}
|
args = []interface{}{key, key, key}
|
||||||
} else {
|
} else {
|
||||||
// 查询所有群聊
|
// 查询所有群聊
|
||||||
query = `SELECT m_nsUsrName, nickname, IFNULL(m_nsRemark,""), IFNULL(m_nsChatRoomMemList,""), IFNULL(m_nsChatRoomAdminList,"")
|
query = `SELECT IFNULL(m_nsUsrName,""), nickname, IFNULL(m_nsRemark,""), IFNULL(m_nsChatRoomMemList,""), IFNULL(m_nsChatRoomAdminList,"")
|
||||||
FROM GroupContact`
|
FROM GroupContact`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +364,7 @@ func (ds *DataSource) GetChatRooms(ctx context.Context, key string, limit, offse
|
|||||||
if err == nil && len(contacts) > 0 && strings.HasSuffix(contacts[0].UserName, "@chatroom") {
|
if err == nil && len(contacts) > 0 && strings.HasSuffix(contacts[0].UserName, "@chatroom") {
|
||||||
// 再次尝试通过用户名查找群聊
|
// 再次尝试通过用户名查找群聊
|
||||||
rows, err := ds.chatRoomDb.QueryContext(ctx,
|
rows, err := ds.chatRoomDb.QueryContext(ctx,
|
||||||
`SELECT m_nsUsrName, nickname, m_nsRemark, m_nsChatRoomMemList, m_nsChatRoomAdminList
|
`SELECT IFNULL(m_nsUsrName,""), nickname, IFNULL(m_nsRemark,""), IFNULL(m_nsChatRoomMemList,""), IFNULL(m_nsChatRoomAdminList,"")
|
||||||
FROM GroupContact
|
FROM GroupContact
|
||||||
WHERE m_nsUsrName = ?`,
|
WHERE m_nsUsrName = ?`,
|
||||||
contacts[0].UserName)
|
contacts[0].UserName)
|
||||||
|
|||||||
@@ -32,3 +32,12 @@ func MustAnyToInt(v interface{}) int {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsNumeric(s string) bool {
|
||||||
|
for _, r := range s {
|
||||||
|
if !unicode.IsDigit(r) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(s) > 0
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user