Commit e04e6148 by yexing

优化代码

parent 107a897b
3.5.0
\ No newline at end of file
3.5.3
\ No newline at end of file
No preview for this file type
......@@ -383,15 +383,15 @@ var G = (function (exports) {
if (!(this.uri && this.partnerId)) {
throw new Error(`uri: ${this.uri}, partnerId: ${this.partnerId}`);
}
this._ext = this.options.ext || "csv"; // 扩展名
this._retryLimit = 6;
this._retryCount = 0;
}
getFileName(sf) {
const ext = this.options.ext || 'csv';
let name = this.names.showName;
name = this.options.noLowerCase ? name : name.toLowerCase();
sf = sf === undefined || sf === null ? '' : ' ' + sf;
return `${this.partnerId} #${name}# ${this.desc}${sf}.${ext}`;
return `${this.partnerId} #${name}# ${this.desc}${sf}.${this._ext}`;
}
async _retry(args) {
if (++this._retryCount < this._retryLimit) {
......@@ -409,7 +409,7 @@ var G = (function (exports) {
const url = new URL(`${this.uri}${this.names.apiName || ''}`);
const method = this.options.method || 'GET';
const callback = this.options.callback;
const ext = this.options.ext || 'csv';
const sign = this.options.sign;
next |= this.options.next;
let body = this.options.body;
......@@ -438,23 +438,21 @@ var G = (function (exports) {
console.error(`重试回调, ${e.message}`);
return this._retry(arguments);
}
} else if (ext == 'json') {
} else if (sign == 'json') {
const json = await response.json();
if (Object.keys(json).length === 0) {
return true;
}
const csv = JSON2CSV(json);
blob = new Blob([csv], { type: "text/csv" });
this.options.ext = "csv";
} else {
blob = await response.blob();
}
if (blob === undefined || blob === null) return false;
if (next) return blob;
const fn = this.getFileName();
if (ext === 'zip') {
const newFn = fn.replace(/\.\w+$/g, ".csv");
return renameZipFile(blob, newFn);
if (sign === 'zip') {
return renameZipFile(blob, fn);
}
return createZip([blob], [fn]);
} catch (e) {
......@@ -914,7 +912,7 @@ var G = (function (exports) {
reportDate,
},
{
ext: "zip",
sign: "zip",
}
),
new Task(
......@@ -926,7 +924,7 @@ var G = (function (exports) {
reportDate,
},
{
ext: "zip",
sign: "zip",
}
)
);
......@@ -1122,7 +1120,7 @@ var G = (function (exports) {
fromDate,
toDate,
},
{ ext: "json", isMmonthly: true }
{ sign: "json", isMmonthly: true }
),
new Task(
{
......@@ -1134,7 +1132,7 @@ var G = (function (exports) {
toDate,
type: "MCS",
},
{ ext: "json", isMmonthly: true }
{ sign: "json", isMmonthly: true }
),
new TaskGroup(
......@@ -1148,7 +1146,7 @@ var G = (function (exports) {
fromDate,
toDate: cut ? cutOffDate : toDate,
},
{ ext: "json" }
{ sign: "json" }
),
new Task(
{
......@@ -1159,7 +1157,7 @@ var G = (function (exports) {
fromDate: cut ? cutOffDate : fromDate,
toDate,
},
{ ext: "json" }
{ sign: "json" }
),
].slice(...se)
),
......@@ -1322,7 +1320,7 @@ var G = (function (exports) {
let fn = task.getFileName();
const isJson = fn.endsWith('.json');
if (!isJson) fn = fn.replace(/\.\w+$/g, ".zip");
if ((isSingle || isJson) && !await checkLog(fn)) {
if (isSingle || isJson ? !await checkLog(fn): false) {
console.log(`${pf} skip2`);
continue;
}
......
{"name":"WalmartExports","description":"导出沃尔玛报表","version":"3.5.0","manifest_version":3,"background":{"service_worker":"./js/background.js"},"permissions":["tabs","activeTab","scripting","notifications","storage","alarms"],"action":{"default_title":"WalmartExports","default_popup":"popup.html","default_icon":{"16":"icon.png","32":"icon.png","48":"icon.png","128":"icon.png"}},"icons":{"16":"icon.png","32":"icon.png","48":"icon.png","128":"icon.png"},"web_accessible_resources":[{"resources":["src/main.js"],"matches":["<all_urls>"]}],"host_permissions":["https://seller.walmart.com/*","https://advertising.walmart.com/*","https://login.account.wal-mart.com/*","https://marketplace.walmartapis.com/*","https://walmart.meinuosha.com/*"],"content_scripts":[{"matches":["https://seller.walmart.com/*","https://advertising.walmart.com/*","https://login.account.wal-mart.com/*","https://marketplace.walmartapis.com/*","https://walmart.meinuosha.com/*"],"js":["./js/main.js"]}]}
\ No newline at end of file
{"name":"WalmartExports","description":"导出沃尔玛报表","version":"3.5.3","manifest_version":3,"background":{"service_worker":"./js/background.js"},"permissions":["tabs","activeTab","scripting","notifications","storage","alarms"],"action":{"default_title":"WalmartExports","default_popup":"popup.html","default_icon":{"16":"icon.png","32":"icon.png","48":"icon.png","128":"icon.png"}},"icons":{"16":"icon.png","32":"icon.png","48":"icon.png","128":"icon.png"},"web_accessible_resources":[{"resources":["src/main.js"],"matches":["<all_urls>"]}],"host_permissions":["https://seller.walmart.com/*","https://advertising.walmart.com/*","https://login.account.wal-mart.com/*","https://marketplace.walmartapis.com/*","https://walmart.meinuosha.com/*"],"content_scripts":[{"matches":["https://seller.walmart.com/*","https://advertising.walmart.com/*","https://login.account.wal-mart.com/*","https://marketplace.walmartapis.com/*","https://walmart.meinuosha.com/*"],"js":["./js/main.js"]}]}
\ No newline at end of file
......@@ -413,7 +413,7 @@ export async function createTasks(uri, fromDate, toDate) {
reportDate,
},
{
ext: "zip",
sign: "zip",
}
),
new Task(
......@@ -425,7 +425,7 @@ export async function createTasks(uri, fromDate, toDate) {
reportDate,
},
{
ext: "zip",
sign: "zip",
}
)
);
......@@ -621,7 +621,7 @@ export async function createTasks(uri, fromDate, toDate) {
fromDate,
toDate,
},
{ ext: "json", isMmonthly: true }
{ sign: "json", isMmonthly: true }
),
new Task(
{
......@@ -633,7 +633,7 @@ export async function createTasks(uri, fromDate, toDate) {
toDate,
type: "MCS",
},
{ ext: "json", isMmonthly: true }
{ sign: "json", isMmonthly: true }
),
new TaskGroup(
......@@ -647,7 +647,7 @@ export async function createTasks(uri, fromDate, toDate) {
fromDate,
toDate: cut ? cutOffDate : toDate,
},
{ ext: "json" }
{ sign: "json" }
),
new Task(
{
......@@ -658,7 +658,7 @@ export async function createTasks(uri, fromDate, toDate) {
fromDate: cut ? cutOffDate : fromDate,
toDate,
},
{ ext: "json" }
{ sign: "json" }
),
].slice(...se)
),
......
......@@ -38,7 +38,7 @@ export async function run(options = {}) {
let fn = task.getFileName();
const isJson = fn.endsWith('.json');
if (!isJson) fn = fn.replace(/\.\w+$/g, ".zip");
if ((isSingle || isJson) && !await checkLog(fn)) {
if (isSingle || isJson ? !await checkLog(fn): false) {
console.log(`${pf} skip2`);
continue;
}
......
......@@ -59,15 +59,15 @@ export class Task {
if (!(this.uri && this.partnerId)) {
throw new Error(`uri: ${this.uri}, partnerId: ${this.partnerId}`);
}
this._ext = this.options.ext || "csv" // 扩展名
this._retryLimit = 6
this._retryCount = 0
}
getFileName(sf) {
const ext = this.options.ext || 'csv';
let name = this.names.showName;
name = this.options.noLowerCase ? name : name.toLowerCase();
sf = sf === undefined || sf === null ? '' : ' ' + sf;
return `${this.partnerId} #${name}# ${this.desc}${sf}.${ext}`;
return `${this.partnerId} #${name}# ${this.desc}${sf}.${this._ext}`;
}
async _retry(args) {
if (++this._retryCount < this._retryLimit) {
......@@ -85,7 +85,7 @@ export class Task {
const url = new URL(`${this.uri}${this.names.apiName || ''}`);
const method = this.options.method || 'GET';
const callback = this.options.callback;
const ext = this.options.ext || 'csv';
const sign = this.options.sign;
next |= this.options.next;
let body = this.options.body;
......@@ -114,23 +114,21 @@ export class Task {
console.error(`重试回调, ${e.message}`);
return this._retry(arguments);
}
} else if (ext == 'json') {
} else if (sign == 'json') {
const json = await response.json();
if (Object.keys(json).length === 0) {
return true;
}
const csv = JSON2CSV(json);
blob = new Blob([csv], { type: "text/csv" });
this.options.ext = "csv";
} else {
blob = await response.blob();
}
if (blob === undefined || blob === null) return false;
if (next) return blob;
const fn = this.getFileName();
if (ext === 'zip') {
const newFn = fn.replace(/\.\w+$/g, ".csv");
return renameZipFile(blob, newFn);
if (sign === 'zip') {
return renameZipFile(blob, fn);
}
return createZip([blob], [fn]);
} catch (e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment