update: now able to recover from mismatched subject errors

This commit is contained in:
2025-08-29 01:21:21 +08:00
parent 9994ca8e21
commit 29e953673d
2 changed files with 78 additions and 32 deletions

View File

@@ -100,18 +100,21 @@
</div>
</div>
<br>
<label for="slice" class="pure-checkbox">
<input id="slice" type="checkbox"/> Enable task slicing
</label>
<label for="greet" class="pure-checkbox">
<input id="greet" type="checkbox"/> Greet recipients (by proper names if possible)
</label>
<label for="save" class="pure-checkbox">
<input id="save" type="checkbox" checked/> Save to file upon exit
<label for="recovery" class="pure-checkbox">
<input id="recovery" type="checkbox"/> Try recover from a mismatched subject error
</label>
<label for="slice" class="pure-checkbox">
<input id="slice" type="checkbox"/> Enable task slicing
</label>
<label for="nospam" class="pure-checkbox">
<input id="nospam" type="checkbox"/> Avoid spamming
</label>
<label for="save" class="pure-checkbox">
<input id="save" type="checkbox" checked/> Save to file upon exit
</label>
</fieldset>
<br>
<fieldset>
@@ -249,8 +252,18 @@ $$$('#send', 'click', async (e) => {
break;
default:
try {
let PickerOptions = {
types: [
{
description: "Excel Spreadsheet",
accept: {
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ['.xlsx']
}
}
]
};
$('#send > span.icon').classList.remove('hidden');
let [handle] = await showOpenFilePicker();
let [handle] = await showOpenFilePicker(PickerOptions);
let file = await handle.getFile();
let buffer = await new Promise((resolve, reject) => {
@@ -265,7 +278,7 @@ $$$('#send', 'click', async (e) => {
Status = 'READY';
$('#fileLabel').innerHTML = file.name;
$('#uptimeLabel').dataset.timestamp = dayjs().unix();
$('#uptimeLabel').dataset.seconds = 0;
$('#send > span.text').innerHTML = 'Send';
$('#cancel').disabled = false;
$('#send').disabled = true;
@@ -420,10 +433,13 @@ function main(url, parameters, locales) {
$('#cancel').disabled = false;
break;
case 'setProgress':
let [sent, name, recipient] = args;
let [index, name, recipient, sent, warnings, errors] = args;
let label = name ? `${name} <${recipient}>` : recipient;
$('#recipientLabel').innerHTML = label;
$('#progressLabel').dataset.sent = sent;
$('#progressLabel').dataset.index = index;
$('#progressLabel').dataset.errors = errors;
$('#progressLabel').dataset.warnings = warnings;
break;
case 'setStatus':
switch (args[0]) {
@@ -443,7 +459,8 @@ function main(url, parameters, locales) {
$('#send > span.icon').classList.add('hidden');
break;
case 'FINISH':
alert('任务结束')
let {sent, warnings, errors} = $('#progressLabel').dataset;
alert(`${sent||0} Sent; ${warnings||0} Warning(s); ${errors||0} Error(s)`);
case 'CANCEL':
Status = null;
$('#send > span.text').innerHTML = 'Open';
@@ -488,21 +505,19 @@ function main(url, parameters, locales) {
$('#statusLabel').innerHTML = Status ? Status.charAt(0).toUpperCase() + Status.slice(1).toLowerCase() : 'Idle';
if (Status === 'RUNNING') {
let sent = Number($('#progressLabel').dataset.sent) || 0;
let index = Number($('#progressLabel').dataset.index) || 0;
let limit = Number($('#subcategory').dataset.limit) || Limit;
let percentage = parseFloat((sent / limit * 100).toFixed(2));
$('#progressLabel').innerHTML = `${sent} / ${limit} (${percentage} %)`;
let timestamp = Number($('#uptimeLabel').dataset.timestamp);
let uptime = dayjs.duration(dayjs().diff(dayjs.unix(timestamp)));
let rate = sent / uptime.asSeconds();
let percentage = parseFloat((index / limit * 100).toFixed(2));
$('#progressLabel').innerHTML = `${index} / ${limit} (${percentage} %)`;
let uptime = dayjs.duration($('#uptimeLabel').dataset.seconds, 'second');
let rate = Number($('#progressLabel').dataset.sent) / uptime.asSeconds();
let spm = parseFloat(Number(rate*60).toFixed(2));
let speed = spm >= 1 ? `${spm} per minute` : null;
let remaining = rate > 0 ? dayjs.duration((limit - sent) / rate, 'second').humanize() : null;
$('#remainingLabel').innerHTML = [remaining, speed].filter((x) => x).join(' - ');
$('#remainingLabel').innerHTML = rate > 0 ? `<span>${dayjs.duration((limit - index) / rate, 'second').humanize()}</span>` : '';
$('#remainingLabel').innerHTML += spm >= 1 ? `<span class="${spm > 8.33 ? 'rate warning' : 'rate'}">${spm} per minute</span>` : '';
$('#uptimeLabel').innerHTML = uptime.format("HH:mm:ss");
$('#uptimeLabel').dataset.seconds = uptime.asSeconds() + 1;
}
}, 1000);
}
@@ -525,6 +540,12 @@ label {
width: fit-content;
}
.rate:not(:first-child)::before {
padding: 0em 0.4em;
content: '';
color: #666;
}
.inline-flex {
display: inline-flex;
align-items: center;
@@ -536,6 +557,10 @@ label {
white-space: nowrap;
}
.warning {
color: orangered;
}
.hidden {
display: none;
}