fix: 189 cloud login reliability, CJK share path, proactive token refresh - #8
Open
slamdunk111 wants to merge 1 commit into
Open
fix: 189 cloud login reliability, CJK share path, proactive token refresh#8slamdunk111 wants to merge 1 commit into
slamdunk111 wants to merge 1 commit into
Conversation
…resh
Port real-world fixes (developed in a long-running fork based on this
library) that address observed failures against the live 天翼云盘 API.
1. Login flow adaptation (cloudpan/login.go, cloudpan/app_login.go)
The official login entry point and the embedded form-token regexes have
drifted, so password login silently mis-parsed captchaToken / lt /
paramId (index-out-of-range panic on FindStringSubmatch(...)[1]) and lost
the COOKIE_LOGIN_USER cookie required to obtain the PC session.
- getLoginParams: use the current unifyLoginForPC.action entry point
instead of the removed udb/udb_login.jsp; parse the form tokens with
MustCompile plus nil-safe `len(match) > 1` guards instead of raw [1].
- Login / AppLogin: surface the server message (r.Msg) instead of a
generic "登录失败"; capture COOKIE_LOGIN_USER by visiting ToUrl and
reading the cookie jar, with a resp.Request().Cookies() fallback.
2. CJK share path (cloudpan/share.go)
text.Substr(shareIds, 0, len-1) mis-slices multi-byte (CJK) share ids and
can truncate mid-rune. Replace with strings.TrimSuffix(shareIds, ",") and
drop the library-go/text dependency for this call.
3. Proactive token refresh (cloudpan/app_login.go, cloudpan/api_constant.go)
Expose RefreshUserSessionByAccessToken(accessToken) (wraps the existing
dead-code getSessionByAccessToken) so callers can renew the PC session
with the long-lived accessToken instead of a full password re-login — the
frequent password re-login is what triggers 天翼's rate limiting.
Move API_URL from const to var so callers' tests can inject an httptest
mock-server URL; the runtime value is unchanged.
Verified: `go build ./...` and `go vet ./...` pass; the `cloudpan` package
tests (app_login_test.go, login_test.go) pass.
(Note: cloudpan/apiutil TestSignatureOfHmac fails on pristine upstream as
well — a hex-case mismatch unrelated to this change.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Real-world fixes developed in a long-running fork based on this library, each addressing an observed failure against the live 天翼云盘 (China Telecom 189 cloud) API.
1. Login flow adaptation —
cloudpan/login.go,cloudpan/app_login.goThe official login entry point and the embedded form-token regexes have drifted, so password login silently mis-parsed
captchaToken/lt/paramId(index-out-of-range panic onFindStringSubmatch(...)[1]) and lost theCOOKIE_LOGIN_USERcookie required to obtain the PC session.getLoginParams: hit the currentunifyLoginForPC.actionentry point instead of the removedudb/udb_login.jsp; parse form tokens withregexp.MustCompile+ nil-safelen(match) > 1guards instead of raw[1].Login/AppLogin: surface the server message (r.Msg) instead of a generic"登录失败"; captureCOOKIE_LOGIN_USERby visitingToUrland reading the cookie jar, with aresp.Request().Cookies()fallback.2. CJK share path —
cloudpan/share.gotext.Substr(shareIds, 0, len-1)mis-slices multi-byte (CJK) share ids and can truncate mid-rune. Replaced withstrings.TrimSuffix(shareIds, ",")and dropped thelibrary-go/textdependency for this call.3. Proactive token refresh —
cloudpan/app_login.go,cloudpan/api_constant.goExpose
RefreshUserSessionByAccessToken(accessToken)(wraps the existing dead-codegetSessionByAccessToken) so callers can renew the PC session with the long-livedaccessTokeninstead of a full password re-login — the frequent password re-login is what triggers 天翼's rate limiting.API_URLis moved fromconsttovarso callers' tests can inject anhttptestmock-server URL; runtime value unchanged.Verification
go build ./...✅go vet ./...✅cloudpanpackage tests (app_login_test.go,login_test.go) ✅ passcloudpan/apiutilTestSignatureOfHmacfails on pristine upstream too (a hex-case mismatch), unrelated to this change.