Schedule pickers, and target progress at one row
"Check feeds every" becomes a number plus a unit dropdown in both global and per-feed settings; parse_interval gained weeks to back it. The per-feed dropdown can select the global default, clearing the override. Fixes progress painting every pending row: the event carried no enclosure id, so the handler had nothing to target and set the width on all of them. Adding a feed looked like it was downloading everything. Progress, DownloadDone and DownloadError now carry the enclosure id. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AdXho5tTkjFLeUXKbEjKBh
This commit is contained in:
@@ -168,7 +168,8 @@ input:focus,select:focus{outline:0;border-color:var(--accent)}
|
||||
}
|
||||
.notes img{max-width:100%;height:auto;border-radius:6px}
|
||||
.notes p:first-child{margin-top:0}.notes p:last-child{margin-bottom:0}
|
||||
.dlbar{height:3px;background:var(--raise);border-radius:2px;overflow:hidden;margin-top:7px}
|
||||
.dlbar{height:3px;background:transparent;border-radius:2px;overflow:hidden;margin-top:7px}
|
||||
.dlbar.live{background:var(--raise)}
|
||||
.dlbar i{display:block;height:100%;width:0;background:var(--accent);transition:width .25s}
|
||||
.empty{color:var(--faint);text-align:center;padding:50px 0}
|
||||
#more{display:block;width:100%;margin-top:10px}
|
||||
@@ -224,6 +225,8 @@ input[type=range]::-moz-range-thumb{width:12px;height:12px;border:0;border-radiu
|
||||
.inline{display:flex;gap:6px;align-items:stretch}
|
||||
.inline input{flex:1;min-width:0}
|
||||
.inline .btn{white-space:nowrap;flex:none}
|
||||
.inline select{flex:none;width:auto}
|
||||
.inline input[type=number]{flex:none;width:90px}
|
||||
.check input{width:16px;height:16px;accent-color:var(--accent)}
|
||||
.cardacts{display:flex;gap:8px;justify-content:flex-end;margin-top:16px}
|
||||
#toasts{position:fixed;bottom:88px;right:18px;display:flex;flex-direction:column;gap:8px;z-index:60}
|
||||
@@ -671,11 +674,26 @@ $('#addFeed').onclick=()=>{
|
||||
};
|
||||
|
||||
let globalEvery = 60;
|
||||
const UNITS = [['m','minutes'],['h','hours'],['d','days'],['w','weeks']];
|
||||
const UNIT_MINS = {m:1, h:60, d:1440, w:10080};
|
||||
|
||||
/// Largest unit that divides evenly, so 120 reads "2 hours" not "120 minutes".
|
||||
function splitEvery(m){
|
||||
if(!m) return {n:1, u:'h'};
|
||||
for(const u of ['w','d','h']) if(m % UNIT_MINS[u] === 0) return {n:m/UNIT_MINS[u], u};
|
||||
return {n:m, u:'m'};
|
||||
}
|
||||
function unitOptions(sel, firstLabel){
|
||||
const head = firstLabel
|
||||
? `<option value=""${sel===''?' selected':''}>${firstLabel}</option>` : '';
|
||||
return head + UNITS.map(([v,l]) =>
|
||||
`<option value="${v}"${sel===v?' selected':''}>${l}</option>`).join('');
|
||||
}
|
||||
function everyText(m){
|
||||
if(!m) return '\u2014';
|
||||
if(m % 1440 === 0) return (m/1440)+(m===1440?' day':' days');
|
||||
if(m % 60 === 0) return (m/60)+(m===60?' hour':' hours');
|
||||
return m+' min';
|
||||
const {n,u} = splitEvery(m);
|
||||
const name = {m:'min', h:'hour', d:'day', w:'week'}[u];
|
||||
return n + ' ' + name + (u!=='m' && n!==1 ? 's' : '');
|
||||
}
|
||||
function due(ts){
|
||||
const d = ts - Date.now()/1000;
|
||||
@@ -688,12 +706,15 @@ function due(ts){
|
||||
async function prefsModal(){
|
||||
const g = await api('/api/settings');
|
||||
globalEvery = g.every_mins;
|
||||
const gs = splitEvery(g.every_mins);
|
||||
openModal(`<h3>Settings</h3>
|
||||
<div class="field"><label>Check feeds</label>
|
||||
<input type="text" id="gsched" value="${esc(g.schedule)}">
|
||||
<span class="hint">How often every feed is re-checked unless it overrides this.
|
||||
Try <b>every 30m</b>, <b>every 4h</b>, <b>1d</b>. A feed's own suggested interval
|
||||
(its <b>ttl</b>) is honoured when it asks to be polled less often than this.</span></div>
|
||||
<div class="field"><label>Check feeds every</label>
|
||||
<div class="inline">
|
||||
<input type="number" id="gnum" min="1" max="999" value="${gs.n}">
|
||||
<select id="gunit">${unitOptions(gs.u)}</select>
|
||||
</div>
|
||||
<span class="hint">Applies to every feed that does not set its own. A feed's suggested
|
||||
interval (its <b>ttl</b>) is still honoured when it asks to be polled less often.</span></div>
|
||||
<div class="field"><label>Disk quota (GB, 0 = unlimited)</label>
|
||||
<input type="number" id="gquota" min="0" step="0.5" value="${g.max_total_gb}">
|
||||
<span class="hint">Over this, the oldest played episodes are deleted first. Starred
|
||||
@@ -707,7 +728,7 @@ async function prefsModal(){
|
||||
$('#gsave').onclick=async()=>{
|
||||
try{
|
||||
await api('/api/settings',{method:'PATCH',body:JSON.stringify({
|
||||
schedule:$('#gsched').value.trim(),
|
||||
schedule:`every ${Math.max(1,Number($('#gnum').value)||1)}${$('#gunit').value}`,
|
||||
max_total_gb:Number($('#gquota').value)||0,
|
||||
max_age_days:Number($('#gage').value)||0})});
|
||||
closeModal(); toast('Settings saved');
|
||||
@@ -717,6 +738,7 @@ async function prefsModal(){
|
||||
}
|
||||
|
||||
function settingsModal(f){
|
||||
const fs = splitEvery(f.schedule_mins || globalEvery);
|
||||
openModal(`<h3>${esc(f.title||f.id)}</h3>
|
||||
<div class="field"><label>Download folder</label>
|
||||
<input type="text" id="sfolder" value="${esc(f.folder||'')}" placeholder="${esc(f.title||f.id)}"></div>
|
||||
@@ -724,9 +746,12 @@ function settingsModal(f){
|
||||
<input type="text" id="skw" value="${esc(f.keywords.join(', '))}">
|
||||
<span class="hint">Comma separated. Empty takes everything.</span></div>
|
||||
<div class="field"><label>Check schedule</label>
|
||||
<input type="text" id="ssched" value="${esc(f.schedule||'')}" placeholder="default — every ${everyText(globalEvery)}">
|
||||
<span class="hint">e.g. <b>every 30m</b>, <b>every 6h</b>, <b>2d</b>. Empty follows the global
|
||||
schedule. Setting one here overrides the feed's own suggested interval.</span></div>
|
||||
<div class="inline">
|
||||
<input type="number" id="snum" min="1" max="999" value="${fs.n}" ${f.schedule_mins?'':'disabled'}>
|
||||
<select id="sunit">${unitOptions(f.schedule_mins?fs.u:'', `Use the default — every ${everyText(globalEvery)}`)}</select>
|
||||
</div>
|
||||
<span class="hint">Overrides the global schedule, and the feed's own suggested
|
||||
interval, for this feed only.</span></div>
|
||||
<div class="field"><label>Max new downloads per scan</label>
|
||||
<input type="number" id="smax" min="0" value="${f.max_new_per_check??''}">
|
||||
<span class="hint">Blank means no limit. The rest wait for the next scan.</span></div>
|
||||
@@ -742,13 +767,16 @@ function settingsModal(f){
|
||||
<div class="cardacts"><button class="btn" onclick="closeModal()">Cancel</button>
|
||||
<button class="btn primary" id="ssave">Save</button></div>`);
|
||||
$('#scopy').onclick=()=>copyText($('#surl').value,$('#scopy'));
|
||||
// An empty unit means "follow the global default", so the number has nothing to say.
|
||||
$('#sunit').onchange=()=>{ $('#snum').disabled = !$('#sunit').value; };
|
||||
$('#ssave').onclick=async()=>{
|
||||
const max=$('#smax').value;
|
||||
try{
|
||||
await api(`/api/feeds/${encodeURIComponent(f.id)}`,{method:'PATCH',body:JSON.stringify({
|
||||
url:$('#surl').value.trim(),
|
||||
folder:$('#sfolder').value.trim()||null,
|
||||
schedule:$('#ssched').value.trim()||null,
|
||||
schedule:$('#sunit').value
|
||||
? `every ${Math.max(1,Number($('#snum').value)||1)}${$('#sunit').value}` : null,
|
||||
keywords:$('#skw').value.split(',').map(s=>s.trim()).filter(Boolean),
|
||||
max_new_per_check:max===''?null:Number(max),
|
||||
auto_download:$('#sauto').checked, allow_explicit:$('#sexp').checked})});
|
||||
@@ -830,13 +858,22 @@ function connect(){
|
||||
let ev; try{ ev=JSON.parse(m.data) }catch{ return }
|
||||
if(ev.ev==='progress'){
|
||||
const pct=ev.total?ev.done/ev.total*100:0;
|
||||
$$('.dlbar').forEach(b=>{ /* progress applies to whatever is downloading now */
|
||||
if(b.dataset.bar) b.firstElementChild.style.width=pct+'%';
|
||||
});
|
||||
// Only the row actually downloading. Without the enclosure id this used to paint
|
||||
// every pending bar at once, so adding a feed looked like it was fetching the lot.
|
||||
const bar=document.querySelector(`.dlbar[data-bar="${ev.enclosure}"] i`);
|
||||
if(bar){ bar.style.width=pct+'%'; bar.parentElement.classList.add('live'); }
|
||||
$('#count') && ($('#count').textContent=`downloading ${ev.file} — ${pct.toFixed(0)}%`);
|
||||
}
|
||||
else if(ev.ev==='download_done'){ toast('Downloaded '+ev.path.split('/').pop()); loadEntries(); loadFeeds(true); }
|
||||
else if(ev.ev==='download_error'){ toast('Download failed: '+ev.msg,true); loadEntries(); }
|
||||
else if(ev.ev==='download_done'){
|
||||
const bar=document.querySelector(`.dlbar[data-bar="${ev.enclosure}"]`);
|
||||
if(bar) bar.classList.remove('live');
|
||||
toast('Downloaded '+ev.path.split('/').pop()); loadEntries(); loadFeeds(true);
|
||||
}
|
||||
else if(ev.ev==='download_error'){
|
||||
const bar=document.querySelector(`.dlbar[data-bar="${ev.enclosure}"]`);
|
||||
if(bar) bar.classList.remove('live');
|
||||
toast('Download failed: '+ev.msg,true); loadEntries();
|
||||
}
|
||||
else if(ev.ev==='feed_done'){ if(ev.new) toast(`${ev.feed}: ${ev.new} new`); loadFeeds(true); if(ev.feed===S.feed) loadEntries(); }
|
||||
else if(ev.ev==='feed_error'){ toast(ev.feed+': '+ev.msg,true); loadFeeds(true); }
|
||||
else if(ev.ev==='scan_done'){ loadFeeds(true); if(S.feed) loadEntries(); }
|
||||
|
||||
Reference in New Issue
Block a user