更新adobe 优化408

This commit is contained in:
2026-08-01 01:49:05 +08:00
parent a1514b5f82
commit 110edc9b81
2 changed files with 51 additions and 20 deletions
+44 -4
View File
@@ -7,15 +7,23 @@ import (
"encoding/json"
"math/big"
"net/url"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/google/uuid"
)
// arpPIDPool maps access tokens to unique PIDs so the same account always
// reuses its PID and different accounts never collide. Guarded by arpPIDMu.
var (
arpPIDMu sync.Mutex
arpTokenPID = map[string]int{} // token → pid
arpPIDToken = map[int]string{} // pid → token
)
// adobeUserIDPat matches Adobe IMS user IDs embedded in cookies (e.g.
// "4BDA81F069FC6DA40A495FAB@AdobeID").
var adobeUserIDPat = regexp.MustCompile(`[A-Fa-f0-9]{20,}@AdobeID`)
@@ -96,12 +104,11 @@ func decodeJWTPayload(token string) map[string]any {
return out
}
func buildARPSessionID() string {
func buildARPSessionID(token string) string {
// Matches adobe2api's format exactly:
// base64({"sid":"<uuid>","ftr":"<hex16>_<ts_ms>_<pid>_dUAL43-mnts-ants-d4_31ck__tt"})
// Two fields only (no "ark") — mirrors what a real browser session sends.
pid := os.Getpid()
ftr := randomHex(16) + "_" + strconv.FormatInt(time.Now().UnixMilli(), 10) + "_" + strconv.Itoa(pid) + "_dUAL43-mnts-ants-d4_31ck__tt"
ftr := randomHex(16) + "_" + strconv.FormatInt(time.Now().UnixMilli(), 10) + "_" + strconv.Itoa(allocPID(token)) + "_dUAL43-mnts-ants-d4_31ck__tt"
raw := map[string]any{
"sid": uuid.NewString(),
"ftr": ftr,
@@ -110,6 +117,39 @@ func buildARPSessionID() string {
return base64.StdEncoding.EncodeToString(b)
}
// allocPID returns a unique PID bound to token. Same token always gets the
// same PID; different tokens never share a PID. Picks randomly from
// [1000, 99999] and retries on collision.
func allocPID(token string) int {
arpPIDMu.Lock()
defer arpPIDMu.Unlock()
if pid, ok := arpTokenPID[token]; ok {
return pid
}
for {
pid := randomInt(1000, 99999)
if _, used := arpPIDToken[pid]; !used {
arpPIDToken[pid] = token
arpTokenPID[token] = pid
return pid
}
}
}
// ReleasePID releases the PID bound to token so it can be reused by another
// account. Call this when a token/session is finished (e.g. after the Adobe
// API request completes or on token expiry).
func ReleasePID(token string) {
arpPIDMu.Lock()
defer arpPIDMu.Unlock()
if pid, ok := arpTokenPID[token]; ok {
delete(arpPIDToken, pid)
delete(arpTokenPID, token)
}
}
func randomHex(n int) string {
if n <= 0 {
return ""