Skip to content

fix: 189 cloud login reliability, CJK share path, proactive token refresh - #8

Open
slamdunk111 wants to merge 1 commit into
tickstep:masterfrom
slamdunk111:master
Open

fix: 189 cloud login reliability, CJK share path, proactive token refresh#8
slamdunk111 wants to merge 1 commit into
tickstep:masterfrom
slamdunk111:master

Conversation

@slamdunk111

Copy link
Copy Markdown

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.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: hit the current unifyLoginForPC.action entry point instead of the removed udb/udb_login.jsp; parse form tokens with regexp.MustCompile + 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. Replaced with strings.TrimSuffix(shareIds, ",") and dropped 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. API_URL is moved from const to var so callers' tests can inject an httptest mock-server URL; runtime value unchanged.

Verification

  • go build ./...
  • go vet ./...
  • cloudpan package tests (app_login_test.go, login_test.go) ✅ pass
  • Note: cloudpan/apiutil TestSignatureOfHmac fails on pristine upstream too (a hex-case mismatch), unrelated to this change.

…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.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant