eprolo-cli 1.0.99 → 1.0.101

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 +18 -10
  2. package/package.json +1 -1
package/bin/eprolo-cli.js CHANGED
@@ -48,8 +48,14 @@ function readFlag(argv, flag) {
48
48
  // ---------------------------------------------------------------------------
49
49
 
50
50
  function postJson(url, body, headers = {},method = "POST") {
51
+ const config = readConfig();
52
+ let signValue={}
53
+ if(config.timestamp){
54
+ signValue.timestamp = config.timestamp;
55
+ signValue.sign = config.accessToken;
56
+ }
57
+ url += "?" + new URLSearchParams(signValue).toString();
51
58
  if(method == "GET") {
52
- url += "?" + new URLSearchParams(body).toString();
53
59
  body = {};
54
60
  }
55
61
  return new Promise((resolve, reject) => {
@@ -99,10 +105,6 @@ function postJson(url, body, headers = {},method = "POST") {
99
105
  async function postJsonWithRetry(url, body, config, method = "POST") {
100
106
  let headers = {};
101
107
  if (config.apiKey) headers["apiKey"] = `${config.apiKey}`;
102
- if(config.timestamp){
103
- body.timestamp = config.timestamp;
104
- body.sign = config.accessToken;
105
- }
106
108
  let result = await postJson(url, body, headers, method);
107
109
  if (result.data.code == '-1') {
108
110
  // 刷新 token
@@ -110,8 +112,6 @@ async function postJsonWithRetry(url, body, config, method = "POST") {
110
112
 
111
113
  if (refreshRes.data.code == 0) {
112
114
  // 更新凭据文件
113
- body.timestamp = refreshRes.data.data.timestamp;
114
- body.sign = refreshRes.data.data.accessToken;
115
115
  writeConfig(refreshRes.data.data);
116
116
 
117
117
  // 用新 token 重试
@@ -236,7 +236,6 @@ function getId(id){
236
236
  }
237
237
  async function insertProduct(arg) {
238
238
  const config = readConfig();
239
- console.log('insertProduct666-----------------------------6',arg);
240
239
  const product = JSON.parse(arg);
241
240
  const info={};
242
241
  const optionList=[];
@@ -265,8 +264,17 @@ async function insertProduct(arg) {
265
264
  product.media.edges.forEach((edge)=>{
266
265
  imageList.push({src:edge.url,images_id:getId(edge.id)});
267
266
  })
268
- const data = await postJsonWithRetry(BASE_URL+'/insert_product.html', info, config, "POST");
269
- console.log(JSON.stringify(data, null, 2));
267
+ const data = await postJsonWithRetry(BASE_URL+'/insert_product.html', info, config, "POST");
268
+ if(data.data.code==-1){
269
+ if(data.data.msg=="product_id exist"){
270
+ const result = await postJsonWithRetry(BASE_URL+'/getproduct.html', {product_id:info.product_id}, config);
271
+ if(result.data.code==0){
272
+ console.log(JSON.stringify({product_id:result.data.data.id}, null, 2));
273
+ process.exit(0);
274
+ }
275
+ }
276
+ }
277
+ console.log(JSON.stringify({product_id:data.data.data.id}, null, 2));
270
278
  process.exit(0);
271
279
  }
272
280
  async function addOrder(arg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eprolo-cli",
3
- "version": "1.0.99",
3
+ "version": "1.0.101",
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"