mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 23:07:51 +00:00
fix(translate): resolve DeepL iOS app version at runtime (#238)
Merge branch 'pr-238' (JounQin/DLX:feat/dynamic-ios-app-version). Look up the current DeepL iOS version from Apple's App Store lookup API lazily, cache it for 24h and fall back to the pinned constant on any failure. Conflict in translate/translate.go resolved by keeping the PR's fallback wording and the 26.52 value from #237. Fixes #236
This commit is contained in:
+26
-14
@@ -42,8 +42,11 @@ import (
|
||||
// traffic hard; oneshot lives on a separate pool and accepts the literal
|
||||
// header `Authorization: None` for free requests.
|
||||
//
|
||||
// Request shape reverse-engineered from DeepL iOS 26.42 (build 5443737,
|
||||
// bundle com.linguee.DeepLMobileTranslator, IPA Info.plist + ItaClient.framework):
|
||||
// Request shape reverse-engineered from the DeepL iOS client (bundle
|
||||
// com.linguee.DeepLMobileTranslator, IPA Info.plist + ItaClient.framework).
|
||||
// The advertised app version is resolved at runtime from the App Store
|
||||
// (appversion.go) so a DeepL release cannot silently invalidate the profile;
|
||||
// iosAppVersion below is only the fallback.
|
||||
//
|
||||
// Transport
|
||||
// ItaClient oneshot uses Ktor Darwin engine
|
||||
@@ -73,11 +76,12 @@ const (
|
||||
oneshotFreeEndpoint = "https://oneshot-free.www.deepl.com/v1/translate"
|
||||
oneshotProEndpoint = "https://oneshot-pro.www.deepl.com/v1/translate"
|
||||
|
||||
// Pinned to DeepL iOS IPA (CFBundleShortVersionString / CFBundleVersion).
|
||||
// This has to track DeepL's current App Store release: a version that is no
|
||||
// longer current is rejected the same way as a future one — every request
|
||||
// comes back HTTP 429 ("your IP has been blocked by DeepL temporarily"),
|
||||
// from any IP, direct or proxied. Bump it when DeepL ships a new build.
|
||||
// Fallback DeepL iOS version, used only when the runtime App Store
|
||||
// lookup fails (appversion.go). Keep it tracking DeepL's current App Store
|
||||
// release: a stale version is answered with HTTP 429 on every request
|
||||
// ("your IP has been blocked by DeepL temporarily"), from any IP. The build
|
||||
// number stays pinned because Apple's lookup API does not expose
|
||||
// CFBundleVersion.
|
||||
iosAppVersion = "26.52"
|
||||
iosAppBuild = "5443737"
|
||||
|
||||
@@ -309,12 +313,13 @@ func newOneshotClient(proxyURL string) (*req.Client, error) {
|
||||
// - TLS ClientHello ≈ real iOS (utls HelloIOS_Auto)
|
||||
// - Cookie jar shared like URLSession's HTTPCookieStorage
|
||||
// - Common headers = what URLSession attaches by default
|
||||
// Per-request headers (Authorization, x-app-*) are set in callOneshot.
|
||||
// Per-request headers (Authorization, User-Agent, x-app-*) are set in
|
||||
// callOneshot; the client-level User-Agent is only a default.
|
||||
client := req.C().
|
||||
SetTLSFingerprintIOS().
|
||||
SetCookieJar(sharedCookieJar()).
|
||||
SetTimeout(oneshotTimeout).
|
||||
SetUserAgent(iosUserAgent()).
|
||||
SetUserAgent(iosUserAgent(iosAppVersion)).
|
||||
// URLSession default Accept-Encoding for data tasks.
|
||||
SetCommonHeader("Accept-Encoding", "gzip, deflate, br").
|
||||
SetCommonHeader("Accept", "*/*").
|
||||
@@ -336,10 +341,10 @@ func newOneshotClient(proxyURL string) (*req.Client, error) {
|
||||
// Darwin stack emits (CFBundleName/CFBundleShortVersionString + CFNetwork
|
||||
// + Darwin). Do NOT invent alternate formats (e.g. embedding the bundle
|
||||
// ID) — mismatched UA + iOS TLS fingerprint is a cheap ban signal.
|
||||
func iosUserAgent() string {
|
||||
func iosUserAgent(appVersion string) string {
|
||||
return fmt.Sprintf(
|
||||
"DeepL/%s CFNetwork/%s Darwin/%s",
|
||||
iosAppVersion, iosCFNetworkVersion, iosDarwinVersion,
|
||||
appVersion, iosCFNetworkVersion, iosDarwinVersion,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -347,7 +352,9 @@ func iosUserAgent() string {
|
||||
// For anonymous traffic bearerToken is empty and we send the literal
|
||||
// header `Authorization: None` — matching ItaClient.LoginNone. Omitting
|
||||
// that header puts the request on a different server-side auth branch.
|
||||
func callOneshot(endpoint string, body []byte, bearerToken, proxyURL string) (gjson.Result, int, error) {
|
||||
// appVersion is the value the request body advertises; the same value is
|
||||
// echoed in the User-Agent so TLS, UA and app_information stay consistent.
|
||||
func callOneshot(endpoint string, body []byte, bearerToken, proxyURL, appVersion string) (gjson.Result, int, error) {
|
||||
client, err := getOneshotClient(proxyURL)
|
||||
if err != nil {
|
||||
return gjson.Result{}, 0, err
|
||||
@@ -363,6 +370,7 @@ func callOneshot(endpoint string, body []byte, bearerToken, proxyURL string) (gj
|
||||
DisableAutoReadResponse().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetHeader("Authorization", authValue).
|
||||
SetHeader("User-Agent", iosUserAgent(appVersion)).
|
||||
// ClientInfos.appHeaders (Util/ClientInfos.swift) — only these three
|
||||
// x-app-* keys exist in the iOS binary.
|
||||
SetHeader("x-app-os-version", iosOSVersion).
|
||||
@@ -439,6 +447,10 @@ func TranslateByDLX(sourceLang, targetLang, text string, tagHandling string, pro
|
||||
// official v2 API does — ignored upstream.
|
||||
_ = tagHandling
|
||||
|
||||
// Resolve the advertised version once per request so the User-Agent and
|
||||
// app_information always agree; the lookup itself is cached (appversion.go).
|
||||
appVersion := currentIOSAppVersion()
|
||||
|
||||
reqStruct := oneshotRequest{
|
||||
Text: []string{text},
|
||||
TargetLang: resolvedTarget,
|
||||
@@ -448,7 +460,7 @@ func TranslateByDLX(sourceLang, targetLang, text string, tagHandling string, pro
|
||||
AppInformation: appInformation{
|
||||
OS: "iOS",
|
||||
OSVersion: iosOSVersion,
|
||||
AppVersion: iosAppVersion,
|
||||
AppVersion: appVersion,
|
||||
AppBuild: iosAppBuild,
|
||||
InstanceID: instanceID,
|
||||
},
|
||||
@@ -461,7 +473,7 @@ func TranslateByDLX(sourceLang, targetLang, text string, tagHandling string, pro
|
||||
}
|
||||
|
||||
id := time.Now().UnixMilli()
|
||||
result, status, err := callOneshot(endpoint, bodyBytes, dlSession, proxyURL)
|
||||
result, status, err := callOneshot(endpoint, bodyBytes, dlSession, proxyURL, appVersion)
|
||||
if err != nil {
|
||||
// Map upstream timeouts to 504 so callers can distinguish "DeepL
|
||||
// took too long" from other 503 failure modes (DNS, TLS, etc.).
|
||||
|
||||
Reference in New Issue
Block a user