fix: replace with session ID

This commit is contained in:
lilong.129
2025-03-05 14:51:01 +08:00
parent b9db874f38
commit 98d1ecb478
3 changed files with 8 additions and 9 deletions

View File

@@ -1 +1 @@
v5.0.0+2503051147
v5.0.0+2503051452

View File

@@ -105,7 +105,7 @@ func TestDriverExt_Seek(t *testing.T) {
err := driver.Swipe(0.5, 0.8, 0.5, 0.2)
assert.Nil(t, err)
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)
time.Sleep(1 * time.Second)
}

View File

@@ -38,15 +38,11 @@ type DriverRequests struct {
Error string `json:"error,omitempty"`
}
const (
emptySessionID = "<SessionNotInit>"
)
func NewDriverSession() *DriverSession {
timeout := 30 * time.Second
session := &DriverSession{
ctx: context.Background(),
ID: emptySessionID,
ID: "",
timeout: timeout,
client: &http.Client{
Timeout: timeout,
@@ -101,8 +97,11 @@ func (s *DriverSession) concatURL(urlStr string) (string, error) {
}
// replace with session ID
if s.ID != emptySessionID {
urlStr = strings.Replace(urlStr, emptySessionID, s.ID, 1)
if s.ID != "" && !strings.Contains(urlStr, s.ID) {
sessionPattern := regexp.MustCompile(`/session/([^/]+)/`)
if matches := sessionPattern.FindStringSubmatch(urlStr); len(matches) != 0 {
urlStr = strings.Replace(urlStr, matches[1], s.ID, 1)
}
}
// 处理完整 URL