D1, seconda parte: «Cosa scaricare prima» anche per account, reel distinti e quota per chi aspetta

L'ordine dei tipi (storie, evidenza, post, reel, taggati) ora vale anche per il singolo account:
nella scheda account → Impostazioni si sceglie «Come le impostazioni generali» o un ordine suo,
con lo stesso elenco da trascinare (o Su/Giù da tastiera) di Limiti e comportamento, ora un
modulo solo (download-order.js). Il motore pesa le visite con l'ordine dell'account, la coda dei
file mette ogni file al posto del suo tipo nell'ordine del suo account, stabile dentro il tipo
(scadenza, scoperta, elemento, posizione).

Perché nessun tipo resti fermo per sempre quando il tetto dei dati finisce prima della coda, un
posto su otto di ogni giro della coda va al file che aspetta da più tempo, di qualunque tipo.

I reel non si inventano (regola 9): un post è reel se viene dalla scheda Reel o se la risposta
ha product_type «clips», valore visto nei campioni ripuliti. Il segno si scrive da solo e non si
toglie mai, così una copia vecchia non sposta di nuovo i file in coda.

Migrazione 0002_ordine_scaricamento (account.download_order, entry.is_reel): prende il primo
numero dopo quelle unite, E1 userà il successivo. Prove su motore (seme fisso), coda, lettori,
ricette e API; dimostrazione con un account che ha l'ordine suo; guida e decisioni aggiornate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 15:25:34 +01:00
1 parent d6c0ef851d
commit 0547c747c5
40 files changed
+775 -158

No files matched your search

+3 -1
View File
@@ -38,7 +38,8 @@ public static class AccountSettingsMapper
account.Limits.BackfillPostsPerDay,
account.Limits.MaxVideoBytes is { } bytes ? Math.Round(bytes / 1024d / 1024d, 1) : null,
account.Limits.StoryVideos,
account.Folder);
account.Folder,
account.DownloadOrder is { } own ? DownloadOrder.Parse(own).ToNames() : null);
}
/// <summary>
@@ -144,6 +145,7 @@ public static class AccountSettingsMapper
StoryVideos = dto.StoryVideos,
},
Folder = folder,
DownloadOrder = dto.DownloadOrder is { Count: > 0 } names ? DownloadOrder.From(names).ToString() : null,
State = state,
StateChangedAt = changedAt,
};
+2 -1
View File
@@ -310,7 +310,8 @@ public static class AccountsApi
account.Folder is null,
account.State == AccountState.ArchiveOnly && account.InstagramId is null && account.IsMine is false ? null : InstagramLinks.Profile(account.Username),
highlights,
AccountSettingsMapper.MaxBackfillPerDay);
AccountSettingsMapper.MaxBackfillPerDay,
(await DownloadOrder.LoadAsync(storage.Settings, ct).ConfigureAwait(false)).ToNames());
}
/// <summary>«Con queste impostazioni», recomputed at every change of the form (spec §4.4).</summary>
+8 -3
View File
@@ -151,7 +151,10 @@ public sealed record AccountListDto(long Now, AccountCountsDto Counts, IReadOnly
public sealed record AccountStatsDto(int Entries, int Posts, int Stories, int HighlightItems, int Tagged, int ProfilePictures, int Collections, long Bytes, int PendingFiles);
/// <summary>The editable settings of an account (mockup 05).</summary>
/// <summary>
/// The editable settings of an account (mockup 05). <see cref="DownloadOrder"/> is «Cosa scaricare prima» (spec §4.4):
/// the names of the five kinds first to last for «Un ordine suo», null or empty for «Come le impostazioni generali».
/// </summary>
public sealed record AccountSettingsDto(
bool KeepUpdated,
string Frequency,
@@ -164,7 +167,8 @@ public sealed record AccountSettingsDto(
int BackfillPerDay,
double? MaxVideoMb,
bool StoryVideos,
string? Folder);
string? Folder,
IReadOnlyList<string>? DownloadOrder = null);
public sealed record PlanLineDto(string Key, string Title, string Text);
@@ -190,7 +194,8 @@ public sealed record AccountDetailDto(
bool FolderIsDefault,
string? InstagramUrl,
IReadOnlyList<HighlightDto> Highlights,
int MaxBackfillPerDay);
int MaxBackfillPerDay,
IReadOnlyList<string>? GeneralDownloadOrder = null);
public sealed record HistoryItemDto(long Id, LocalTimeDto At, string Severity, string Code, string Message);
+8 -1
View File
@@ -119,7 +119,7 @@ public static class DemoSeeder
new("tuo.profilo", "Il tuo profilo", false, false, AccountState.UpToDate, 420, 980, 140, 5, 402, 4, [DemoSubject.Hills, DemoSubject.Sea, DemoSubject.Food, DemoSubject.Portrait, DemoSubject.Room, DemoSubject.Sunset, DemoSubject.CityNight]) { Mine = true },
new("marta.demo", "Marta B.", true, true, AccountState.UpToDate, 810, 312, 92, 6, 40, 4, [DemoSubject.Portrait, DemoSubject.Flowers, DemoSubject.Food, DemoSubject.Room, DemoSubject.Sunset, DemoSubject.CityNight, DemoSubject.Sea, DemoSubject.Houses, DemoSubject.Hills]) { Imported = 30, Tagging = true },
new("studio.lumen.demo", "Studio Lumen", false, false, AccountState.Backfilling, 340, 8, 4, 4, 0, 3, [DemoSubject.Room, DemoSubject.Portrait, DemoSubject.Bokeh, DemoSubject.Leaves]) { PostCount = 1280, BackfillToday = 300 },
new("luca.viaggi.demo", "Luca in viaggio", false, true, AccountState.UpToDate, 1900, 1000, 208, 8, 0, 4, [DemoSubject.Mountains, DemoSubject.Sea, DemoSubject.Road, DemoSubject.Hills, DemoSubject.Houses, DemoSubject.Sunset]) { Types = ContentTypes.PostPhotos | ContentTypes.PostVideos | ContentTypes.Stories, ProfilePictures = 2 },
new("luca.viaggi.demo", "Luca in viaggio", false, true, AccountState.UpToDate, 1900, 1000, 208, 8, 0, 4, [DemoSubject.Mountains, DemoSubject.Sea, DemoSubject.Road, DemoSubject.Hills, DemoSubject.Houses, DemoSubject.Sunset]) { Types = ContentTypes.PostPhotos | ContentTypes.PostVideos | ContentTypes.Stories, ProfilePictures = 2, DownloadOrder = "post,reel,storie,evidenza,taggati" },
new("nonna.pina.demo", "Pina", true, true, AccountState.UpToDate, 150, 50, 14, 2, 0, 3, [DemoSubject.Food, DemoSubject.Flowers, DemoSubject.Room, DemoSubject.Portrait]) { Types = ContentTypes.PostPhotos | ContentTypes.Stories | ContentTypes.Highlights },
new("circolo.foto.demo", "Circolo fotografico", false, true, AccountState.Backfilling, 2060, 0, 11, 3, 0, 4, [DemoSubject.Mountains, DemoSubject.CityNight, DemoSubject.Sea, DemoSubject.Hills, DemoSubject.Bokeh, DemoSubject.Houses, DemoSubject.Road]) { PostCount = 2410, BackfillToday = 150, Types = ContentTypes.PostPhotos | ContentTypes.PostVideos | ContentTypes.Highlights | ContentTypes.Tagged | ContentTypes.ProfilePicture },
new("giulia.corre.demo", "Giulia", false, true, AccountState.UpToDate, 600, 230, 46, 3, 0, 3, [DemoSubject.Road, DemoSubject.Hills, DemoSubject.Mountains, DemoSubject.Portrait, DemoSubject.Sea]) { ProfilePictures = 3, Types = ContentTypes.PostPhotos | ContentTypes.PostVideos | ContentTypes.Stories | ContentTypes.Highlights },
@@ -362,6 +362,9 @@ public static class DemoSeeder
ExpiresAt = item.Kind == EntryKind.Story ? item.Published + TimeSpan.FromHours(24) : null,
};
var media = Media(item, entry, spec, account, folder, collectionTitle, layout, zone, pool, random);
// A downloaded post with a single video is shown as a reel (spec §7.2: Febe knows it from the Reel tab).
entry = entry with { IsReel = item.Kind == EntryKind.Post && !item.Imported && media.Count == 1 && media[0].Kind == MediaKind.Video };
pending.Add(new NewEntry(entry, media));
created.Add((account.Id, item.Kind, item.Discovered, media.Sum(m => m.Bytes ?? 0), media.Count, item.Backfill));
entriesCount += item.Kind == EntryKind.ProfilePicture ? 0 : 1;
@@ -641,6 +644,9 @@ public static class DemoSeeder
public ContentTypes? Types { get; init; }
public Frequency Frequency { get; init; } = Frequency.Normal;
/// <summary>«Cosa scaricare prima» of its own (spec §4.4); null: «Come le impostazioni generali».</summary>
public string? DownloadOrder { get; init; }
}
private static ContentTypes DefaultTypes(AccountSpec spec) =>
@@ -674,6 +680,7 @@ public static class DemoSeeder
ContentTypes = spec.State == AccountState.ArchiveOnly ? ContentTypes.None : spec.Types ?? DefaultTypes(spec),
PostCount = spec.PostCount ?? (spec.State == AccountState.ArchiveOnly ? null : spec.Posts),
BackfillCompletedAt = spec.State == AccountState.Backfilling || spec.State == AccountState.ArchiveOnly ? null : added + TimeSpan.FromDays(4),
DownloadOrder = spec.DownloadOrder,
AddedAt = added,
};
}
+2
View File
@@ -696,6 +696,8 @@ a.stato:hover{border-color:var(--bordo-forte)}
.riga-ordine .posizione{width:16px;color:var(--testo-2)}
.riga-ordine .destra{margin-left:auto;display:flex;gap:4px}
.riga-sotto{display:flex;align-items:center;gap:12px;margin-top:8px}
.riga-ordine.spenta b,.riga-ordine.spenta .posizione{color:var(--testo-3)}
.ordine-account{margin-top:10px}
@media (max-width:1000px){
.cruscotto{flex-direction:column}
.cruscotto .anteprima{width:100%}
+33
View File
@@ -13,6 +13,7 @@ import { avatar, checkbox, confirmDialog, menu, segmented, showError, toast, tog
import { accountLabels, accountMenu, checkNow, openProfile } from './accounts.js';
import { confirmDelete } from './library.js';
import { Mosaic, justify, tileElement, defaultDayLabel } from './mosaic.js';
import { kindName, orderEditor, orderOrDefault } from './download-order.js';
import { openViewer } from './viewer.js';
const KINDS = [
@@ -325,6 +326,7 @@ function settingsTab(page, detail) {
function changed() {
drawSaveBar();
recompute();
drawOrder();
}
// Tieni aggiornato.
@@ -361,6 +363,36 @@ function settingsTab(page, detail) {
return box;
}));
// Cosa scaricare prima (spec §4.4, §7.2): «Come le impostazioni generali» or an order of its own, which starts from the
// general one. The kinds switched off in «Cosa scaricare» stay in the list, attenuated.
const general = orderOrDefault(detail.generalDownloadOrder);
const KIND_TYPES = { storie: ['stories'], evidenza: ['highlights'], post: ['photos', 'videos'], reel: ['videos'], taggati: ['tagged'] };
const orderBox = h('div.ordine-account');
const order = orderEditor({
read: () => form.downloadOrder,
write: (next) => { form.downloadOrder = next; },
changed,
off: (kind) => !(KIND_TYPES[kind] || []).some((key) => form.types[key]),
label: t('impAccount.ordineScelta'),
});
const orderChoice = segmented({
label: t('impAccount.ordineScelta'),
value: Array.isArray(form.downloadOrder) && form.downloadOrder.length ? 'own' : 'general',
options: [{ value: 'general', label: t('impAccount.ordineGenerale') }, { value: 'own', label: t('impAccount.ordineSuo') }],
onchange: (v) => {
form.downloadOrder = v === 'own' ? [...general] : null;
changed();
},
});
function drawOrder() {
if (Array.isArray(form.downloadOrder) && form.downloadOrder.length) {
order.draw();
fill(orderBox, h('div.pannello', order.list), order.status);
} else {
fill(orderBox, h('p.nota', t('impAccount.ordineOra', { ordine: general.map(kindName).join(', ') })));
}
}
drawOrder();
// Limiti.
const depth = h('select', { id: 'profondita' }, ['all', 'lastPosts', 'fromDate'].map((d) => h('option', { value: d, selected: form.depth === d }, t(`impAccount.profondita.${d}`))));
const lastPosts = h('input', { type: 'number', min: '1', step: '1', value: form.lastPosts ?? 100, id: 'ultimi', inputmode: 'numeric' });
@@ -417,6 +449,7 @@ function settingsTab(page, detail) {
h('div.sezione', keep, h('p.aiuto', { style: { margin: '6px 0 0 46px' } }, t('impAccount.tieniAiuto'))),
h('div.sezione', h('h2.sez', t('impAccount.frequenza')), h('div.frequenza', frequency, frequencyNote), customFields),
h('div.sezione', h('h2.sez', t('impAccount.cosa')), h('p.aiuto', t('impAccount.cosaAiuto')), types),
h('div.sezione', h('h2.sez', t('impAccount.ordine')), h('p.aiuto', t('impAccount.ordineAiuto')), orderChoice, orderBox),
h('div.sezione', h('h2.sez', t('impAccount.limiti')), h('p.aiuto', t('impAccount.limitiAiuto')),
h('div.riga-campi',
h('div', h('label.etichetta', { for: 'profondita' }, t('impAccount.quanto')), h('label.campo.scelta', depth, icon('chevron-down', 's'))),
@@ -0,0 +1,100 @@
// «Cosa scaricare prima» (spec §7.2, §4.4, tappa D1): the list of the five kinds that moves by dragging (mouse) or with
// «Su» and «Giù» (keyboard), shared by Impostazioni → Limiti e comportamento and by the account card → Impostazioni.
// The page keeps the order and saves it with its save bar; this module only draws and moves the rows.
import { h, icon, fill } from '../core/dom.js';
import { t } from '../core/text.js';
/** The default order of the kinds, the one the server also uses. */
export const DEFAULT_ORDER = ['storie', 'evidenza', 'post', 'reel', 'taggati'];
/** The Italian name of a kind («Storie», «In evidenza», ...). */
export function kindName(kind) {
return t(`impostazioni.limiti.tipi.${kind}`);
}
/** An order as the server sent it, or the default one when it is missing. */
export function orderOrDefault(order) {
return Array.isArray(order) && order.length ? [...order] : [...DEFAULT_ORDER];
}
/**
* The editor of an order.
* @param {object} options
* @param {() => string[]} options.read the current order of the page
* @param {(order: string[]) => void} options.write stores a new order in the page
* @param {() => void} options.changed called after every move (save bar, recomputations)
* @param {(kind: string) => boolean} [options.off] kinds switched off in «Cosa scaricare»: they stay, attenuated
* @param {string} [options.label] accessible name of the list
* @returns {{ list: HTMLElement, status: HTMLElement, draw: () => void }}
*/
export function orderEditor({ read, write, changed, off = () => false, label }) {
const list = h('ol.ordine-tipi', { 'aria-label': label ?? t('impostazioni.limiti.ordine') });
const status = h('span.vh', { 'aria-live': 'polite' });
let dragged = null;
function move(from, to, focus) {
const order = [...read()];
if (to < 0 || to >= order.length || from === to) return;
const [kind] = order.splice(from, 1);
order.splice(to, 0, kind);
write(order);
draw();
changed();
status.textContent = t('impostazioni.limiti.ordineSpostato', { tipo: kindName(kind), n: to + 1 });
if (focus) {
const again = list.querySelector(`[data-tipo="${kind}"] [data-verso="${focus}"]`);
if (again && !again.disabled) again.focus();
else list.querySelector(`[data-tipo="${kind}"] button:not([disabled])`)?.focus();
}
}
function draw() {
const order = read();
fill(list, order.map((kind, i) => {
const name = kindName(kind);
const spento = off(kind);
const row = h(spento ? 'li.riga-ordine.spenta' : 'li.riga-ordine', { draggable: 'true', dataset: { tipo: kind } },
h('span.maniglia', { title: t('impostazioni.limiti.ordineManiglia'), 'aria-hidden': 'true' }, icon('grip-vertical', 's')),
h('span.posizione.dati', String(i + 1)),
h('b', name),
spento ? h('span.muto.piccolo', t('impostazioni.limiti.ordineSpento')) : null,
kind === 'storie' && i > 0 && !spento ? h('span.muto.piccolo', icon('clock', 'xs'), ' ', t('impostazioni.limiti.ordineStorie')) : null,
h('div.destra',
h('button.btn.piccolo.nudo', {
type: 'button', disabled: i === 0, dataset: { verso: 'su' }, 'aria-label': t('impostazioni.limiti.ordineSuDi', { tipo: name }), onclick: () => move(i, i - 1, 'su'),
}, icon('chevron-up', 's'), h('span.testo-btn', t('impostazioni.limiti.ordineSu'))),
h('button.btn.piccolo.nudo', {
type: 'button', disabled: i === order.length - 1, dataset: { verso: 'giu' }, 'aria-label': t('impostazioni.limiti.ordineGiuDi', { tipo: name }), onclick: () => move(i, i + 1, 'giu'),
}, icon('chevron-down', 's'), h('span.testo-btn', t('impostazioni.limiti.ordineGiu')))));
row.addEventListener('dragstart', (event) => {
dragged = i;
row.classList.add('trascinata');
try {
event.dataTransfer.effectAllowed = 'move';
event.dataTransfer.setData('text/plain', kind);
} catch {
// Some browsers refuse data on a drag: the index above is enough.
}
});
row.addEventListener('dragend', () => {
dragged = null;
row.classList.remove('trascinata');
});
row.addEventListener('dragover', (event) => {
if (dragged === null) return;
event.preventDefault();
});
row.addEventListener('drop', (event) => {
if (dragged === null) return;
event.preventDefault();
const from = dragged;
dragged = null;
move(from, i, null);
});
return row;
}));
}
return { list, status, draw };
}
@@ -9,11 +9,10 @@ import { h, icon, fill } from '../core/dom.js';
import { refreshEngine } from '../core/engine.js';
import { t, list, number, decimal } from '../core/text.js';
import { checkbox, confirmDialog, label, showError, toast, toggle } from '../core/ui.js';
import { DEFAULT_ORDER, orderEditor, orderOrDefault } from './download-order.js';
import { guardChanges, heading } from './settings.js';
const PACES = ['slow', 'natural', 'brisk'];
// «Cosa scaricare prima» (spec §7.2): the default order of the kinds, the one the server also uses.
const DEFAULT_ORDER = ['storie', 'evidenza', 'post', 'reel', 'taggati'];
const DAY_ORDER = [1, 2, 3, 4, 5, 6, 0]; // Monday first; the API counts from Sunday = 0
export default async function limits(page, box) {
@@ -34,73 +33,20 @@ export default async function limits(page, box) {
gradualStart: d.gradualStart,
activeDays: new Set(d.activeDays),
jitterOn: d.current.jitterMinutes > 0,
order: Array.isArray(d.downloadOrder) && d.downloadOrder.length ? [...d.downloadOrder] : [...DEFAULT_ORDER],
order: orderOrDefault(d.downloadOrder),
};
}
// ------------------------------------------------------------------------------------------- download order
// The rows move by dragging (mouse) or with «Su» and «Giù» (keyboard); the order is saved with the save bar.
const orderList = h('ol.ordine-tipi', { 'aria-label': t('impostazioni.limiti.ordine') });
const orderStatus = h('span.vh', { 'aria-live': 'polite' });
let dragged = null;
function move(from, to, focus) {
if (to < 0 || to >= form.order.length || from === to) return;
const [kind] = form.order.splice(from, 1);
form.order.splice(to, 0, kind);
drawOrder();
drawSaveBar();
orderStatus.textContent = t('impostazioni.limiti.ordineSpostato', { tipo: t(`impostazioni.limiti.tipi.${kind}`), n: to + 1 });
if (focus) {
const again = orderList.querySelector(`[data-tipo="${kind}"] [data-verso="${focus}"]`);
if (again && !again.disabled) again.focus();
else orderList.querySelector(`[data-tipo="${kind}"] button:not([disabled])`)?.focus();
}
}
function drawOrder() {
fill(orderList, form.order.map((kind, i) => {
const name = t(`impostazioni.limiti.tipi.${kind}`);
const row = h('li.riga-ordine', { draggable: 'true', dataset: { tipo: kind } },
h('span.maniglia', { title: t('impostazioni.limiti.ordineManiglia'), 'aria-hidden': 'true' }, icon('grip-vertical', 's')),
h('span.posizione.dati', String(i + 1)),
h('b', name),
kind === 'storie' && i > 0 ? h('span.muto.piccolo', icon('clock', 'xs'), ' ', t('impostazioni.limiti.ordineStorie')) : null,
h('div.destra',
h('button.btn.piccolo.nudo', {
type: 'button', disabled: i === 0, dataset: { verso: 'su' }, 'aria-label': t('impostazioni.limiti.ordineSuDi', { tipo: name }), onclick: () => move(i, i - 1, 'su'),
}, icon('chevron-up', 's'), h('span.testo-btn', t('impostazioni.limiti.ordineSu'))),
h('button.btn.piccolo.nudo', {
type: 'button', disabled: i === form.order.length - 1, dataset: { verso: 'giu' }, 'aria-label': t('impostazioni.limiti.ordineGiuDi', { tipo: name }), onclick: () => move(i, i + 1, 'giu'),
}, icon('chevron-down', 's'), h('span.testo-btn', t('impostazioni.limiti.ordineGiu')))));
row.addEventListener('dragstart', (event) => {
dragged = i;
row.classList.add('trascinata');
try {
event.dataTransfer.effectAllowed = 'move';
event.dataTransfer.setData('text/plain', kind);
} catch {
// Some browsers refuse data on a drag: the index above is enough.
}
});
row.addEventListener('dragend', () => {
dragged = null;
row.classList.remove('trascinata');
});
row.addEventListener('dragover', (event) => {
if (dragged === null) return;
event.preventDefault();
});
row.addEventListener('drop', (event) => {
if (dragged === null) return;
event.preventDefault();
const from = dragged;
dragged = null;
move(from, i, null);
});
return row;
}));
}
// The rows move by dragging or with «Su» and «Giù» (download-order.js); the order is saved with the save bar.
const order = orderEditor({
read: () => form.order,
write: (next) => { form.order = next; },
changed: () => drawSaveBar(),
});
const orderList = order.list;
const orderStatus = order.status;
const drawOrder = order.draw;
const orderReset = h('button.btn.collegamento', {
type: 'button',
+7
View File
@@ -430,6 +430,12 @@
"ore": "ore",
"cosa": "Cosa scaricare",
"cosaAiuto": "Quello che togli resta in libreria, ma non viene più aggiornato.",
"ordine": "Cosa scaricare prima",
"ordineAiuto": "Pesa sulle visite di Febe a questo account e sulla coda dei suoi file: il tipo più in alto viene di norma prima, ma non sempre. Non aggiunge controlli e non scavalca tetti, pause e frequenze.",
"ordineScelta": "Ordine dei tipi per questo account",
"ordineGenerale": "Come le impostazioni generali",
"ordineSuo": "Un ordine suo",
"ordineOra": "Ordine generale: {ordine}. Si cambia in Impostazioni → Limiti e comportamento.",
"tipi": {
"photos": "Foto dei post",
"videos": "Video e reel",
@@ -686,6 +692,7 @@
"ordine": "Cosa scaricare prima",
"ordineAiuto": "Dopo il giro dei profili che segui, Febe sceglie più spesso il tipo che sta più in alto, e scarica prima i suoi file. Non aggiunge controlli e non scavalca tetti, pause e frequenze. Trascina le righe o usa «Su» e «Giù».",
"ordineStorie": "Le storie scadono dopo 24 ore: più in basso stanno, più è facile che scadano prima di essere scaricate.",
"ordineSpento": "spento in «Cosa scaricare»",
"ordineMetti": "Ripristina l'ordine predefinito",
"ordineManiglia": "Trascina per spostare",
"ordineSu": "Su",