fix: replace with session ID

This commit is contained in:
lilong.129
2025-03-05 14:52:32 +08:00
parent b9db874f38
commit 98d1ecb478
3 changed files with 8 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
v5.0.0+2503051147 v5.0.0+2503051452
+1 -1
View File
@@ -105,7 +105,7 @@ func TestDriverExt_Seek(t *testing.T) {
err := driver.Swipe(0.5, 0.8, 0.5, 0.2) err := driver.Swipe(0.5, 0.8, 0.5, 0.2)
assert.Nil(t, err) assert.Nil(t, err)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
err = driver.Drag(20, y, float64(width)*0.75, y) err = driver.Swipe(20, y, float64(width)*0.6, y)
assert.Nil(t, err) assert.Nil(t, err)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
+6 -7
View File
@@ -38,15 +38,11 @@ type DriverRequests struct {
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
} }
const (
emptySessionID = "<SessionNotInit>"
)
func NewDriverSession() *DriverSession { func NewDriverSession() *DriverSession {
timeout := 30 * time.Second timeout := 30 * time.Second
session := &DriverSession{ session := &DriverSession{
ctx: context.Background(), ctx: context.Background(),
ID: emptySessionID, ID: "",
timeout: timeout, timeout: timeout,
client: &http.Client{ client: &http.Client{
Timeout: timeout, Timeout: timeout,
@@ -101,8 +97,11 @@ func (s *DriverSession) concatURL(urlStr string) (string, error) {
} }
// replace with session ID // replace with session ID
if s.ID != emptySessionID { if s.ID != "" && !strings.Contains(urlStr, s.ID) {
urlStr = strings.Replace(urlStr, emptySessionID, s.ID, 1) sessionPattern := regexp.MustCompile(`/session/([^/]+)/`)
if matches := sessionPattern.FindStringSubmatch(urlStr); len(matches) != 0 {
urlStr = strings.Replace(urlStr, matches[1], s.ID, 1)
}
} }
// 处理完整 URL // 处理完整 URL