Commit 3db14115 by yexing

[yx] update

parent f63311b6
2.4.3
\ No newline at end of file
2.5.1
\ No newline at end of file
No preview for this file type
......@@ -19685,41 +19685,28 @@
let taskInterval = null, taskNum = 0, logs = [];
function startTask() {
// chrome.storage.local.get(['isRunning']).then(console.log);
// chrome.storage.local.set({ isRunning: true });
taskNum++;
if (taskInterval) return;
chrome.storage.local.set({ isRunning: true });
// chrome.storage.local.get(null, console.log);
taskInterval = setInterval(() => {
// 推送更新
const ackLen = logs.filter(x => x.message.includes("完成")).length;
chrome.runtime.sendMessage({ type: 'progress', logs });
if (ackLen === taskNum) {
clearInterval(taskInterval);
// recycle
taskInterval = null, taskNum = 0;
logs.push({
time: new Date().toLocaleTimeString(),
message: "已全部完成"
});
chrome.runtime.sendMessage({ type: 'progress', logs });
// copy logs
chrome.storage.local.set({ isRunning: false, logs });
clearInterval(taskInterval);
// recycle
taskInterval = null, taskNum = 0, logs = [];
}
chrome.runtime.sendMessage({
type: 'progress', logs
});
}, 1000);
}
const initTimedTask = () => {
for (const [key, { uri, params }] of Object.entries(TABLE)) {
const plan = new Plan(null, params);
const period = plan.get()?.period;
const when = plan.next().dt.getTime();
chrome.alarms.create(key, { when });
console.log(`[timedTask] uri: ${uri} period: ${period} when: ${when}`);
}
};
chrome.alarms.onAlarm.addListener((alarm) => {
let [key, fromDate, toDate, when] = alarm.name.split('_');
if (!Object.keys(TABLE).includes(key)) return;
......@@ -19735,14 +19722,10 @@
sendTabMsg({ type: "run", data: { uri, period } });
});
// 初始化
initTimedTask();
// chrome.alarms.clearAll();
const getTmpClock = () => {
const clock = new Date();
clock.setHours(22, 0, 0, 0);
return clock.getTime();
};
// initTimedTask();
// chrome.storage.local.clear();
// chrome.alarms.getAll(console.log);
chrome.alarms.clearAll();
globalThis.initTmpTimedTask = (when) => {
const period = ['2025-02-01', '2025-02-28'];
for (const [key, { uri }] of Object.entries(TABLE)) {
......@@ -19751,7 +19734,7 @@
console.log(`[timedTask] uri: ${uri} period: ${period} when: ${when}`);
}
};
globalThis.initTmpTimedTask(getTmpClock());
// globalThis.initTmpTimedTask(getTmpClock());
// initTmpTimedTask(new Date().getTime() + 10)
})();
......@@ -138,10 +138,6 @@
}));
return rr;
};
const gHeaders = Object.freeze({
"Accept-Encoding": "gzip, deflate, br",
"wm_aurora.market": "US",
});
const headers = Object.freeze({
"wm_aurora.market": "US",
});
......@@ -227,6 +223,8 @@
if (!(this.uri && this.scid)) {
throw new Error(`uri: ${this.uri}, scid: ${this.scid}`);
}
this._retryLimit = 5;
this._retryCount = 0;
}
getFileName(sf) {
const ext = this.options.ext || 'csv';
......@@ -254,6 +252,19 @@
...this.options.requestInit
});
console.log(response);
if (response.status !== 200) {
if (++this._retryCount < this._retryLimit) {
await sleep(DELAY);
const text = await response.text();
console.log(`重试请求, ${text}`);
return await this.send(...arguments);
} else {
console.error(`重试失败: ${response.url}`);
return false;
}
}
this._retryCount = 0; // reset
let blob;
if (callback) {
blob = await callback.call(this, response);
......@@ -625,7 +636,7 @@
}, {
fromDate,
toDate,
}, { headers: gHeaders }),
}),
new Task({
apiName: "poAudit",
showName: "Inbound receipts"
......@@ -713,6 +724,7 @@
}
}
// fetch("https://advertising.walmart.com/extend-sso")
async function webJump() {
if (location.hostname === 'login.account.wal-mart.com') {
document.querySelector("button").click();
......
{"name":"Test","description":"导出沃尔玛报表","version":"2.4.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
{"name":"WalmartExports","description":"导出沃尔玛报表","version":"2.5.1","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
......@@ -20,7 +20,7 @@ const changeManifest = (others = {}) => {
}
const inputs = ["src/main.js", "src/popup.js", "src/background.js"];
const conf = [];
const nodeEnv = process.env.NODE_ENV.trim() || 'DEV';
const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV';
console.log(`NODE_ENV: ${nodeEnv}`);
nodeEnv == 'TEST' ? changeManifest({ name: 'Test' }) : changeManifest();
inputs.forEach(input => {
......
......@@ -83,32 +83,29 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
let taskInterval = null, taskNum = 0, logs = [];
function startTask() {
// chrome.storage.local.get(['isRunning']).then(console.log);
// chrome.storage.local.set({ isRunning: true });
taskNum++;
if (taskInterval) return;
chrome.storage.local.set({ isRunning: true });
taskInterval = setInterval(() => {
// 推送更新
const ackLen = logs.filter(x => x.message.includes("完成")).length;
chrome.runtime.sendMessage({ type: 'progress', logs });
if (ackLen === taskNum) {
clearInterval(taskInterval);
// recycle
taskInterval = null, taskNum = 0;
logs.push({
time: new Date().toLocaleTimeString(),
message: "已全部完成"
});
chrome.runtime.sendMessage({ type: 'progress', logs });
// copy logs
chrome.storage.local.set({ isRunning: false, logs });
clearInterval(taskInterval);
// recycle
taskInterval = null, taskNum = 0, logs = [];
}
chrome.runtime.sendMessage({
type: 'progress', logs
});
}, 1000);
}
// eslint-disable-next-line no-unused-vars
const initTimedTask = () => {
for (const [key, { uri, params }] of Object.entries(TABLE)) {
const plan = new Plan(null, params);
......@@ -133,8 +130,11 @@ chrome.alarms.onAlarm.addListener((alarm) => {
sendTabMsg({ type: "run", data: { uri, period } });
});
// 初始化
initTimedTask();
// chrome.alarms.clearAll();
// initTimedTask();
// chrome.storage.local.get(null, console.log);
// chrome.storage.local.clear();
// chrome.alarms.getAll(console.log);
chrome.alarms.clearAll();
// eslint-disable-next-line no-unused-vars
const getTmpClock = () => {
......
import { sleep, getValue, fmt0, fmt2, fmt3, JSON2CSV, createZip, renameZipFile } from "./util.js";
import { rrHeaders, headers, gHeaders } from "./header.js";
import { rrHeaders, headers } from "./header.js";
import { TABLE } from "./conf.js";
const DELAY = 2000; // 2s
......@@ -43,6 +43,8 @@ class Task {
if (!(this.uri && this.scid)) {
throw new Error(`uri: ${this.uri}, scid: ${this.scid}`);
}
this._retryLimit = 5
this._retryCount = 0
}
getFileName(sf) {
const ext = this.options.ext || 'csv';
......@@ -70,6 +72,19 @@ class Task {
...this.options.requestInit
});
console.log(response);
if (response.status !== 200) {
if (++this._retryCount < this._retryLimit) {
await sleep(DELAY);
const text = await response.text();
console.log(`重试请求, ${text}`);
return await this.send(...arguments);
} else {
console.error(`重试失败: ${response.url}`);
return false;
}
}
this._retryCount = 0; // reset
let blob;
if (callback) {
blob = await callback.call(this, response);
......@@ -441,7 +456,7 @@ export async function createTasks(uri, period) {
}, {
fromDate,
toDate,
}, { headers: gHeaders }),
}),
new Task({
apiName: "poAudit",
showName: "Inbound receipts"
......
......@@ -21,10 +21,6 @@ export const rHeaders = Object.freeze({
"accept": "application/json",
"wm_aurora.market": "US",
});
export const gHeaders = Object.freeze({
"Accept-Encoding": "gzip, deflate, br",
"wm_aurora.market": "US",
});
export const headers = Object.freeze({
"wm_aurora.market": "US",
});
loguru
aiofiles
bs4
curl_cffi
fake_useragent
tenacity
oss2
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