feat: add audited work records and controlled digest retries
Build and publish container images / images (push) Successful in 12m27s
Build and publish container images / images (push) Successful in 12m27s
This commit is contained in:
1 parent
6e0aecdfb3
commit
e65ca56f92
33 files changed
+2262
-114
No files matched your search
@@ -0,0 +1,54 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const root=document.getElementById('task-digest-history');if(!root)return;
|
||||
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
|
||||
const api='/_/api/v1/extension/organizer.tasks/digest-history';
|
||||
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
||||
const states={queued:t('Queued','待機中'),sending:t('Sending / pending result','送信中・結果待ち'),sent:t('Accepted by mail server','メールサーバー受付済み'),uncertain:t('Delivery uncertain','結果不明'),cancelled:t('Not sent','送信中止')};
|
||||
const reasons={legacy:t('Migrated record; attempt details unknown','移行前の記録(詳細不明)'),smtp_unavailable:t('SMTP unavailable','SMTPを利用できません'),tasks_unavailable:t('Tasks unavailable','タスクを取得できません'),consent_changed:t('Settings or permission changed','設定・権限が変わりました'),transport_uncertain:t('SMTP result uncertain','SMTPの結果が不明です'),extension_disabled:t('Extension disabled','拡張機能が無効です'),day_expired:t('Requested date has passed','対象日を過ぎました'),worker_interrupted:t('Worker interrupted; check for delivery','処理中断の可能性・受信を確認してください')};
|
||||
const details=el('details'),summary=el('summary',t('Email delivery history and retry','メール配信履歴・再送'));details.append(summary);root.append(details);
|
||||
const status=el('p');status.role='status';status.setAttribute('aria-live','polite');
|
||||
const controls=el('div'),refresh=el('button','↻ '+t('Refresh','更新'));refresh.type='button';controls.className='productivity-controls';controls.append(refresh);
|
||||
const content=el('div'),pager=el('div');pager.className='productivity-controls';details.append(status,controls,content,pager);
|
||||
let loaded=false,busy=false,cursor='',stack=[],pending=null,generation=0;
|
||||
async function request(suffix='',options={}){
|
||||
const response=await fetch(api+suffix,{credentials:'same-origin',cache:'no-store',signal:AbortSignal.timeout(15000),...options,headers:{'Content-Type':'application/json'}});
|
||||
const data=await response.json().catch(()=>({}));
|
||||
if(!response.ok||response.redirected){const errors={conflict:t('Changed, already queued, or the daily retry limit was reached. Refresh to check.','状態の変更・処理中・再送回数上限のいずれかです。更新して確認してください。'),invalid:t('Check the date and duplicate-delivery confirmation.','対象日と重複送信の確認を見直してください。'),forbidden:t('Enable delivery and check your permissions.','配信設定と権限を確認してください。'),email_required:t('Set your account email first.','先にプロフィールのメールアドレスを設定してください。'),smtp_unavailable:t('SMTP is not configured or enabled.','SMTPが未設定または無効です。')};const error=Error(errors[data.error]||t('Unable to confirm the result. Retry uses the same request.','結果を確認できません。同じ要求で再試行できます。'));error.status=response.status;throw error;}
|
||||
return data;
|
||||
}
|
||||
function retryForm(data){
|
||||
const box=el('div');box.className='digest-retry';const current=data.current;
|
||||
box.append(el('p',t('Retries use current tasks and your current account email, not the original message. Saved settings apply. Up to 5 retries per day.','再送は元の本文ではなく、現在のタスクとアカウントのメールアドレスを使います。保存済み設定に従い、1日5回までです。')));
|
||||
if(pending&¤t?.uuid===pending.request_id){pending=null;status.textContent=t('Request is recorded. Check its status below.','要求は記録されています。以下の状態を確認してください。');}
|
||||
if(root.dataset.writable!=='true')return box;
|
||||
if(!pending&&(!data.enabled||!current||['queued','sending'].includes(current.state)||data.retries>=5)){
|
||||
box.append(el('p',!data.enabled?t('Enable daily email in the settings above.','上の設定で日次メールを有効にしてください。'):!current?t('No delivery attempt for today yet.','本日の配信記録はまだありません。'):data.retries>=5?t('Daily retry limit reached.','本日の再送回数上限に達しました。'):t('Request is queued or running. Refresh later.','待機中または実行中です。しばらくして更新してください。')));return box;
|
||||
}
|
||||
const form=el('form'),ack=el('input'),label=el('label');ack.type='checkbox';ack.checked=!!pending?.duplicate_acknowledged;
|
||||
const duplicate=pending?pending.duplicate_acknowledged:['sent','uncertain'].includes(current.state);
|
||||
ack.required=duplicate;label.append(ack,document.createTextNode(t('I checked my inbox and accept possible duplicate delivery.','受信状況を確認し、重複して届く可能性を了承します。')));if(duplicate)form.append(label);
|
||||
const send=el('button',pending?t('Retry the same request','同じ要求で再試行'):t('Queue today’s email again','本日分の再送を予約'));send.type='submit';form.append(send);box.append(form);
|
||||
form.onsubmit=async event=>{event.preventDefault();if(busy||!form.reportValidity())return;
|
||||
if(!pending)pending={request_id:crypto.randomUUID(),day:current.day,expected_attempt:current.uuid,duplicate_acknowledged:duplicate&&ack.checked};
|
||||
busy=true;send.disabled=refresh.disabled=ack.disabled=true;pager.inert=true;
|
||||
try{await request('/retry',{method:'POST',body:JSON.stringify(pending)});pending=null;cursor='';stack=[];const refreshed=await load();if(refreshed)status.textContent=t('Queued. The scheduler will process this request; queue delays may apply.','予約しました。スケジューラが処理するまでお待ちください。');else status.textContent=t('Request accepted. ','予約済みです。')+status.textContent;}
|
||||
catch(error){if(error.status>=400&&error.status<500)pending=null;status.textContent=error.message;send.textContent=pending?t('Retry the same request','同じ要求で再試行'):t('Queue today’s email again','本日分の再送を予約');}
|
||||
finally{busy=false;send.disabled=refresh.disabled=ack.disabled=false;pager.inert=false;}
|
||||
};return box;
|
||||
}
|
||||
async function load(){
|
||||
const ticket=++generation;refresh.disabled=true;content.inert=true;pager.inert=true;
|
||||
try{const data=await request('?'+new URLSearchParams({limit:'25',...(cursor?{after:cursor}:{})}));if(ticket!==generation)return;
|
||||
const table=el('table');table.className='productivity-table';const head=el('tr');for(const title of [t('Date','対象日'),t('Method','区分'),t('Status','状態'),t('Updated','更新'),t('Detail','詳細')])head.append(el('th',title));const thead=el('thead');thead.append(head);table.append(thead);const body=el('tbody');
|
||||
for(const item of data.items){const row=el('tr');const date=new Date(item.updated_ms).toLocaleString(ja?'ja-JP':'en-GB',{timeZone:item.timezone||undefined});for(const value of [item.day,item.kind==='manual'?t('Manual','手動'):item.kind==='legacy'?t('Legacy','移行前'):t('Scheduled','定期'),states[item.state]||item.state,date+(item.timezone?' · '+item.timezone:''),reasons[item.reason]||''])row.append(el('td',value));body.append(row);}table.append(body);
|
||||
const wrap=el('div');wrap.className='productivity-table-wrap';wrap.append(table);if(!data.items.length)wrap.append(el('p',t('No delivery history.','配信履歴はありません。')));
|
||||
status.textContent='';content.replaceChildren(retryForm(data),wrap,el('p',t('Detailed attempts: '+data.retention_days+' days. Duplicate-prevention receipts are retained. An accepted message is not a guarantee of inbox delivery.','詳細履歴は'+data.retention_days+'日保持します。重複防止記録は残します。メールサーバーの受付は受信箱への到達保証ではありません。')));
|
||||
pager.replaceChildren();const button=(title,fn)=>{const b=el('button',title);b.type='button';b.onclick=fn;pager.append(b);};
|
||||
if(stack.length)button(t('Previous','前へ'),()=>{if(!busy){cursor=stack.pop();load();}});
|
||||
if(data.next)button(t('Next','次へ'),()=>{if(!busy){stack.push(cursor);cursor=data.next;load();}});loaded=true;return true;
|
||||
}catch(error){status.textContent=error.message;}finally{if(ticket===generation){refresh.disabled=false;content.inert=false;pager.inert=false;}}
|
||||
}
|
||||
refresh.onclick=()=>{if(!busy){cursor='';stack=[];load();}};
|
||||
details.ontoggle=()=>{if(details.open&&!loaded)load();};
|
||||
})();
|
||||
Reference in new issue
Block a user