eprolo-cli 1.0.55 → 1.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/eprolo-cli.js +27 -31
  2. package/package.json +1 -1
package/bin/eprolo-cli.js CHANGED
@@ -91,29 +91,27 @@ async function postJsonWithRetry(url, body, config) {
91
91
 
92
92
  let result = await postJson(url, body, headers);
93
93
 
94
- // if (result.statusCode === 401) {
95
- // // 刷新 token
96
- // const refreshRes = await postJson(REFRESH_API, {
97
- // accessToken: config.accessToken,
98
- // accountId: config.accountId,
99
- // shopId: config.shopId
100
- // });
101
-
102
- // if (refreshRes.statusCode >= 200 && refreshRes.statusCode < 300 && refreshRes.data.accessToken) {
103
- // // 更新凭据文件
104
- // config.accessToken = refreshRes.data.accessToken;
105
- // if (refreshRes.data.account) config.account = refreshRes.data.account;
106
- // writeConfig(config);
107
-
108
- // // 用新 token 重试
109
- // headers["authorization"] = `Bearer ${config.accessToken}`;
110
- // result = await postJson(url, body, headers);
111
- // } else {
112
- // const err = new Error("Token 刷新失败,请重新登录授权");
113
- // err.response = refreshRes.data;
114
- // throw err;
115
- // }
116
- // }
94
+ if (result.code === 400) {
95
+ // 刷新 token
96
+ const refreshRes = await postJson(REFRESH_API, {},{
97
+ refreshToken: config.refreshToken
98
+ });
99
+
100
+ if (refreshRes.code === 0 && refreshRes.data.accessToken) {
101
+ // 更新凭据文件
102
+ config.accessToken = refreshRes.data.accessToken;
103
+ if (refreshRes.data.account) config.account = refreshRes.data.account;
104
+ writeConfig(config);
105
+
106
+ // 用新 token 重试
107
+ headers["accessToken"] = `${config.accessToken}`;
108
+ result = await postJson(url, body, headers);
109
+ } else {
110
+ const err = new Error("Token 刷新失败,请重新登录授权");
111
+ err.response = refreshRes.data;
112
+ throw err;
113
+ }
114
+ }
117
115
 
118
116
  if (result.code !== 0) {
119
117
  const err = new Error(`HTTP ${result.statusCode}`);
@@ -132,23 +130,21 @@ async function login(argv) {
132
130
  const userCode = process.env.EPROLO_USER_CODE; // env 通道
133
131
  if (!userCode) { console.error("缺少用户密文:请在授权弹窗中填写"); process.exit(2); }
134
132
 
135
- const defaultShop = readFlag(argv, "--default-shop"); // arg 通道,可能不存在
136
-
137
133
  const res = await postJson(LOGIN_API, { openApiKey: userCode });
138
134
 
139
- if (res.statusCode < 200 || res.statusCode >= 300) {
135
+ if (res.code !== 0) {
140
136
  console.error(JSON.stringify({
141
137
  success: false,
142
- errorMessage: "密文验证失败,请到账号设置页重新复制",
143
- statusCode: res.statusCode,
138
+ errorMessage: res.error || "登录失败",
139
+ statusCode: res.code,
144
140
  response: res.data
145
141
  }));
146
142
  process.exit(1);
147
143
  }
148
144
 
149
- const { account, accessToken, accountId, shopId } = res.data;
150
- const config = { account, accessToken, defaultShop, accountId, shopId, version: 1 };
151
- writeConfig(config);
145
+ // const { account, accessToken, accountId, shopId } = res.data;
146
+ // const config = { account, accessToken, defaultShop, accountId, shopId, version: 1 };
147
+ writeConfig(res.data);
152
148
 
153
149
  console.log("login ok");
154
150
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eprolo-cli",
3
- "version": "1.0.55",
3
+ "version": "1.0.57",
4
4
  "description": "CLI for Dianxiaobao ICBU AI publishing, authorization profile management, task submission, and task status checks.",
5
5
  "bin": {
6
6
  "eprolo": "bin/eprolo-cli.js"