Commit ca863c6
authored
feat: support feilian v1 login (platform "feilian_v1") (#89)
* feat: support feilian v1 login (platform "feilian_v1")
The newer feilian backend serves login at /api/v1/login with an
AES-CBC-encrypted password instead of the old /api/login (see #78).
Add an opt-in platform "feilian_v1" implementing it:
- utils::feilian_v1_encrypt_password: AES-256-CBC password encoding
(key/iv derived from fixed constants), matching the official client
- POST requests now send Content-Type: application/json; the v1 login
endpoint otherwise rejects the body with "参数错误"
- after login, fetch the TOTP secret from /api/v2/p/otp so 2fa codes
are generated locally, the same way the existing login flow does
- on exit, log out the current terminal (/api/logout) to free the
server-side terminal quota; only for feilian_v1, since SSO platforms
would then need an interactive re-auth on the next run
Refs #78
* fix(client): recover from expired session instead of failing to parse
When the server-side session expires, the API returns a non-zero code
(e.g. 101) with a `data` whose shape no longer matches the success type
T — ListVPN, for example, returns an object where a VPN array is
expected. Deserializing the response straight into Resp<T> failed at
that point, so the run died with an opaque "invalid type: map, expected
a sequence" error and the existing code==101 logout/relogin path never
ran (it lives after the parse).
Parse the envelope into Resp<Value> first to read `code`, and only
coerce `data` into T when code == 0; otherwise carry the code/message
through with data=None. This lets the existing logout handling reset the
state to Init and trigger a (non-interactive, for feilian_v1) re-login
and retry, so an expired session self-heals instead of requiring the
user to manually flip `state` back to Init.
* review: drop redundant comments, hoist crypto imports to file level
Address @PinkD review on #89:
- remove the Content-Type explanatory comment (keep the header)
- shorten the logout comment to "only logout for feilian_v1"
- move aes/cbc/sha1 imports in utils.rs to file level1 parent 7901541 commit ca863c6
8 files changed
Lines changed: 268 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
| |||
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| 40 | + | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
| |||
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
| |||
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
87 | 99 | | |
88 | 100 | | |
89 | 101 | | |
90 | 102 | | |
91 | 103 | | |
92 | 104 | | |
| 105 | + | |
93 | 106 | | |
94 | 107 | | |
95 | 108 | | |
| |||
120 | 133 | | |
121 | 134 | | |
122 | 135 | | |
| 136 | + | |
123 | 137 | | |
124 | 138 | | |
| 139 | + | |
125 | 140 | | |
126 | 141 | | |
127 | 142 | | |
| |||
0 commit comments