2 Commits

Author SHA1 Message Date
Shen Junzheng
ef4e7854d7 Fix HTTP Addr & macOS v3 m_nsUsrName is NULL 2025-03-25 18:10:01 +08:00
Shen Junzheng
3f673cbd7e x 2025-03-25 11:38:47 +08:00
9 changed files with 137 additions and 26 deletions

View File

@@ -12,11 +12,14 @@ jobs:
release:
name: Release Binary
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross:v1.24
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git config --global --add safe.directory "$(pwd)"
- name: Setup Go
uses: actions/setup-go@v4
@@ -36,16 +39,8 @@ jobs:
with:
install-only: true
- name: Build Package
run: |
./script/package.sh
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
- name: Run GoReleaser
run: goreleaser release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: packages/*
draft: true
prerelease: true
ENABLE_UPX: true

3
.gitignore vendored
View File

@@ -28,4 +28,5 @@ go.work.sum
.stfolder
chatlog
chatlog.exe
chatlog.exe# Added by goreleaser init:
dist/

90
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,90 @@
# GoReleaser v2 配置
version: 2
before:
hooks:
- go mod tidy
builds:
- id: darwin-amd64
binary: chatlog
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
goos:
- darwin
goarch:
- amd64
ldflags:
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
- id: darwin-arm64
binary: chatlog
env:
- CGO_ENABLED=1
- CC=oa64-clang
- CXX=oa64-clang++
goos:
- darwin
goarch:
- arm64
ldflags:
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
- id: windows-amd64
binary: chatlog
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
goos:
- windows
goarch:
- amd64
ldflags:
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
- id: windows-arm64
binary: chatlog
env:
- CGO_ENABLED=1
- CC=/llvm-mingw/bin/aarch64-w64-mingw32-gcc
- CXX=/llvm-mingw/bin/aarch64-w64-mingw32-g++
goos:
- windows
goarch:
- arm64
ldflags:
- -s -w -X github.com/sjzar/chatlog/pkg/version.Version={{.Version}}
archives:
- id: default
format: tar.gz
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- .Os }}_
{{- .Arch }}
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md
upx:
- enabled: "{{ .Env.ENABLE_UPX }}"
goos: [darwin, windows]
goarch: [amd64]
compress: best
checksum:
name_template: 'checksums.txt'
algorithm: sha256
# 配置 GitHub Release
release:
draft: true
prerelease: auto
mode: replace

View File

@@ -38,7 +38,7 @@ test:
build:
@echo "🔨 Building for current platform..."
$(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME) main.go
CGO_ENABLED=1 $(GO) build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME) main.go
crossbuild: clean
@echo "🌍 Building for multiple platforms..."
@@ -50,7 +50,7 @@ crossbuild: clean
[ "$$float" != "" ] && output_name=$$output_name_$$float; \
echo "🔨 Building for $$os/$$arch..."; \
echo "🔨 Building for $$output_name..."; \
GOOS=$$os GOARCH=$$arch GOARM=$$float $(GO) build -trimpath $(LDFLAGS) -o $$output_name main.go ; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=1 GOARM=$$float $(GO) build -trimpath $(LDFLAGS) -o $$output_name main.go ; \
if [ "$(ENABLE_UPX)" = "1" ] && echo "$(UPX_PLATFORMS)" | grep -q "$$os/$$arch"; then \
echo "⚙️ Compressing binary $$output_name..." && upx --best $$output_name; \
fi; \

View File

@@ -54,7 +54,7 @@ go install github.com/sjzar/chatlog@latest
3. 下载 `chatlog` 预编译版本或从源码安装,推荐使用 go 进行安装。
4. 运行 `chatlog`,按照提示进行操作,解密数据开启 HTTP 服务后,即可通过浏览器或 AI 助手访问聊天记录。
4. 运行 `chatlog`,按照提示进行操作,解密数据开启 HTTP 服务后,即可通过浏览器或 AI 助手访问聊天记录。
### macOS 版本提示

View File

@@ -338,8 +338,8 @@ func (a *App) settingSelected(i *menu.Item) {
settings := []settingItem{
{
name: "设置 HTTP 服务端口",
description: "配置 HTTP 服务监听的端口",
name: "设置 HTTP 服务地址",
description: "配置 HTTP 服务监听的地址",
action: a.settingHTTPPort,
},
{
@@ -373,17 +373,17 @@ func (a *App) settingHTTPPort() {
// 实现端口设置逻辑
// 这里可以使用 tview.InputField 让用户输入端口
form := tview.NewForm().
AddInputField("端口", a.ctx.HTTPAddr, 20, nil, func(text string) {
a.ctx.SetHTTPAddr(text)
AddInputField("地址", a.ctx.HTTPAddr, 20, nil, func(text string) {
a.m.SetHTTPAddr(text)
}).
AddButton("保存", func() {
a.mainPages.RemovePage("submenu2")
a.showInfo("HTTP 端口已设置为 " + a.ctx.HTTPAddr)
a.showInfo("HTTP 地址已设置为 " + a.ctx.HTTPAddr)
}).
AddButton("取消", func() {
a.mainPages.RemovePage("submenu2")
})
form.SetBorder(true).SetTitle("设置 HTTP 端口")
form.SetBorder(true).SetTitle("设置 HTTP 地址")
a.mainPages.AddPage("submenu2", form, true, true)
a.SetFocus(form)

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path/filepath"
"strings"
"github.com/sjzar/chatlog/internal/chatlog/conf"
"github.com/sjzar/chatlog/internal/chatlog/ctx"
@@ -128,6 +129,21 @@ func (m *Manager) StopService() error {
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 {
if m.ctx.Current == nil {
return fmt.Errorf("未选择任何账号")

View File

@@ -260,13 +260,13 @@ func (ds *DataSource) GetContacts(ctx context.Context, key string, limit, offset
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
WHERE m_nsUsrName = ? OR nickname = ? OR m_nsRemark = ? OR m_nsAliasName = ?`
args = []interface{}{key, key, key, key}
} 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`
}
@@ -314,13 +314,13 @@ func (ds *DataSource) GetChatRooms(ctx context.Context, key string, limit, offse
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
WHERE m_nsUsrName = ? OR nickname = ? OR m_nsRemark = ?`
args = []interface{}{key, key, key}
} 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`
}
@@ -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") {
// 再次尝试通过用户名查找群聊
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
WHERE m_nsUsrName = ?`,
contacts[0].UserName)

View File

@@ -32,3 +32,12 @@ func MustAnyToInt(v interface{}) int {
}
return 0
}
func IsNumeric(s string) bool {
for _, r := range s {
if !unicode.IsDigit(r) {
return false
}
}
return len(s) > 0
}