mirror of
https://github.com/gowvp/gb28181.git
synced 2025-12-24 12:12:31 +08:00
加载快照
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/gowvp/gb28181/internal/core/sms"
|
||||
"github.com/gowvp/gb28181/pkg/zlm"
|
||||
"github.com/ixugo/goddd/domain/uniqueid"
|
||||
"github.com/ixugo/goddd/pkg/hook"
|
||||
"github.com/ixugo/goddd/pkg/orm"
|
||||
"github.com/ixugo/goddd/pkg/reason"
|
||||
"github.com/ixugo/goddd/pkg/web"
|
||||
@@ -278,7 +279,7 @@ func (a GB28181API) play(c *gin.Context, _ *struct{}) (*playOutput, error) {
|
||||
body, err := a.uc.SMSAPI.smsCore.GetSnapshot(svr, zlm.GetSnapRequest{
|
||||
URL: out.Items[0].RTSP,
|
||||
TimeoutSec: 10,
|
||||
ExpireSec: 10,
|
||||
ExpireSec: 15,
|
||||
})
|
||||
if err != nil {
|
||||
slog.ErrorContext(c.Request.Context(), "get snapshot", "err", err)
|
||||
@@ -320,13 +321,15 @@ func (a GB28181API) refreshSnapshot(c *gin.Context, in *refreshSnapshotInput) (a
|
||||
img, err := a.uc.SMSAPI.smsCore.GetSnapshot(svr, zlm.GetSnapRequest{
|
||||
URL: in.URL,
|
||||
TimeoutSec: 10,
|
||||
ExpireSec: 10,
|
||||
ExpireSec: 28800,
|
||||
})
|
||||
if err != nil {
|
||||
slog.ErrorContext(c.Request.Context(), "get snapshot", "err", err)
|
||||
// return nil, reason.ErrBadRequest.Msg(err.Error())
|
||||
} else {
|
||||
writeCover(a.uc.Conf.ConfigDir, channelID, img)
|
||||
if hook.MD5FromBytes(img) != "" {
|
||||
writeCover(a.uc.Conf.ConfigDir, channelID, img)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ package zlm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ixugo/goddd/pkg/hook"
|
||||
)
|
||||
|
||||
func TestEngine_GetServerConfig(t *testing.T) {
|
||||
@@ -15,3 +18,21 @@ func TestEngine_GetServerConfig(t *testing.T) {
|
||||
}
|
||||
fmt.Printf("%+v", out)
|
||||
}
|
||||
|
||||
func TestGetSnap(t *testing.T) {
|
||||
const url = "http://127.0.0.1:8080"
|
||||
const link = "rtmp://localhost:1935/rtp/che1ml5"
|
||||
b, err := NewEngine().SetConfig(
|
||||
Config{URL: url, Secret: "jvRqCAzEg7AszBi4gm1cfhwXpmnVmJMG"},
|
||||
).GetSnap(GetSnapRequest{URL: link, TimeoutSec: 50, ExpireSec: 10})
|
||||
if err != nil {
|
||||
t.Errorf("Engine.GetServerConfig() error = %v", err)
|
||||
}
|
||||
|
||||
fmt.Println(len(b))
|
||||
os.WriteFile("snap.jpg", b, 0o644)
|
||||
fmt.Println(string(b))
|
||||
|
||||
md5 := hook.MD5FromBytes(b)
|
||||
fmt.Println(md5)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package zlm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/ixugo/goddd/pkg/hook"
|
||||
)
|
||||
|
||||
const (
|
||||
getSnapshot = `/index/api/getSnap`
|
||||
)
|
||||
@@ -12,10 +19,26 @@ type GetSnapRequest struct {
|
||||
|
||||
// GetSnap 获取截图或生成实时截图并返回
|
||||
// https://docs.zlmediakit.com/zh/guide/media_server/restful_api.html#_23%E3%80%81-index-api-getsnap
|
||||
func (e *Engine) GetSnap(in GetSnapRequest) ([]byte, error) {
|
||||
func (e Engine) GetSnap(in GetSnapRequest) ([]byte, error) {
|
||||
body, err := struct2map(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.post2(getSnapshot, body)
|
||||
b, err := e.post2(getSnapshot, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(b) < 100 {
|
||||
var resp OpenRTPServerResponse
|
||||
if err := json.Unmarshal(b, &resp); err == nil {
|
||||
if err := e.ErrHandle(resp.Code, resp.Msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(b) == 47255 && hook.MD5FromBytes(b) == "32ddfa5715059731ae893ec92fca0311" {
|
||||
return nil, fmt.Errorf("zlm: 没有更新图片")
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user