Merge pull request #1 from HoshinoDesu/cursor/-bc-22f1b125-2577-40ff-8bac-b0354c1cf205-5f3d
问候信息
This commit is contained in:
14 files changed
+34
-25
No files matched your search
@@ -5,6 +5,7 @@ sms-forwarder-linux-arm64
|
||||
*.exe
|
||||
dist/
|
||||
dist-min/
|
||||
dist-release/
|
||||
|
||||
# 配置文件
|
||||
config.toml
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -197,11 +197,7 @@ func (f *Forwarder) handleMessage(m *modem.Modem, sms *modem.SMS) error {
|
||||
// incoming := sms.State == modem.SMSStateReceived || sms.State == modem.SMSStateReceiving
|
||||
|
||||
smsPath := sms.Path()
|
||||
textPreview := sms.Text
|
||||
if len(textPreview) > 20 {
|
||||
textPreview = textPreview[:20]
|
||||
}
|
||||
slog.Info("handleMessage调用", "path", smsPath, "from", sms.Number, "state", sms.State.String(), "text_preview", textPreview)
|
||||
slog.Debug("handleMessage调用", "path", smsPath, "from", sms.Number, "state", sms.State.String())
|
||||
|
||||
// 优先过滤旧消息(避免重启后重复发送)
|
||||
// if incoming && !sms.Timestamp.IsZero() && time.Since(sms.Timestamp) > 5*time.Minute {
|
||||
@@ -226,7 +222,6 @@ func (f *Forwarder) handleMessage(m *modem.Modem, sms *modem.SMS) error {
|
||||
"imei", m.EquipmentIdentifier,
|
||||
"from", sms.Number,
|
||||
"timestamp", sms.Timestamp,
|
||||
"text", sms.Text,
|
||||
)
|
||||
|
||||
// 保存到存储
|
||||
|
||||
@@ -51,6 +51,7 @@ func (m *Manager) Modems() (map[dbus.ObjectPath]*Modem, error) {
|
||||
|
||||
modem, err := NewModem(m.conn, objectPath)
|
||||
if err != nil {
|
||||
slog.Warn("初始化调制解调器失败", "path", objectPath, "error", err)
|
||||
continue
|
||||
}
|
||||
modems[objectPath] = modem
|
||||
|
||||
@@ -70,7 +70,7 @@ func (msg *Messaging) Subscribe(ctx context.Context, subscriber func(message *SM
|
||||
for {
|
||||
select {
|
||||
case sig := <-signalChan:
|
||||
if len(sig.Body) < 2 {
|
||||
if sig == nil || len(sig.Body) < 2 {
|
||||
continue
|
||||
}
|
||||
// Body[0] 是 ObjectPath, Body[1] 是 bool (received)
|
||||
|
||||
@@ -34,15 +34,21 @@ func NewModem(conn *dbus.Conn, path dbus.ObjectPath) (*Modem, error) {
|
||||
|
||||
// 获取设备信息
|
||||
if variant, err := obj.GetProperty(ModemInterface + ".EquipmentIdentifier"); err == nil {
|
||||
modem.EquipmentIdentifier = variant.Value().(string)
|
||||
if v, ok := variant.Value().(string); ok {
|
||||
modem.EquipmentIdentifier = v
|
||||
}
|
||||
}
|
||||
|
||||
if variant, err := obj.GetProperty(ModemInterface + ".Model"); err == nil {
|
||||
modem.Model = variant.Value().(string)
|
||||
if v, ok := variant.Value().(string); ok {
|
||||
modem.Model = v
|
||||
}
|
||||
}
|
||||
|
||||
if variant, err := obj.GetProperty(ModemInterface + ".Manufacturer"); err == nil {
|
||||
modem.Manufacturer = variant.Value().(string)
|
||||
if v, ok := variant.Value().(string); ok {
|
||||
modem.Manufacturer = v
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试获取 MSISDN
|
||||
|
||||
@@ -2,6 +2,7 @@ package modem
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
@@ -104,10 +105,9 @@ func (msg *Messaging) retrieveWithConn(conn *dbus.Conn, objectPath dbus.ObjectPa
|
||||
return nil, fmt.Errorf("短信时间字段类型错误")
|
||||
}
|
||||
if t != "" {
|
||||
// 处理时区格式(+08:00 需要转为 +08:00)
|
||||
if len(t) >= 3 && (t[len(t)-3] == '+' || t[len(t)-3] == '-') {
|
||||
t = t + ":00"
|
||||
}
|
||||
// 处理短时区格式,如 "+08" -> "+08:00"、"-05" -> "-05:00"
|
||||
shortTZPattern := regexp.MustCompile(`([+-]\d{2})$`)
|
||||
t = shortTZPattern.ReplaceAllString(t, "${1}:00")
|
||||
sms.Timestamp, err = time.Parse(time.RFC3339, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/CyberPigeon/internal/config"
|
||||
@@ -55,7 +56,10 @@ func (b *BarkChannel) Send(msg Message) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("Bark 返回错误状态: %d", resp.StatusCode)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/CyberPigeon/internal/config"
|
||||
@@ -61,7 +62,10 @@ func (g *GotifyChannel) Send(msg Message) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("Gotify 返回错误状态: %d", resp.StatusCode)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package notifier
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
@@ -95,14 +96,7 @@ func (n *Notifier) Send(msg Message) error {
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// 返回最后一个错误
|
||||
var lastErr error
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
}
|
||||
}
|
||||
return lastErr
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
// createChannel 根据配置创建通道
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -139,7 +140,10 @@ func (w *WebhookChannel) Send(msg Message) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return fmt.Errorf("Webhook 返回错误状态: %d", resp.StatusCode)
|
||||
|
||||
Reference in new issue
Block a user