Foto del profilo: uno schema dei nomi proprio (#38) #47
No files matched your search
+4
-2
@@ -196,18 +196,20 @@ A destra un riquadro «Con queste impostazioni» traduce le scelte in conseguenz
|
||||
|
||||
- **Libreria**: dove finiscono foto e video. Può stare su un disco di rete o su una condivisione.
|
||||
- **Dati**: database, profilo del browser, miniature, registro, copie di sicurezza. Deve stare su un disco locale (§8.2).
|
||||
- Due schemi dei nomi configurabili, uno generale e uno per le raccolte in evidenza, con anteprima del risultato (mockup 08). Predefiniti:
|
||||
- Tre schemi dei nomi configurabili, uno generale, uno per le raccolte in evidenza e uno per le foto del profilo, con anteprima del risultato (mockup 08). Le foto del profilo restano nella loro cartella dentro l'account anche se lo schema generale cambia (#38). Predefiniti:
|
||||
|
||||
```text
|
||||
{account}\{tipo}\{anno}\{data}_{ora}_{codice}_{n}
|
||||
{account}\evidenza\{raccolta}\{data}_{ora}_{codice}_{n}
|
||||
{account}\profilo\{data}_{ora}_{codice}_{n}
|
||||
|
||||
marta.demo\post\2026\2026-10-10_18-22-05_DBx3kQ2_2.jpg
|
||||
marta.demo\storie\2026\2026-10-13_09-41-07_3742118_1.mp4
|
||||
marta.demo\evidenza\Estate 2025\2025-08-02_10-11-12_3391207_1.jpg
|
||||
marta.demo\profilo\2026-09-30_21-04-33_a3f9c2e1_1.jpg
|
||||
```
|
||||
|
||||
- Segnaposto: `account`, `tipo`, `anno`, `mese`, `data`, `ora`, `codice`, `n` (posizione del file nell'elemento), `raccolta`.
|
||||
- Segnaposto: `account`, `tipo`, `anno`, `mese`, `data`, `ora`, `codice`, `n` (posizione del file nell'elemento), `raccolta` (solo nello schema delle raccolte). Per le foto del profilo `codice` sono le prime otto cifre dello SHA-256 e `n` vale sempre 1.
|
||||
- Data e ora nei nomi sono nel fuso di Alberto; nel database sono in UTC. La data di modifica del file è quella di pubblicazione.
|
||||
- I nomi vengono ripuliti per Windows: caratteri vietati, nomi riservati, punti e spazi finali, percorsi oltre 240 caratteri.
|
||||
- Cambiare lo schema vale per i prossimi file: quelli già salvati non si rinominano.
|
||||
|
||||
@@ -319,3 +319,4 @@ Ogni scelta tecnica presa strada facendo, con data e motivo (specifica §15).
|
||||
| 2026-11-12 | Ripulitura e verifica sul HAR vero: (1) un numero lungo con esponente o virgola (`1.2e+21`) si falsifica cifra per cifra, lasciando segno, punto ed esponente, così resta un numero JSON valido; (2) la verifica non cerca dentro i valori che l'elenco ammesso tiene di proposito (un tipo di file, una data, una dimensione), mai però nelle chiavi di dati, che la ripulitura falsifica sempre, e indica sotto quale chiave sopravvive un frammento, mai il frammento; (3) le parole degli indirizzi finti (`sito`, `altro`, `esempio`) e le estensioni dei file non contano come frammenti. Campioni del secondo HAR accorciati sulla copia **ripulita** e già verificata, non sui grezzi | Sul HAR del 12/11 `ripulisci` si fermava su un numero con esponente e `verifica` dava 223 falsi allarmi (frammenti come «script» dentro `text/javascript`). Accorciare la copia ripulita evita di aprire i grezzi anche solo per tagliarli: togliere elementi da una copia verificata non può aggiungere valori dei grezzi |
|
||||
| 2026-11-12 | Vocabolario dei lettori di Instagram: `profile.postCount` = `media_count` e una chiave nuova `highlight.cover` (`cover_media.cropped_image_version`), letta come una versione. Le griglie delle schede Reel e Con tag restano anteprime, non contenuti | Dal secondo HAR: `media_count` compare solo nella scheda del profilo; la copertina delle raccolte è nell'elenco delle raccolte del profilo; le anteprime delle schede non hanno `taken_at` né `video_versions` (regola 9: si legge solo ciò che i campioni mostrano) |
|
||||
| 2026-11-13 | `febe-sonda da-har` e `richieste` leggono anche un HAR **troncato**: se il file finisce prima del suo JSON, e solo in quel caso, tengono le voci complete di `log.entries`, scartano quella dentro cui il file finisce e lo dicono a schermo e nel resoconto (`Truncated`, `DroppedEntry`). Per riconoscere il caso il lettore JSON lavora in modalità «dati non finiti»: la fine del file non è un errore, un errore di sintassi sì, e un file rotto in qualunque altro modo resta rifiutato. Per `richieste` la voce scartata conta comunque come dati: si chiude dove si ferma (il testo interrotto tenuto fino al taglio) e passa per le stesse regole di una voce intera (base64, pagine con blocchi incorporati, intestazioni, moduli); in più ogni stringa JSON del testo interrotto conta come valore, così un nome che è un dato solo lì viene tolto lo stesso. Resta fuori solo un valore tagliato a metà, di cui c'è solo l'inizio. Lettura comune in `HarFile` | Il 12/11 sera Chrome ha troncato due esportazioni dello stesso giro: la prima a 200 000 byte esatti, la seconda a 57 MB a metà di un corpo di risposta. Prima la sonda diceva solo «non è un file HAR valido (riga …)», senza distinguere un file tagliato da uno sbagliato, e non dava nulla della parte buona. La revisione avversaria ha trovato che la prima versione non contava i valori del testo interrotto né applicava alla voce scartata le regole di base64 e pagine: corretto prima del commit |
|
||||
| 2026-11-13 | Le foto del profilo hanno un **terzo schema dei nomi**, predefinito `{account}\profilo\{data}_{ora}_{codice}_{n}` (chiave `libreria.schema-profilo`), accanto a quello generale e a quello delle raccolte; Impostazioni ▸ Generali lo mostra come terzo campo, con la cartella `profilo` nel risultato. Niente cartella dell'anno; `{codice}` sono le prime otto cifre dello SHA-256 e `{n}` vale sempre 1, tenuto perché i nomi si leggano come gli altri e l'importazione li riconosca con il riconoscitore di Febe. Senza `{codice}` l'avviso dice che due foto possono avere lo stesso nome; `{raccolta}` è un errore. Una richiesta di salvataggio senza il terzo schema tiene quello salvato | Decisione di Alberto su #38 (12/11): le foto del profilo dentro ogni account, in `<account>\profilo\…`. Con lo schema unico bastava cambiare quello generale perché finissero con i post; uno schema proprio, come per le raccolte, le tiene separate qualunque cosa dica il generale |
|
||||
@@ -73,18 +73,25 @@ senza dati di Instagram, li riceve dall'elemento appena trovato.
|
||||
- **Libreria:** dove finiscono foto e video, una cartella per account. Può stare su un disco di rete.
|
||||
- **Dati:** database, profilo del browser, miniature, registro, copie. Deve stare su un disco locale.
|
||||
|
||||
Due schemi dei nomi, in Impostazioni ▸ Generali ▸ Nomi dei file, con anteprima del risultato. Predefiniti:
|
||||
Tre schemi dei nomi, in Impostazioni ▸ Generali ▸ Nomi dei file, con anteprima del risultato: uno generale (post,
|
||||
storie, taggati), uno per le raccolte in evidenza e uno per le foto del profilo. Predefiniti:
|
||||
|
||||
```text
|
||||
{account}\{tipo}\{anno}\{data}_{ora}_{codice}_{n}
|
||||
{account}\evidenza\{raccolta}\{data}_{ora}_{codice}_{n}
|
||||
{account}\profilo\{data}_{ora}_{codice}_{n}
|
||||
|
||||
marta.demo\post\2026\2026-10-10_18-22-05_DBx3kQ2_2.jpg
|
||||
marta.demo\evidenza\Estate 2025\2025-08-02_10-11-12_3391207_1.jpg
|
||||
marta.demo\profilo\2026-09-30_21-04-33_a3f9c2e1_1.jpg
|
||||
```
|
||||
|
||||
Le foto del profilo hanno il loro schema perché restino in una cartella a parte anche se cambi quello generale: una
|
||||
copia a ogni cambio di foto, con le prime otto cifre dell'impronta del file al posto del codice.
|
||||
|
||||
- Segnaposto: `account`, `tipo`, `anno`, `mese`, `data`, `ora`, `codice`, `n` (posizione del file nell'elemento),
|
||||
`raccolta`. Un segnaposto sconosciuto è un errore.
|
||||
`raccolta` (solo nello schema delle raccolte). Un segnaposto sconosciuto è un errore, e il campo sbagliato si
|
||||
colora di rosso.
|
||||
- Data e ora nei nomi sono nel tuo fuso; la data di modifica del file è quella di pubblicazione (si può spegnere).
|
||||
- I nomi sono ripuliti per Windows (caratteri vietati, nomi riservati, punti e spazi finali); un percorso oltre 240
|
||||
caratteri si accorcia prima nel nome del file, poi nelle cartelle. Un nome già occupato diventa `nome (2).ext`: mai
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 159 KiB |
@@ -86,8 +86,9 @@ schermata del motore fermo si prende per prima, perché «Riprendi» resta spent
|
||||
- **Limiti e comportamento.** Gli orari sono campi di testo a 24 ore («07:30») invece del selettore d'ora del
|
||||
browser, che in alcune lingue mostra AM/PM. I giorni sono cerchi con l'iniziale. La barra di salvataggio resta
|
||||
sempre visibile: spenta con «Nessuna modifica», si accende alla prima modifica.
|
||||
- **Impostazioni generali.** In più rispetto al mockup: lo spazio libero accanto alle cartelle, la nota «Per ora
|
||||
c'è solo l'italiano» sotto la lingua e la riga «Solo versione Windows» accanto ad «Avvio». In Docker le cartelle
|
||||
- **Impostazioni generali.** In più rispetto al mockup: lo spazio libero accanto alle cartelle, il terzo schema «Schema
|
||||
per le foto del profilo» con la cartella `profilo` nel risultato (#38, schermata rifatta il 13/11 da Windows), la
|
||||
nota «Per ora c'è solo l'italiano» sotto la lingua e la riga «Solo versione Windows» accanto ad «Avvio». In Docker le cartelle
|
||||
non si cambiano dall'interfaccia (si cambiano i volumi del contenitore) e la sezione Avvio non c'è.
|
||||
- **Importa, revisione.** Percorso della cartella temporanea della dimostrazione; le immagini dei doppioni sono
|
||||
disegni generati. Il riquadro dei doppioni passa al caso seguente dopo ogni scelta: la schermata torna al primo
|
||||
|
||||
+15
-1
@@ -1,12 +1,26 @@
|
||||
# Stato
|
||||
|
||||
Filo fra le sessioni (specifica §15): che cosa è fatto, che cosa è in corso, che cosa è rimandato e perché.
|
||||
Aggiornato il 12 novembre 2026, versione 0.1.2 in `main` (il tag `v0.1.2` non è stato creato). **Le attività stanno
|
||||
Aggiornato il 13 novembre 2026, versione 0.1.2 in `main` (il tag `v0.1.2` non è stato creato). **Le attività stanno
|
||||
su Gitea**: issue, etichette e traguardi di https://gitea.encke-hake.ts.net/Alby96/Febe. Questo file resta il resoconto
|
||||
fra le sessioni; ciò che è da fare si legge nelle issue aperte.
|
||||
|
||||
## In breve
|
||||
|
||||
**13 novembre 2026, giorno: le foto del profilo hanno il loro schema** (#38).
|
||||
|
||||
- PR #45 è **unita in `main`** (305791f) con la verifica verde (esecuzione 272). Forzare l'unione non era possibile:
|
||||
la protezione di `main` vale anche per gli amministratori.
|
||||
- Le foto del profilo hanno un terzo schema dei nomi, predefinito `{account}\profilo\{data}_{ora}_{codice}_{n}`,
|
||||
accanto a quello generale e a quello delle raccolte: restano in `<account>\profilo` anche se Alberto cambia lo schema
|
||||
generale (sua decisione su #38). In Impostazioni ▸ Generali è il terzo campo, con la cartella `profilo` nel risultato
|
||||
e il campo rosso se è sbagliato; confrontata con il mockup 08 e rifatta `docs/schermate/08-impostazioni-generali.png`.
|
||||
Specifica §4.7, guida (Libreria) e una riga in `docs/decisioni.md`.
|
||||
- Prove nuove: nomi e regole del terzo schema, anteprima, impostazioni (un salvataggio senza il terzo schema lo tiene),
|
||||
salvataggio dei file con uno schema generale piatto, riconoscimento all'importazione, ricostruzione del database.
|
||||
- **Resta di #38**: che le foto arrivino davvero, con la raccolta riscritta (#36), anche per gli account aggiunti dalla
|
||||
ricerca (#37).
|
||||
|
||||
**13 novembre 2026, notte: il HAR dello scorrimento è troncato** (#35).
|
||||
|
||||
- Alberto ha esportato il giro corto della parte A quater (seguiti e seconda pagina dei post). Il file è arrivato
|
||||
|
||||
@@ -3,7 +3,7 @@ using Febe.Core.Storage;
|
||||
namespace Febe.Core.Library;
|
||||
|
||||
/// <summary>
|
||||
/// Settings of the library (spec §4.7, mockup 08): the library folder, the two naming schemes and whether the file
|
||||
/// Settings of the library (spec §4.7, mockup 08): the library folder, the three naming schemes and whether the file
|
||||
/// modification time is set to the publication time. Stored in the <c>setting</c> table.
|
||||
/// </summary>
|
||||
public sealed record LibrarySettings(string LibraryRoot, LibraryNaming Naming, bool SetFileTimeToPublication = true)
|
||||
@@ -18,12 +18,16 @@ public sealed record LibrarySettings(string LibraryRoot, LibraryNaming Naming, b
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(defaultLibraryRoot);
|
||||
var values = await store.GetAllAsync(ct).ConfigureAwait(false);
|
||||
var root = values.GetValueOrDefault(SettingKeys.LibraryRoot);
|
||||
var general = NamingScheme.Validate(values.GetValueOrDefault(SettingKeys.NamingScheme) ?? NamingScheme.DefaultGeneral, forHighlights: false);
|
||||
var highlight = NamingScheme.Validate(values.GetValueOrDefault(SettingKeys.HighlightNamingScheme) ?? NamingScheme.DefaultHighlight, forHighlights: true);
|
||||
NamingScheme Scheme(string key, NamingSchemeUse use) =>
|
||||
NamingScheme.Validate(values.GetValueOrDefault(key) ?? NamingScheme.Default(use).Text, use).Scheme ?? NamingScheme.Default(use);
|
||||
|
||||
var setTime = !values.TryGetValue(SettingKeys.SetFileTimeToPublication, out var text) || !bool.TryParse(text, out var parsed) || parsed;
|
||||
return new LibrarySettings(
|
||||
string.IsNullOrWhiteSpace(root) ? defaultLibraryRoot : root,
|
||||
new LibraryNaming(general.Scheme ?? NamingScheme.General, highlight.Scheme ?? NamingScheme.Highlight),
|
||||
new LibraryNaming(
|
||||
Scheme(SettingKeys.NamingScheme, NamingSchemeUse.General),
|
||||
Scheme(SettingKeys.HighlightNamingScheme, NamingSchemeUse.Highlight),
|
||||
Scheme(SettingKeys.ProfilePictureNamingScheme, NamingSchemeUse.ProfilePicture)),
|
||||
setTime);
|
||||
}
|
||||
|
||||
@@ -37,6 +41,7 @@ public sealed record LibrarySettings(string LibraryRoot, LibraryNaming Naming, b
|
||||
[SettingKeys.LibraryRoot] = LibraryRoot,
|
||||
[SettingKeys.NamingScheme] = Naming.General.Text,
|
||||
[SettingKeys.HighlightNamingScheme] = Naming.Highlight.Text,
|
||||
[SettingKeys.ProfilePictureNamingScheme] = Naming.ProfilePicture.Text,
|
||||
[SettingKeys.SetFileTimeToPublication] = SetFileTimeToPublication ? "true" : "false",
|
||||
},
|
||||
ct);
|
||||
|
||||
@@ -9,7 +9,7 @@ public sealed record NamingPreviewFile(string Name, MediaKind Kind);
|
||||
public sealed record NamingPreviewFolder(IReadOnlyList<string> Path, IReadOnlyList<NamingPreviewFile> Files);
|
||||
|
||||
/// <summary>
|
||||
/// The «Risultato» tree of the settings screen (mockup 08): an account folder with sample files rendered by the two
|
||||
/// The «Risultato» tree of the settings screen (mockup 08): an account folder with sample files rendered by the three
|
||||
/// schemes. The interface shows each folder path joined by « \ ».
|
||||
/// </summary>
|
||||
public sealed record NamingPreview(
|
||||
@@ -21,21 +21,25 @@ public sealed record NamingPreview(
|
||||
public bool IsValid => Errors.Count == 0;
|
||||
|
||||
/// <summary>
|
||||
/// Renders three sample files — a post photo (second of a series), a story video and a highlight photo — with the
|
||||
/// given schemes. Sample times are local times in <paramref name="zone"/>, so the preview reads the same anywhere.
|
||||
/// Renders four sample files — a post photo (second of a series), a story video, a highlight photo and a profile
|
||||
/// picture — with the given schemes. Sample times are local times in <paramref name="zone"/>, so the preview reads
|
||||
/// the same anywhere. Each error and warning starts with the name of its scheme (<see cref="Prefix"/>).
|
||||
/// </summary>
|
||||
public static NamingPreview Build(string? generalScheme, string? highlightScheme, TimeZoneInfo zone, string sampleAccount = "nome.utente")
|
||||
public static NamingPreview Build(string? generalScheme, string? highlightScheme, string? profilePictureScheme, TimeZoneInfo zone, string sampleAccount = "nome.utente")
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(zone);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(sampleAccount);
|
||||
var general = NamingScheme.Validate(generalScheme, forHighlights: false);
|
||||
var highlight = NamingScheme.Validate(highlightScheme, forHighlights: true);
|
||||
var errors = general.Errors.Select(e => "Schema: " + e)
|
||||
.Concat(highlight.Errors.Select(e => "Schema per le raccolte in evidenza: " + e))
|
||||
.ToList();
|
||||
var warnings = general.Warnings.Select(e => "Schema: " + e)
|
||||
.Concat(highlight.Warnings.Select(e => "Schema per le raccolte in evidenza: " + e))
|
||||
.ToList();
|
||||
var general = NamingScheme.Validate(generalScheme, NamingSchemeUse.General);
|
||||
var highlight = NamingScheme.Validate(highlightScheme, NamingSchemeUse.Highlight);
|
||||
var profile = NamingScheme.Validate(profilePictureScheme, NamingSchemeUse.ProfilePicture);
|
||||
(NamingSchemeValidation Validation, string Prefix)[] all =
|
||||
[
|
||||
(general, Prefix(NamingSchemeUse.General)),
|
||||
(highlight, Prefix(NamingSchemeUse.Highlight)),
|
||||
(profile, Prefix(NamingSchemeUse.ProfilePicture)),
|
||||
];
|
||||
var errors = all.SelectMany(s => s.Validation.Errors.Select(e => s.Prefix + e)).ToList();
|
||||
var warnings = all.SelectMany(s => s.Validation.Warnings.Select(e => s.Prefix + e)).ToList();
|
||||
|
||||
var folders = new List<NamingPreviewFolder>();
|
||||
void Add(NamingScheme scheme, EntryKind kind, DateTime local, string code, int n, MediaKind media, string? collection)
|
||||
@@ -73,6 +77,22 @@ public sealed record NamingPreview(
|
||||
Add(h, EntryKind.Highlight, new DateTime(2025, 8, 2, 10, 11, 12), "3391207", 1, MediaKind.Photo, "Estate 2025");
|
||||
}
|
||||
|
||||
if (profile.Scheme is { } p)
|
||||
{
|
||||
Add(p, EntryKind.ProfilePicture, new DateTime(2026, 9, 30, 21, 4, 33), "a3f9c2e1", 1, MediaKind.Photo, null);
|
||||
}
|
||||
|
||||
return new NamingPreview(WindowsFileNames.SanitizeSegment(sampleAccount), folders, errors, warnings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The start of the errors and warnings of a scheme («Schema: », «Schema per le raccolte in evidenza: », «Schema
|
||||
/// per le foto del profilo: »): the settings screen uses it to mark the field in error.
|
||||
/// </summary>
|
||||
public static string Prefix(NamingSchemeUse use) => use switch
|
||||
{
|
||||
NamingSchemeUse.Highlight => "Schema per le raccolte in evidenza: ",
|
||||
NamingSchemeUse.ProfilePicture => "Schema per le foto del profilo: ",
|
||||
_ => "Schema: ",
|
||||
};
|
||||
}
|
||||
@@ -9,7 +9,8 @@ namespace Febe.Core.Library;
|
||||
/// <para>
|
||||
/// A backslash (or a slash) separates folders on every operating system. Placeholders: <c>account</c>, <c>tipo</c>,
|
||||
/// <c>anno</c>, <c>mese</c>, <c>data</c>, <c>ora</c>, <c>codice</c>, <c>n</c>, <c>raccolta</c> (only in the scheme of
|
||||
/// highlight collections). Dates and times are in Alberto's time zone: <c>data</c> is yyyy-MM-dd and <c>ora</c> is
|
||||
/// highlight collections). There are three schemes (<see cref="NamingSchemeUse"/>): general, highlight collections and
|
||||
/// profile pictures, so that each of the last two keeps its own folder whatever the general scheme says. Dates and times are in Alberto's time zone: <c>data</c> is yyyy-MM-dd and <c>ora</c> is
|
||||
/// HH-mm-ss. The file extension is added to the last segment.
|
||||
/// </para>
|
||||
/// <para>
|
||||
@@ -23,33 +24,57 @@ public sealed class NamingScheme
|
||||
|
||||
public const string DefaultHighlight = @"{account}\evidenza\{raccolta}\{data}_{ora}_{codice}_{n}";
|
||||
|
||||
/// <summary>
|
||||
/// Profile pictures: few per account, so no year folder. <c>{codice}</c> is the start of the SHA-256 (spec §4.3);
|
||||
/// <c>{n}</c> is always 1, kept so that the names read like the others and the import recognizes them.
|
||||
/// </summary>
|
||||
public const string DefaultProfilePicture = @"{account}\profilo\{data}_{ora}_{codice}_{n}";
|
||||
|
||||
/// <summary>Placeholders accepted, in the order shown in the interface.</summary>
|
||||
public static IReadOnlyList<string> Placeholders { get; } = ["account", "tipo", "anno", "mese", "data", "ora", "codice", "n", "raccolta"];
|
||||
|
||||
private readonly IReadOnlyList<IReadOnlyList<Token>> _segments;
|
||||
|
||||
private NamingScheme(string text, bool forHighlights, IReadOnlyList<IReadOnlyList<Token>> segments)
|
||||
private NamingScheme(string text, NamingSchemeUse use, IReadOnlyList<IReadOnlyList<Token>> segments)
|
||||
{
|
||||
Text = text;
|
||||
ForHighlights = forHighlights;
|
||||
Use = use;
|
||||
_segments = segments;
|
||||
}
|
||||
|
||||
/// <summary>The scheme as written.</summary>
|
||||
public string Text { get; }
|
||||
|
||||
/// <summary>Which files the scheme names.</summary>
|
||||
public NamingSchemeUse Use { get; }
|
||||
|
||||
/// <summary>True for the scheme of highlight collections (accepts <c>{raccolta}</c>).</summary>
|
||||
public bool ForHighlights { get; }
|
||||
public bool ForHighlights => Use == NamingSchemeUse.Highlight;
|
||||
|
||||
public static NamingScheme General { get; } = Parse(DefaultGeneral, forHighlights: false);
|
||||
public static NamingScheme General { get; } = Parse(DefaultGeneral, NamingSchemeUse.General);
|
||||
|
||||
public static NamingScheme Highlight { get; } = Parse(DefaultHighlight, forHighlights: true);
|
||||
public static NamingScheme Highlight { get; } = Parse(DefaultHighlight, NamingSchemeUse.Highlight);
|
||||
|
||||
/// <summary>Parses a scheme. </summary>
|
||||
/// <exception cref="FormatException">The scheme is not valid; the message (Italian) says why.</exception>
|
||||
public static NamingScheme Parse(string text, bool forHighlights)
|
||||
public static NamingScheme ProfilePicture { get; } = Parse(DefaultProfilePicture, NamingSchemeUse.ProfilePicture);
|
||||
|
||||
/// <summary>The default scheme for a use.</summary>
|
||||
public static NamingScheme Default(NamingSchemeUse use) => use switch
|
||||
{
|
||||
var validation = Validate(text, forHighlights);
|
||||
NamingSchemeUse.Highlight => Highlight,
|
||||
NamingSchemeUse.ProfilePicture => ProfilePicture,
|
||||
_ => General,
|
||||
};
|
||||
|
||||
/// <summary>Parses the general scheme or the one of highlight collections.</summary>
|
||||
/// <exception cref="FormatException">The scheme is not valid; the message (Italian) says why.</exception>
|
||||
public static NamingScheme Parse(string text, bool forHighlights) =>
|
||||
Parse(text, forHighlights ? NamingSchemeUse.Highlight : NamingSchemeUse.General);
|
||||
|
||||
/// <summary>Parses a scheme.</summary>
|
||||
/// <exception cref="FormatException">The scheme is not valid; the message (Italian) says why.</exception>
|
||||
public static NamingScheme Parse(string text, NamingSchemeUse use)
|
||||
{
|
||||
var validation = Validate(text, use);
|
||||
if (!validation.IsValid)
|
||||
{
|
||||
throw new FormatException(validation.Errors[0]);
|
||||
@@ -58,8 +83,12 @@ public sealed class NamingScheme
|
||||
return validation.Scheme!;
|
||||
}
|
||||
|
||||
/// <summary>Checks the general scheme or the one of highlight collections.</summary>
|
||||
public static NamingSchemeValidation Validate(string? text, bool forHighlights) =>
|
||||
Validate(text, forHighlights ? NamingSchemeUse.Highlight : NamingSchemeUse.General);
|
||||
|
||||
/// <summary>Checks a scheme for the settings screen: errors block saving, warnings are shown.</summary>
|
||||
public static NamingSchemeValidation Validate(string? text, bool forHighlights)
|
||||
public static NamingSchemeValidation Validate(string? text, NamingSchemeUse use)
|
||||
{
|
||||
var errors = new List<string>();
|
||||
var warnings = new List<string>();
|
||||
@@ -90,7 +119,7 @@ public sealed class NamingScheme
|
||||
{
|
||||
errors.Add($"Segnaposto sconosciuto: {{{token.Value}}}. Quelli ammessi sono: {string.Join(", ", Placeholders)}.");
|
||||
}
|
||||
else if (token.Value == "raccolta" && !forHighlights)
|
||||
else if (token.Value == "raccolta" && use != NamingSchemeUse.Highlight)
|
||||
{
|
||||
errors.Add("{raccolta} si usa solo nello schema per le raccolte in evidenza.");
|
||||
}
|
||||
@@ -110,7 +139,15 @@ public sealed class NamingScheme
|
||||
segments.RemoveAt(0);
|
||||
}
|
||||
|
||||
if (!used.Contains("codice") && !used.Contains("n"))
|
||||
if (use == NamingSchemeUse.ProfilePicture)
|
||||
{
|
||||
// One file per picture: {n} is always 1, and {codice} (the start of the SHA-256) tells the pictures apart.
|
||||
if (!used.Contains("codice"))
|
||||
{
|
||||
warnings.Add("Senza {codice} due foto del profilo possono avere lo stesso nome: Febe aggiunge un numero per distinguerle.");
|
||||
}
|
||||
}
|
||||
else if (!used.Contains("codice") && !used.Contains("n"))
|
||||
{
|
||||
warnings.Add("Senza {codice} e {n} più file possono avere lo stesso nome: Febe aggiunge un numero per distinguerli.");
|
||||
}
|
||||
@@ -119,12 +156,12 @@ public sealed class NamingScheme
|
||||
warnings.Add("Senza {n} i file di un post con più foto o video hanno lo stesso nome: Febe aggiunge un numero per distinguerli.");
|
||||
}
|
||||
|
||||
if (forHighlights && !used.Contains("raccolta"))
|
||||
if (use == NamingSchemeUse.Highlight && !used.Contains("raccolta"))
|
||||
{
|
||||
warnings.Add("Senza {raccolta} i contenuti delle diverse raccolte finiscono nella stessa cartella.");
|
||||
}
|
||||
|
||||
return new NamingSchemeValidation(new NamingScheme(text.Trim(), forHighlights, segments), [], warnings);
|
||||
return new NamingSchemeValidation(new NamingScheme(text.Trim(), use, segments), [], warnings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -241,7 +278,20 @@ public sealed class NamingScheme
|
||||
private readonly record struct Token(bool IsPlaceholder, string Value);
|
||||
}
|
||||
|
||||
/// <summary>Result of <see cref="NamingScheme.Validate"/>.</summary>
|
||||
/// <summary>Which files a naming scheme names (spec §4.7).</summary>
|
||||
public enum NamingSchemeUse
|
||||
{
|
||||
/// <summary>Posts, stories and tagged posts.</summary>
|
||||
General,
|
||||
|
||||
/// <summary>Contents of highlight collections (accepts <c>{raccolta}</c>).</summary>
|
||||
Highlight,
|
||||
|
||||
/// <summary>Profile pictures.</summary>
|
||||
ProfilePicture,
|
||||
}
|
||||
|
||||
/// <summary>Result of <see cref="NamingScheme.Validate(string?, NamingSchemeUse)"/>.</summary>
|
||||
public sealed record NamingSchemeValidation(NamingScheme? Scheme, IReadOnlyList<string> Errors, IReadOnlyList<string> Warnings)
|
||||
{
|
||||
public bool IsValid => Scheme is not null && Errors.Count == 0;
|
||||
@@ -272,11 +322,16 @@ public sealed record NamingValues(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The two configurable schemes (spec §4.7): general and for highlight collections.</summary>
|
||||
public sealed record LibraryNaming(NamingScheme General, NamingScheme Highlight)
|
||||
/// <summary>The three configurable schemes (spec §4.7): general, highlight collections and profile pictures.</summary>
|
||||
public sealed record LibraryNaming(NamingScheme General, NamingScheme Highlight, NamingScheme ProfilePicture)
|
||||
{
|
||||
public static LibraryNaming Default { get; } = new(NamingScheme.General, NamingScheme.Highlight);
|
||||
public static LibraryNaming Default { get; } = new(NamingScheme.General, NamingScheme.Highlight, NamingScheme.ProfilePicture);
|
||||
|
||||
/// <summary>The scheme that applies to an entry kind.</summary>
|
||||
public NamingScheme For(EntryKind kind) => kind == EntryKind.Highlight ? Highlight : General;
|
||||
public NamingScheme For(EntryKind kind) => kind switch
|
||||
{
|
||||
EntryKind.Highlight => Highlight,
|
||||
EntryKind.ProfilePicture => ProfilePicture,
|
||||
_ => General,
|
||||
};
|
||||
}
|
||||
@@ -28,6 +28,9 @@ public static class SettingKeys
|
||||
/// <summary>Naming scheme for highlight collections.</summary>
|
||||
public const string HighlightNamingScheme = "libreria.schema-evidenza";
|
||||
|
||||
/// <summary>Naming scheme for profile pictures.</summary>
|
||||
public const string ProfilePictureNamingScheme = "libreria.schema-profilo";
|
||||
|
||||
/// <summary>«Imposta la data del file a quella di pubblicazione» (true/false).</summary>
|
||||
public const string SetFileTimeToPublication = "libreria.data-file-pubblicazione";
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public sealed record NamingPreviewFileDto(string Name, string Kind);
|
||||
|
||||
public sealed record NamingPreviewFolderDto(IReadOnlyList<string> Path, IReadOnlyList<NamingPreviewFileDto> Files);
|
||||
|
||||
/// <summary>The «Risultato» tree of mockup 08 and the problems of the two schemes.</summary>
|
||||
/// <summary>The «Risultato» tree of mockup 08 and the problems of the three schemes.</summary>
|
||||
public sealed record NamingPreviewDto(string AccountFolder, IReadOnlyList<NamingPreviewFolderDto> Folders, IReadOnlyList<string> Errors, IReadOnlyList<string> Warnings);
|
||||
|
||||
/// <summary>Impostazioni, Generali (mockup 08).</summary>
|
||||
@@ -71,8 +71,10 @@ public sealed record GeneralSettingsDto(
|
||||
bool CanChangeDataFolder,
|
||||
string NamingScheme,
|
||||
string HighlightScheme,
|
||||
string ProfilePictureScheme,
|
||||
string DefaultNamingScheme,
|
||||
string DefaultHighlightScheme,
|
||||
string DefaultProfilePictureScheme,
|
||||
IReadOnlyList<string> Placeholders,
|
||||
bool SetFileTime,
|
||||
NamingPreviewDto Preview,
|
||||
@@ -80,10 +82,14 @@ public sealed record GeneralSettingsDto(
|
||||
bool KeepInTray,
|
||||
string Language);
|
||||
|
||||
/// <summary>Saves Impostazioni, Generali. A null <see cref="LibraryFolder"/> keeps the library folder.</summary>
|
||||
public sealed record GeneralSettingsRequest(string? LibraryFolder, string NamingScheme, string HighlightScheme, bool SetFileTime, bool? Autostart, bool? KeepInTray);
|
||||
/// <summary>
|
||||
/// Saves Impostazioni, Generali. A null <see cref="LibraryFolder"/> keeps the library folder; a null
|
||||
/// <see cref="ProfilePictureScheme"/> keeps the scheme of profile pictures.
|
||||
/// </summary>
|
||||
public sealed record GeneralSettingsRequest(string? LibraryFolder, string NamingScheme, string HighlightScheme, bool SetFileTime, bool? Autostart, bool? KeepInTray, string? ProfilePictureScheme = null);
|
||||
|
||||
public sealed record NamingRequest(string? NamingScheme, string? HighlightScheme);
|
||||
/// <summary>The schemes to preview; a null <see cref="ProfilePictureScheme"/> stands for the default one.</summary>
|
||||
public sealed record NamingRequest(string? NamingScheme, string? HighlightScheme, string? ProfilePictureScheme = null);
|
||||
|
||||
/// <summary><see cref="Which"/>: library or data.</summary>
|
||||
public sealed record PickFolderRequest(string Which);
|
||||
|
||||
@@ -38,8 +38,14 @@ public static class SettingsApi
|
||||
{
|
||||
var d = Deps.From(services);
|
||||
var body = await ApiHttp.BodyAsync(context, FebeJsonContext.Default.GeneralSettingsRequest).ConfigureAwait(false);
|
||||
var general = Validate(NamingScheme.Validate(body.NamingScheme, forHighlights: false), "Schema");
|
||||
var highlight = Validate(NamingScheme.Validate(body.HighlightScheme, forHighlights: true), "Schema per le raccolte in evidenza");
|
||||
var general = Validate(NamingScheme.Validate(body.NamingScheme, NamingSchemeUse.General), NamingSchemeUse.General);
|
||||
var highlight = Validate(NamingScheme.Validate(body.HighlightScheme, NamingSchemeUse.Highlight), NamingSchemeUse.Highlight);
|
||||
|
||||
// A request without the scheme of profile pictures keeps the stored one.
|
||||
var profile = body.ProfilePictureScheme is { } profileText
|
||||
? Validate(NamingScheme.Validate(profileText, NamingSchemeUse.ProfilePicture), NamingSchemeUse.ProfilePicture)
|
||||
: (await LibrarySettings.LoadAsync(d.Storage.Settings, d.Library.Layout.Root, ct).ConfigureAwait(false)).Naming.ProfilePicture;
|
||||
var naming = new LibraryNaming(general, highlight, profile);
|
||||
var caps = SystemApi.Capabilities(context, d.Options, d.Shell, d.Browser, d.Clock);
|
||||
var root = d.Library.Layout.Root;
|
||||
if (!string.IsNullOrWhiteSpace(body.LibraryFolder) && !SamePath(body.LibraryFolder, root))
|
||||
@@ -52,7 +58,7 @@ public static class SettingsApi
|
||||
root = await ChangeLibraryRootAsync(d, body.LibraryFolder, ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await new LibrarySettings(root, new LibraryNaming(general, highlight), body.SetFileTime).SaveAsync(d.Storage.Settings, ct).ConfigureAwait(false);
|
||||
await new LibrarySettings(root, naming, body.SetFileTime).SaveAsync(d.Storage.Settings, ct).ConfigureAwait(false);
|
||||
if (caps.Autostart && body.Autostart is { } autostart)
|
||||
{
|
||||
await d.Shell.SetAutostartAsync(autostart, ct).ConfigureAwait(false);
|
||||
@@ -67,7 +73,7 @@ public static class SettingsApi
|
||||
if (d.Services.GetService(typeof(Febe.Core.Library.LibraryIngest)) is Febe.Core.Library.LibraryIngest ingest)
|
||||
{
|
||||
// The scheme and a new library folder (desktop) hold for the next downloads, without a restart.
|
||||
ingest.Apply(new LibraryNaming(general, highlight), body.SetFileTime);
|
||||
ingest.Apply(naming, body.SetFileTime);
|
||||
ingest.UseLayout(d.Library.Layout);
|
||||
}
|
||||
d.Changes.Publish(new LibraryChange(d.Clock.Now, null, "settings"));
|
||||
@@ -78,7 +84,8 @@ public static class SettingsApi
|
||||
{
|
||||
var body = await ApiHttp.BodyAsync(context, FebeJsonContext.Default.NamingRequest).ConfigureAwait(false);
|
||||
var sample = await SampleAccountAsync(storage, ct).ConfigureAwait(false);
|
||||
return ApiHttp.Json(Preview(NamingPreview.Build(body.NamingScheme, body.HighlightScheme, clock.LocalZone, sample)), FebeJsonContext.Default.NamingPreviewDto);
|
||||
var profile = body.ProfilePictureScheme ?? NamingScheme.DefaultProfilePicture;
|
||||
return ApiHttp.Json(Preview(NamingPreview.Build(body.NamingScheme, body.HighlightScheme, profile, clock.LocalZone, sample)), FebeJsonContext.Default.NamingPreviewDto);
|
||||
});
|
||||
|
||||
endpoints.MapPost("/api/settings/pick-folder", async (HttpContext context, IServiceProvider services, CancellationToken ct) =>
|
||||
@@ -268,11 +275,13 @@ public static class SettingsApi
|
||||
!caps.FoldersReadOnly && (dataChange?.CanChange ?? false),
|
||||
settings.Naming.General.Text,
|
||||
settings.Naming.Highlight.Text,
|
||||
settings.Naming.ProfilePicture.Text,
|
||||
NamingScheme.DefaultGeneral,
|
||||
NamingScheme.DefaultHighlight,
|
||||
NamingScheme.DefaultProfilePicture,
|
||||
NamingScheme.Placeholders,
|
||||
settings.SetFileTimeToPublication,
|
||||
Preview(NamingPreview.Build(settings.Naming.General.Text, settings.Naming.Highlight.Text, d.Clock.LocalZone, sample)),
|
||||
Preview(NamingPreview.Build(settings.Naming.General.Text, settings.Naming.Highlight.Text, settings.Naming.ProfilePicture.Text, d.Clock.LocalZone, sample)),
|
||||
autostart,
|
||||
tray,
|
||||
"it");
|
||||
@@ -297,14 +306,14 @@ public static class SettingsApi
|
||||
?? "nome.utente";
|
||||
}
|
||||
|
||||
private static NamingScheme Validate(NamingSchemeValidation validation, string name)
|
||||
private static NamingScheme Validate(NamingSchemeValidation validation, NamingSchemeUse use)
|
||||
{
|
||||
if (validation.IsValid)
|
||||
{
|
||||
return validation.Scheme!;
|
||||
}
|
||||
|
||||
throw new BadRequestException(string.Join(" ", validation.Errors.Select(e => $"{name}: {e}")));
|
||||
throw new BadRequestException(string.Join(" ", validation.Errors.Select(e => NamingPreview.Prefix(use) + e)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Impostazioni, Generali (mockup 08, spec §4.7, §10.5, §12): the Libreria and Dati folders with «Cambia…» (desktop:
|
||||
// native picker; Docker: read-only with the note), free and used space; the two naming schemes with the live «Risultato»
|
||||
// native picker; Docker: read-only with the note), free and used space; the three naming schemes with the live «Risultato»
|
||||
// tree, the placeholders and the errors; «Imposta la data del file a quella di pubblicazione»; theme and language;
|
||||
// the «Avvio» block on Windows only.
|
||||
|
||||
@@ -12,9 +12,10 @@ import { guardChanges, heading } from './settings.js';
|
||||
|
||||
export default async function general(page, box) {
|
||||
let data = await api('/api/settings/general', { signal: page.signal });
|
||||
let saved = { naming: data.namingScheme, highlight: data.highlightScheme, setFileTime: data.setFileTime };
|
||||
const stored = (d) => ({ naming: d.namingScheme, highlight: d.highlightScheme, profile: d.profilePictureScheme, setFileTime: d.setFileTime });
|
||||
let saved = stored(data);
|
||||
const form = { ...saved };
|
||||
const dirty = () => form.naming !== saved.naming || form.highlight !== saved.highlight || form.setFileTime !== saved.setFileTime;
|
||||
const dirty = () => Object.keys(saved).some((key) => form[key] !== saved[key]);
|
||||
guardChanges(page, dirty);
|
||||
|
||||
// ------------------------------------------------------------------------------------------- folders
|
||||
@@ -86,6 +87,7 @@ export default async function general(page, box) {
|
||||
libraryFolder: null,
|
||||
namingScheme: withForm ? form.naming : saved.naming,
|
||||
highlightScheme: withForm ? form.highlight : saved.highlight,
|
||||
profilePictureScheme: withForm ? form.profile : saved.profile,
|
||||
setFileTime: withForm ? form.setFileTime : saved.setFileTime,
|
||||
autostart: null,
|
||||
keepInTray: null,
|
||||
@@ -93,7 +95,7 @@ export default async function general(page, box) {
|
||||
};
|
||||
try {
|
||||
data = await api('/api/settings/general', { method: 'PUT', body });
|
||||
saved = { naming: data.namingScheme, highlight: data.highlightScheme, setFileTime: data.setFileTime };
|
||||
saved = stored(data);
|
||||
if (withForm) Object.assign(form, saved);
|
||||
drawFolders();
|
||||
drawSaveBar();
|
||||
@@ -108,16 +110,20 @@ export default async function general(page, box) {
|
||||
// ------------------------------------------------------------------------------------------- naming
|
||||
const naming = h('input.dati', { type: 'text', value: form.naming, id: 'schema', spellcheck: 'false', autocomplete: 'off' });
|
||||
const highlight = h('input.dati', { type: 'text', value: form.highlight, id: 'schema-evidenza', spellcheck: 'false', autocomplete: 'off' });
|
||||
const profile = h('input.dati', { type: 'text', value: form.profile, id: 'schema-profilo', spellcheck: 'false', autocomplete: 'off' });
|
||||
const namingField = h('label.campo', naming);
|
||||
const highlightField = h('label.campo', highlight);
|
||||
const profileField = h('label.campo', profile);
|
||||
const problems = h('div.problemi-schema', { 'aria-live': 'polite' });
|
||||
const tree = h('div.albero.pannello', { 'aria-label': t('impostazioni.generali.risultato') });
|
||||
const setTime = checkbox({ checked: form.setFileTime, label: t('impostazioni.generali.dataFile'), onchange: (v) => { form.setFileTime = v; drawSaveBar(); } });
|
||||
|
||||
function drawTree(preview) {
|
||||
const errors = preview.errors || [];
|
||||
// Each error starts with the name of its scheme (NamingPreview.Prefix).
|
||||
namingField.classList.toggle('errore', errors.some((e) => e.startsWith('Schema:')));
|
||||
highlightField.classList.toggle('errore', errors.some((e) => !e.startsWith('Schema:')));
|
||||
highlightField.classList.toggle('errore', errors.some((e) => e.startsWith('Schema per le raccolte in evidenza:')));
|
||||
profileField.classList.toggle('errore', errors.some((e) => e.startsWith('Schema per le foto del profilo:')));
|
||||
fill(problems,
|
||||
errors.map((e) => h('p.errore-testo', icon('octagon-alert', 'xs'), ' ', e)),
|
||||
(preview.warnings || []).map((w) => h('p.avviso-testo', icon('triangle-alert', 'xs'), ' ', w)));
|
||||
@@ -131,7 +137,7 @@ export default async function general(page, box) {
|
||||
|
||||
const refresh = later(async () => {
|
||||
try {
|
||||
drawTree(await api('/api/settings/naming-preview', { method: 'POST', body: { namingScheme: form.naming, highlightScheme: form.highlight }, signal: page.signal }));
|
||||
drawTree(await api('/api/settings/naming-preview', { method: 'POST', body: { namingScheme: form.naming, highlightScheme: form.highlight, profilePictureScheme: form.profile }, signal: page.signal }));
|
||||
} catch (error) {
|
||||
if (error.name !== 'AbortError') showError(error);
|
||||
}
|
||||
@@ -139,6 +145,7 @@ export default async function general(page, box) {
|
||||
page.onLeave(() => refresh.cancel());
|
||||
naming.addEventListener('input', () => { form.naming = naming.value; drawSaveBar(); refresh(); });
|
||||
highlight.addEventListener('input', () => { form.highlight = highlight.value; drawSaveBar(); refresh(); });
|
||||
profile.addEventListener('input', () => { form.profile = profile.value; drawSaveBar(); refresh(); });
|
||||
|
||||
// ------------------------------------------------------------------------------------------- save bar
|
||||
function drawSaveBar() {
|
||||
@@ -157,6 +164,7 @@ export default async function general(page, box) {
|
||||
Object.assign(form, saved);
|
||||
naming.value = form.naming;
|
||||
highlight.value = form.highlight;
|
||||
profile.value = form.profile;
|
||||
setTime.input.checked = form.setFileTime;
|
||||
drawSaveBar();
|
||||
refresh();
|
||||
@@ -197,6 +205,7 @@ export default async function general(page, box) {
|
||||
h('div.colonna-nomi',
|
||||
h('label.etichetta', { for: 'schema' }, t('impostazioni.generali.schema')), namingField,
|
||||
h('label.etichetta', { for: 'schema-evidenza' }, t('impostazioni.generali.schemaEvidenza')), highlightField,
|
||||
h('label.etichetta', { for: 'schema-profilo' }, t('impostazioni.generali.schemaProfilo')), profileField,
|
||||
h('p.aiuto.segnaposto', t('impostazioni.generali.segnaposto', { elenco: data.placeholders.join(', ') })),
|
||||
problems,
|
||||
h('div.data-file', setTime)),
|
||||
|
||||
@@ -574,6 +574,7 @@
|
||||
"nomiAiuto": "Vale per i prossimi download: i file già salvati non vengono rinominati.",
|
||||
"schema": "Schema",
|
||||
"schemaEvidenza": "Schema per le raccolte in evidenza",
|
||||
"schemaProfilo": "Schema per le foto del profilo",
|
||||
"risultato": "Risultato",
|
||||
"segnaposto": "Segnaposto: {elenco}.",
|
||||
"dataFile": "Imposta la data del file a quella di pubblicazione",
|
||||
|
||||
@@ -89,6 +89,14 @@ public sealed class RecognizerTests
|
||||
Assert.AreEqual("Estate 2025", highlight.HighlightTitle);
|
||||
Assert.AreEqual("3391207", highlight.InstagramId);
|
||||
|
||||
// Profile pictures with the scheme of #38: their folder, no year folder; the code is a hash, not an identity.
|
||||
var picture = recognizers.Recognize(new ImportFileContext(layout, "profilo/2026-09-30_21-04-33_a3f9c2e1_1.jpg"));
|
||||
Assert.AreEqual("febe", picture.Recognizer);
|
||||
Assert.AreEqual(EntryKind.ProfilePicture, picture.Kind);
|
||||
Assert.AreEqual(new DateTimeOffset(2026, 9, 30, 19, 4, 33, TimeSpan.Zero), picture.Date);
|
||||
Assert.IsNull(picture.InstagramId);
|
||||
Assert.IsNull(picture.Code);
|
||||
|
||||
var instaloader = recognizers.Recognize(new ImportFileContext(layout, "2021-05-06_07-08-09_UTC_1.jpg"));
|
||||
Assert.IsNull(instaloader.Code, "«UTC» non è un codice.");
|
||||
Assert.AreEqual(new DateTimeOffset(2021, 5, 6, 7, 8, 9, TimeSpan.Zero), instaloader.Date);
|
||||
|
||||
@@ -110,7 +110,16 @@ public sealed class LibraryIngestTests
|
||||
var bytes = TestFile.PhotoBytes(40, 320, 320);
|
||||
var saved = await library.SaveAsync(account, Make.Entry(account.Id, "pp1", Make.T0, EntryKind.ProfilePicture), [new TestFile(Make.Photo(1), bytes, ".jpg")]);
|
||||
var sha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(bytes));
|
||||
Assert.AreEqual($"profilo/2026/2026-10-13_10-00-00_{sha[..8]}_1.jpg", saved.Media[0].RelativePath);
|
||||
Assert.AreEqual($"profilo/2026-10-13_10-00-00_{sha[..8]}_1.jpg", saved.Media[0].RelativePath);
|
||||
|
||||
// With a general scheme that puts everything in the account folder the pictures keep their own folder (#38).
|
||||
library.Ingest.Apply(LibraryNaming.Default with { General = NamingScheme.Parse(@"{account}\{data}_{codice}_{n}", NamingSchemeUse.General) }, true);
|
||||
var other = TestFile.PhotoBytes(41, 320, 320);
|
||||
var second = await library.SaveAsync(account, Make.Entry(account.Id, "pp2", Make.T0.AddDays(1), EntryKind.ProfilePicture), [new TestFile(Make.Photo(1), other, ".jpg")]);
|
||||
var otherSha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(other));
|
||||
Assert.AreEqual($"profilo/2026-10-14_10-00-00_{otherSha[..8]}_1.jpg", second.Media[0].RelativePath);
|
||||
var post = await library.SaveAsync(account, Make.Entry(account.Id, "p1", Make.T0) with { Code = "AbC1" }, [new TestFile(Make.Photo(1), TestFile.PhotoBytes(42, 320, 320), ".jpg")]);
|
||||
Assert.AreEqual("2026-10-13_AbC1_1.jpg", post.Media[0].RelativePath);
|
||||
|
||||
var video = await library.Db.Entries.AddAsync(Make.Entry(account.Id, "big", Make.T0), [Make.Video()]);
|
||||
await Assert.ThrowsExactlyAsync<FileTooLargeException>(() => library.Ingest.SaveMediaAsync(
|
||||
|
||||
@@ -135,6 +135,36 @@ public sealed class LibraryRebuildTests
|
||||
Assert.AreEqual(again.Media[0].RelativePath, (await library.Db.Media.ListByEntryAsync(restored.Id))[0].RelativePath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProfilePicturesComeBackFromTheirOwnFolder()
|
||||
{
|
||||
// #38: the pictures have their own scheme (no year folder, outside the general scheme); the rebuild reads them
|
||||
// from the journal wherever that scheme put them.
|
||||
using var temp = new TempFolder();
|
||||
await using var library = await TestLibrary.CreateAsync(temp);
|
||||
library.Ingest.Apply(LibraryNaming.Default with { ProfilePicture = NamingScheme.Parse(@"{account}\foto\{data}_{codice}", NamingSchemeUse.ProfilePicture) }, true);
|
||||
var marta = await library.Db.Accounts.AddAsync(Make.Account("marta.demo", "100"));
|
||||
var first = await library.SaveAsync(marta, Make.Entry(marta.Id, "pp1", Make.T0.AddDays(-30), EntryKind.ProfilePicture), [TestFile.Photo(1, 1)]);
|
||||
var second = await library.SaveAsync(marta, Make.Entry(marta.Id, "pp2", Make.T0, EntryKind.ProfilePicture), [TestFile.Photo(1, 2)]);
|
||||
StringAssert.StartsWith(first.Media[0].RelativePath, "foto/");
|
||||
|
||||
await library.LoseDatabaseAsync();
|
||||
var report = await new LibraryRebuilder(library.Db, library.Layout, library.Clock).RebuildAsync();
|
||||
|
||||
Assert.AreEqual(2, report.EntriesCreated);
|
||||
Assert.AreEqual(0, report.UntrackedFiles);
|
||||
var account = (await library.Db.Accounts.FindByInstagramIdAsync("100"))!;
|
||||
var pictures = await library.Db.Entries.ListByAccountAsync(account.Id, new EntryListOptions { Kind = EntryKind.ProfilePicture });
|
||||
Assert.HasCount(2, pictures);
|
||||
var paths = new List<string?>();
|
||||
foreach (var picture in pictures)
|
||||
{
|
||||
paths.AddRange((await library.Db.Media.ListByEntryAsync(picture.Id)).Select(m => m.RelativePath));
|
||||
}
|
||||
|
||||
CollectionAssert.AreEquivalent(new[] { first.Media[0].RelativePath, second.Media[0].RelativePath }, paths);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AnEmptyLibraryRebuildsNothing()
|
||||
{
|
||||
|
||||
@@ -24,6 +24,51 @@ public sealed class NamingSchemeTests
|
||||
|
||||
var highlight = NamingScheme.Highlight.RenderRelativePath(new NamingValues("marta.demo", EntryKind.Highlight, RomeTime(2025, 8, 2, 10, 11, 12), "3391207", 1, ".JPG", "Estate 2025"), Rome);
|
||||
Assert.AreEqual("evidenza/Estate 2025/2025-08-02_10-11-12_3391207_1.jpg", highlight);
|
||||
|
||||
// Profile pictures (#38): their own folder, no year folder, the start of the SHA-256 as the code.
|
||||
var picture = NamingScheme.ProfilePicture.RenderRelativePath(new NamingValues("marta.demo", EntryKind.ProfilePicture, RomeTime(2026, 9, 30, 21, 4, 33), "a3f9c2e1", 1, ".jpg"), Rome);
|
||||
Assert.AreEqual("profilo/2026-09-30_21-04-33_a3f9c2e1_1.jpg", picture);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProfilePicturesKeepTheirFolderWhateverTheGeneralSchemeSays()
|
||||
{
|
||||
// Alberto's decision on #38: the pictures stay in <account>\profilo, apart from posts and stories, even when the
|
||||
// general scheme puts everything in one folder.
|
||||
var flat = NamingScheme.Parse(@"{account}\{data}_{codice}_{n}", NamingSchemeUse.General);
|
||||
var naming = LibraryNaming.Default with { General = flat };
|
||||
var post = new Entry { AccountId = 1, Kind = EntryKind.Post, InstagramId = "321", Code = "DBx3kQ2", PublishedAt = Make.T0, DiscoveredAt = Make.T0 };
|
||||
var picture = post with { Kind = EntryKind.ProfilePicture };
|
||||
|
||||
Assert.AreSame(flat, naming.For(EntryKind.Post));
|
||||
Assert.AreSame(flat, naming.For(EntryKind.Story));
|
||||
Assert.AreSame(flat, naming.For(EntryKind.Tagged));
|
||||
Assert.AreSame(NamingScheme.Highlight, naming.For(EntryKind.Highlight));
|
||||
Assert.AreSame(NamingScheme.ProfilePicture, naming.For(EntryKind.ProfilePicture));
|
||||
Assert.AreEqual("2026-10-13_DBx3kQ2_1.jpg", naming.For(post.Kind).RenderRelativePath(NamingValues.For("marta.demo", post, 1, ".jpg"), Rome));
|
||||
Assert.AreEqual(
|
||||
"profilo/2026-10-13_10-00-00_00abcdef_1.jpg",
|
||||
naming.For(picture.Kind).RenderRelativePath(NamingValues.For("marta.demo", picture, 1, ".jpg", sha256: "00abcdef" + new string('0', 56)), Rome));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheSchemeOfProfilePicturesHasItsOwnRules()
|
||||
{
|
||||
Assert.IsEmpty(NamingScheme.Validate(NamingScheme.DefaultProfilePicture, NamingSchemeUse.ProfilePicture).Warnings);
|
||||
Assert.IsEmpty(NamingScheme.Validate(@"{account}\profilo\{data}_{codice}", NamingSchemeUse.ProfilePicture).Warnings, "{n} is always 1 for a profile picture.");
|
||||
|
||||
var withoutCode = NamingScheme.Validate(@"{account}\profilo\{data}_{n}", NamingSchemeUse.ProfilePicture);
|
||||
Assert.IsTrue(withoutCode.IsValid);
|
||||
StringAssert.Contains(withoutCode.Warnings.Single(), "Senza {codice} due foto del profilo");
|
||||
|
||||
var collection = NamingScheme.Validate(@"{account}\{raccolta}\{codice}", NamingSchemeUse.ProfilePicture);
|
||||
Assert.IsFalse(collection.IsValid);
|
||||
StringAssert.Contains(collection.Errors.Single(), "solo nello schema per le raccolte");
|
||||
|
||||
Assert.AreEqual(NamingSchemeUse.ProfilePicture, NamingScheme.ProfilePicture.Use);
|
||||
Assert.IsFalse(NamingScheme.ProfilePicture.ForHighlights);
|
||||
Assert.IsTrue(NamingScheme.Highlight.ForHighlights);
|
||||
Assert.AreSame(NamingScheme.ProfilePicture, NamingScheme.Default(NamingSchemeUse.ProfilePicture));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -139,28 +184,37 @@ public sealed class NamingSchemeTests
|
||||
[TestMethod]
|
||||
public void PreviewShowsTheTreeOfMockup08()
|
||||
{
|
||||
var preview = NamingPreview.Build(NamingScheme.DefaultGeneral, NamingScheme.DefaultHighlight, Rome, "marta.demo");
|
||||
var preview = NamingPreview.Build(NamingScheme.DefaultGeneral, NamingScheme.DefaultHighlight, NamingScheme.DefaultProfilePicture, Rome, "marta.demo");
|
||||
Assert.IsTrue(preview.IsValid);
|
||||
Assert.AreEqual("marta.demo", preview.AccountFolder);
|
||||
Assert.HasCount(3, preview.Folders);
|
||||
Assert.HasCount(4, preview.Folders);
|
||||
CollectionAssert.AreEqual(new[] { "post", "2026" }, preview.Folders[0].Path.ToArray());
|
||||
Assert.AreEqual(new NamingPreviewFile("2026-10-10_18-22-05_DBx3kQ2_2.jpg", MediaKind.Photo), preview.Folders[0].Files.Single());
|
||||
CollectionAssert.AreEqual(new[] { "storie", "2026" }, preview.Folders[1].Path.ToArray());
|
||||
Assert.AreEqual(new NamingPreviewFile("2026-10-13_09-41-07_3742118_1.mp4", MediaKind.Video), preview.Folders[1].Files.Single());
|
||||
CollectionAssert.AreEqual(new[] { "evidenza", "Estate 2025" }, preview.Folders[2].Path.ToArray());
|
||||
Assert.AreEqual("2025-08-02_10-11-12_3391207_1.jpg", preview.Folders[2].Files.Single().Name);
|
||||
CollectionAssert.AreEqual(new[] { "profilo" }, preview.Folders[3].Path.ToArray());
|
||||
Assert.AreEqual(new NamingPreviewFile("2026-09-30_21-04-33_a3f9c2e1_1.jpg", MediaKind.Photo), preview.Folders[3].Files.Single());
|
||||
|
||||
// The preview reads the same in any zone: sample times are local.
|
||||
var utc = NamingPreview.Build(NamingScheme.DefaultGeneral, NamingScheme.DefaultHighlight, TimeZoneInfo.Utc, "marta.demo");
|
||||
var utc = NamingPreview.Build(NamingScheme.DefaultGeneral, NamingScheme.DefaultHighlight, NamingScheme.DefaultProfilePicture, TimeZoneInfo.Utc, "marta.demo");
|
||||
Assert.AreEqual(preview.Folders[0].Files[0], utc.Folders[0].Files[0]);
|
||||
|
||||
var flat = NamingPreview.Build(@"{account}\{data}_{codice}_{n}", @"{account}\{raccolta}\{n}", Rome);
|
||||
var flat = NamingPreview.Build(@"{account}\{data}_{codice}_{n}", @"{account}\{raccolta}\{n}", @"{account}\foto-{codice}", Rome);
|
||||
Assert.HasCount(2, flat.Folders);
|
||||
Assert.HasCount(2, flat.Folders[0].Files);
|
||||
Assert.HasCount(3, flat.Folders[0].Files, "Post, story and profile picture all in the account folder.");
|
||||
|
||||
var broken = NamingPreview.Build("{account}\\{x}", NamingScheme.DefaultHighlight, Rome);
|
||||
var broken = NamingPreview.Build("{account}\\{x}", NamingScheme.DefaultHighlight, NamingScheme.DefaultProfilePicture, Rome);
|
||||
Assert.IsFalse(broken.IsValid);
|
||||
Assert.StartsWith("Schema: ", broken.Errors[0]);
|
||||
Assert.HasCount(1, broken.Folders);
|
||||
Assert.HasCount(2, broken.Folders);
|
||||
|
||||
// Every problem says which scheme it is about: the settings screen marks that field.
|
||||
var wrongProfile = NamingPreview.Build(NamingScheme.DefaultGeneral, NamingScheme.DefaultHighlight, @"{account}\{raccolta}", Rome);
|
||||
Assert.StartsWith(NamingPreview.Prefix(NamingSchemeUse.ProfilePicture), wrongProfile.Errors.Single());
|
||||
Assert.AreEqual("Schema per le foto del profilo: ", NamingPreview.Prefix(NamingSchemeUse.ProfilePicture));
|
||||
var noCode = NamingPreview.Build(NamingScheme.DefaultGeneral, NamingScheme.DefaultHighlight, @"{account}\profilo\{data}", Rome);
|
||||
Assert.StartsWith("Schema per le foto del profilo: Senza {codice}", noCode.Warnings.Single());
|
||||
}
|
||||
}
|
||||
@@ -27,12 +27,15 @@ public sealed class SettingsApiTests
|
||||
var general = await server.GetJsonAsync("/api/settings/general");
|
||||
Assert.AreEqual(NamingScheme.DefaultGeneral, general.Str("namingScheme"));
|
||||
Assert.AreEqual(NamingScheme.DefaultHighlight, general.Str("highlightScheme"));
|
||||
Assert.AreEqual(NamingScheme.DefaultProfilePicture, general.Str("profilePictureScheme"));
|
||||
Assert.AreEqual(NamingScheme.DefaultProfilePicture, general.Str("defaultProfilePictureScheme"));
|
||||
Assert.IsTrue(general.Bool("foldersReadOnly"), "Docker: folders change from the container");
|
||||
Assert.IsTrue(general.Bool("setFileTime"));
|
||||
Assert.AreEqual(JsonValueKindNull, general.GetProperty("autostart").ValueKind, "the «Avvio» block exists only on Windows");
|
||||
var preview = general.GetProperty("preview");
|
||||
Assert.AreEqual("marta.prova", preview.Str("accountFolder"));
|
||||
Assert.IsTrue(preview.Items("folders").Any(f => f.Items("files").Any(x => x.Str("name").EndsWith("_DBx3kQ2_2.jpg", StringComparison.Ordinal))));
|
||||
Assert.IsTrue(preview.Items("folders").Any(f => f.Items("path").Select(p => p.GetString()).SequenceEqual(["profilo"])), "the profile picture in its own folder");
|
||||
|
||||
var bad = await server.SendJsonAsync(HttpMethod.Post, "/api/settings/naming-preview", new { namingScheme = "{account}\\{sconosciuto}", highlightScheme = NamingScheme.DefaultHighlight });
|
||||
Assert.AreEqual(HttpStatusCode.OK, bad.Status);
|
||||
@@ -51,6 +54,40 @@ public sealed class SettingsApiTests
|
||||
var stored = await LibrarySettings.LoadAsync(server.Db.Settings, server.Library.Layout.Root);
|
||||
Assert.AreEqual(scheme, stored.Naming.General.Text);
|
||||
Assert.IsFalse(stored.SetFileTimeToPublication);
|
||||
Assert.AreEqual(NamingScheme.DefaultProfilePicture, stored.Naming.ProfilePicture.Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheSchemeOfProfilePicturesIsSavedApartAndKeptWhenNotSent()
|
||||
{
|
||||
await using var server = await Part2.StartAsync();
|
||||
const string profile = @"{account}\foto del profilo\{anno}\{data}_{codice}";
|
||||
var preview = await server.SendJsonAsync(HttpMethod.Post, "/api/settings/naming-preview",
|
||||
new { namingScheme = NamingScheme.DefaultGeneral, highlightScheme = NamingScheme.DefaultHighlight, profilePictureScheme = profile });
|
||||
Assert.IsTrue(preview.Body.Items("folders").Any(f => f.Items("path").Select(p => p.GetString()).SequenceEqual(["foto del profilo", "2026"])));
|
||||
|
||||
var wrong = await server.SendJsonAsync(HttpMethod.Post, "/api/settings/naming-preview",
|
||||
new { namingScheme = NamingScheme.DefaultGeneral, highlightScheme = NamingScheme.DefaultHighlight, profilePictureScheme = @"{account}\{raccolta}" });
|
||||
StringAssert.StartsWith(wrong.Body.Items("errors").Single().GetString(), "Schema per le foto del profilo:");
|
||||
|
||||
var (badStatus, error) = await server.SendJsonAsync(HttpMethod.Put, "/api/settings/general",
|
||||
new { namingScheme = NamingScheme.DefaultGeneral, highlightScheme = NamingScheme.DefaultHighlight, profilePictureScheme = @"{account}\{raccolta}", setFileTime = true });
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, badStatus);
|
||||
StringAssert.StartsWith(error.Str("message"), "Schema per le foto del profilo:");
|
||||
|
||||
var (okStatus, saved) = await server.SendJsonAsync(HttpMethod.Put, "/api/settings/general",
|
||||
new { namingScheme = NamingScheme.DefaultGeneral, highlightScheme = NamingScheme.DefaultHighlight, profilePictureScheme = profile, setFileTime = true });
|
||||
Assert.AreEqual(HttpStatusCode.OK, okStatus);
|
||||
Assert.AreEqual(profile, saved.Str("profilePictureScheme"));
|
||||
Assert.AreEqual(profile, (await LibrarySettings.LoadAsync(server.Db.Settings, server.Library.Layout.Root)).Naming.ProfilePicture.Text);
|
||||
|
||||
// A client that does not know the third scheme (or only changes a folder) does not reset it.
|
||||
const string general = @"{account}\{tipo}\{data}_{codice}_{n}";
|
||||
var (againStatus, again) = await server.SendJsonAsync(HttpMethod.Put, "/api/settings/general",
|
||||
new { namingScheme = general, highlightScheme = NamingScheme.DefaultHighlight, setFileTime = true });
|
||||
Assert.AreEqual(HttpStatusCode.OK, againStatus);
|
||||
Assert.AreEqual(general, again.Str("namingScheme"));
|
||||
Assert.AreEqual(profile, again.Str("profilePictureScheme"));
|
||||
}
|
||||
|
||||
private const System.Text.Json.JsonValueKind JsonValueKindNull = System.Text.Json.JsonValueKind.Null;
|
||||
|
||||
Reference in new issue
Block a user