strom-research 1.30.0-beta.3 → 1.30.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.cs.md +4 -3
- package/CHANGELOG.de.md +4 -3
- package/CHANGELOG.md +4 -3
- package/CHANGELOG.pl.md +4 -3
- package/README.md +4 -0
- package/dist/commands/error.js +3 -2
- package/dist/commands/fixchecks.js +6 -1
- package/dist/commands/fixes.js +1 -1
- package/dist/core/live.js +195 -33
- package/dist/core/liveged.js +49 -9
- package/dist/core/liveimages.js +121 -0
- package/dist/core/tree.js +1 -1
- package/dist/gedcom/export.js +10 -1
- package/dist/gedcom/validate.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.cs.md
CHANGED
|
@@ -7,7 +7,7 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
7
7
|
|
|
8
8
|
## 1.30.0
|
|
9
9
|
|
|
10
|
-
*Připravuje se: bety do 1.30.0-beta.
|
|
10
|
+
*Připravuje se: bety do 1.30.0-beta.4. Oddíl bude úplný s vydáním.*
|
|
11
11
|
|
|
12
12
|
- **Údaje ověřené proti originálu.** Narození, křest, sňatek, úmrtí nebo pohřeb, který cituje původní záznam, ale
|
|
13
13
|
zůstává pravděpodobný nebo možný, agent ověří proti tomu originálu: podívá se na sken a údaj buď povýší na doložený,
|
|
@@ -27,7 +27,7 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
27
27
|
ve stromu, agent nikdy nezmění: jen navrhne – ani souborem, který načte přes `strom sync`. Návrhy agenta jsou v `strom
|
|
28
28
|
conflict list` a `show` poznat a uzavřou se samy, jakmile navržená hodnota platí. Výzkum založený dřív se po
|
|
29
29
|
aktualizaci jednou označí (které údaje přišly z převzatého rodokmenu, které jsou uživatele): žádná hodnota se nemění a
|
|
30
|
-
`strom fixes undo origins` značky vezme zpět
|
|
30
|
+
`strom fixes undo origins` značky vezme zpět; kolik hodnot a v kolika záznamech se označilo, řekne `strom fixes show origins`. Návrh, jehož hodnota se od jeho vzniku změnila (upravil ji uživatel), je
|
|
31
31
|
zastaralý: přijmout ho nelze – přes novější hodnotu se nic nezapíše –, jen uzavřít s ponechanou hodnotou. Co návrh
|
|
32
32
|
neunese (příčina změněná spolu s datem), řekne výsledek synchronizace, nikdy se neztratí.
|
|
33
33
|
Hodnota, která přišla s rodokmenem z aplikace Strom a nikdo ji od té doby nezměnil, je chráněná jako hodnota uživatele.
|
|
@@ -48,7 +48,7 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
48
48
|
z rodokmenu do něj nejde – jména, místa, poznámky, přepisy, snímky, cesty se jménem uživatele, přihlášení a tokeny jsou
|
|
49
49
|
vynechané nebo nahrazené stálými kódy – a nic se neodesílá: soubor posílá uživatel sám, na adresu, kterou příkaz
|
|
50
50
|
vypíše. `--about fetch|sync|agent|install|windows` přidá podrobnosti jedné oblasti (tabulka je v `strom error
|
|
51
|
-
--help`), `--where` říká, kde se problém stal, `--note` ho popíše slovy uživatele; údaje jmenovaných osob, rodin nebo
|
|
51
|
+
--help`), `--where` říká, kde se problém stal, `--note` ho popíše slovy uživatele (jde tak, jak je napsaná – nahradí se jen jména, která výzkum zná); údaje jmenovaných osob, rodin nebo
|
|
52
52
|
knihy jen s `--with-data` a souhlasem uživatele. Agent požádaný o nahlášení problému se zeptá, kde se stal, příkaz
|
|
53
53
|
spustí a řekne cestu – soubor nikdy neposílá, neotvírá ani nepřepisuje do chatu. V nabídce: Údržba → Nahlásit problém.
|
|
54
54
|
Výzkum se jen čte, i rozbitý.
|
|
@@ -60,6 +60,7 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
60
60
|
mostu, a během sledování se změna ohlásí, až je její strom připravený. Most už neskončí, když je disk výzkumu na
|
|
61
61
|
chvíli nedostupný, a druhý most téhož výzkumu spuštěný navíc hned skončí a neběží dál bez povšimnutí.
|
|
62
62
|
Aplikaci, která nejnovější strom už má, se znovu nic neposílá.
|
|
63
|
+
Aplikace, která o to požádá, dostane strom s obrázky označenými podle obsahu a načte jen ty, které ještě nemá.
|
|
63
64
|
|
|
64
65
|
- **Údaj zobrazený nebo upravený v terminálu** (`strom event show`, `strom event edit`) se vypisuje v jazyce
|
|
65
66
|
výzkumu. V aplikaci Strom už rodokmen převzatý do výzkumu nemá jako odkaz celého rodokmenu první řádek z něj:
|
package/CHANGELOG.de.md
CHANGED
|
@@ -7,7 +7,7 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
7
7
|
|
|
8
8
|
## 1.30.0
|
|
9
9
|
|
|
10
|
-
*In Vorbereitung: die Betas bis 1.30.0-beta.
|
|
10
|
+
*In Vorbereitung: die Betas bis 1.30.0-beta.4. Der Abschnitt ist mit dem Release vollständig.*
|
|
11
11
|
|
|
12
12
|
- **Angaben am Original geprüft.** Angaben zu Geburt, Taufe, Heirat, Tod oder Begräbnis, die ihren ursprünglichen
|
|
13
13
|
Eintrag zitieren, aber wahrscheinlich oder möglich bleiben, prüft der Agent an diesem Original: er sieht sich den Scan
|
|
@@ -31,7 +31,7 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
31
31
|
einliest. Die Vorschläge des Agenten sind in `strom conflict list` und `show` erkennbar und schließen sich selbst,
|
|
32
32
|
sobald der vorgeschlagene Wert gilt. Eine früher angelegte Forschung wird nach dem Update einmal markiert (welche
|
|
33
33
|
Angaben aus einem übernommenen Stammbaum kamen, welche vom Benutzer sind): kein Wert ändert sich, und `strom fixes undo
|
|
34
|
-
origins` nimmt die Markierungen zurück
|
|
34
|
+
origins` nimmt die Markierungen zurück; wie viele Werte in wie vielen Datensätzen markiert wurden, sagt `strom fixes show origins`. Ein Vorschlag, dessen Wert sich seit seiner Entstehung geändert hat (vom
|
|
35
35
|
Benutzer bearbeitet), ist veraltet: Er lässt sich nicht annehmen – über den neueren Wert wird nichts geschrieben –, nur
|
|
36
36
|
mit dem behaltenen Wert schließen. Was ein Vorschlag nicht tragen kann (eine zusammen mit dem Datum geänderte Ursache),
|
|
37
37
|
nennt das Ergebnis der Synchronisation, es geht nie verloren.
|
|
@@ -56,7 +56,7 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
56
56
|
Notizen, Transkriptionen, Bilder, Pfade mit dem Namen des Benutzers, Anmeldungen und Tokens werden weggelassen oder
|
|
57
57
|
durch feste Codes ersetzt – und nichts wird gesendet: die Datei sendet der Benutzer selbst, an die Adresse, die der
|
|
58
58
|
Befehl nennt. `--about fetch|sync|agent|install|windows` fügt die Einzelheiten eines Bereichs hinzu (die Tabelle steht
|
|
59
|
-
in `strom error --help`), `--where` sagt, wo das Problem auftrat, `--note` beschreibt es mit den Worten des Benutzers;
|
|
59
|
+
in `strom error --help`), `--where` sagt, wo das Problem auftrat, `--note` beschreibt es mit den Worten des Benutzers (sie geht so, wie sie geschrieben ist – ersetzt werden nur Namen, die die Forschung kennt);
|
|
60
60
|
die Daten genannter Personen, Familien oder eines Buches nur mit `--with-data` und der Zustimmung des Benutzers. Um
|
|
61
61
|
eine Meldung gebeten, fragt der Agent, wo das Problem auftrat, führt den Befehl aus und nennt den Pfad – die Datei
|
|
62
62
|
sendet, öffnet und kopiert er nie in den Chat. Im Menü: Wartung → Ein Problem melden. Die Forschung wird nur gelesen,
|
|
@@ -71,6 +71,7 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
71
71
|
wenn das Laufwerk der Forschung kurz nicht erreichbar ist, und eine zusätzlich gestartete zweite Brücke derselben
|
|
72
72
|
Forschung endet sofort, statt unbemerkt weiterzulaufen.
|
|
73
73
|
Einer App, die den neuesten Stammbaum schon hat, wird nichts erneut gesendet.
|
|
74
|
+
Eine App, die darum bittet, bekommt den Stammbaum mit jedem Bild nach seinem Inhalt benannt und lädt nur die Bilder, die sie noch nicht hat.
|
|
74
75
|
|
|
75
76
|
- **Eine im Terminal gezeigte oder bearbeitete Angabe** (`strom event show`, `strom event edit`) erscheint in der
|
|
76
77
|
Sprache der Forschung. In der App Strom hat ein in die Forschung übernommener Stammbaum nicht mehr die erste Zeile
|
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,7 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
7
7
|
|
|
8
8
|
## 1.30.0
|
|
9
9
|
|
|
10
|
-
*In preparation: the betas up to 1.30.0-beta.
|
|
10
|
+
*In preparation: the betas up to 1.30.0-beta.4. The section is complete with the release.*
|
|
11
11
|
|
|
12
12
|
- **Facts checked against their originals.** A birth, a baptism, a marriage, a death or a burial that cites its
|
|
13
13
|
original record but stays probable or possible is verified by the agent against that original: it looks at the scan
|
|
@@ -29,7 +29,7 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
29
29
|
file it brings in with `strom sync`. The agent's proposals are told apart in `strom conflict list` and `show`, and
|
|
30
30
|
close by themselves once the value proposed holds. A research made before is marked once after the update (which
|
|
31
31
|
values came from an imported tree, which are the user's): no value changes, and `strom fixes undo origins` takes the
|
|
32
|
-
marks back. A proposal whose value has changed since it was made (the user edited it) is out of date: it cannot be
|
|
32
|
+
marks back; `strom fixes show origins` says how many values were marked and in how many records. A proposal whose value has changed since it was made (the user edited it) is out of date: it cannot be
|
|
33
33
|
taken – nothing is written over the newer value – only closed keeping the value. What a proposal cannot carry (a cause
|
|
34
34
|
changed together with a date) is said in the sync's result, never lost.
|
|
35
35
|
A value that came with the family tree from the Strom app and nobody has changed since is guarded as the user's own.
|
|
@@ -52,7 +52,7 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
52
52
|
paths with the user's name, logins and tokens are left out or masked to stable codes – and nothing is sent: the user
|
|
53
53
|
sends the file, to the address the command says. `--about fetch|sync|agent|install|windows` adds the details of one
|
|
54
54
|
area (the table is in `strom error --help`), `--where` says where the problem happened, `--note` says it in the user's
|
|
55
|
-
words; the data of named people, families or a book only with `--with-data` and the user's yes. Asked to report a
|
|
55
|
+
words (it goes as written – only names the research knows are replaced); the data of named people, families or a book only with `--with-data` and the user's yes. Asked to report a
|
|
56
56
|
problem, the agent asks where it happened, runs it and tells the path – it never sends, opens or copies the file. In
|
|
57
57
|
the menu: Maintenance → Report a problem. The research is only read, a broken one too.
|
|
58
58
|
|
|
@@ -64,6 +64,7 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
64
64
|
The bridge no longer ends when the research's disk is away for a moment, and a second bridge started for the same
|
|
65
65
|
research ends at once instead of running on unseen.
|
|
66
66
|
An app that has the newest tree already is sent nothing again.
|
|
67
|
+
An app that asks for it is sent the tree with each image named by its content, and loads only the images it does not have yet.
|
|
67
68
|
|
|
68
69
|
- **A fact shown or edited at the terminal** (`strom event show`, `strom event edit`) is said in the research's
|
|
69
70
|
language. In the Strom app, a family tree taken into the research no longer gives the first line of it as the
|
package/CHANGELOG.pl.md
CHANGED
|
@@ -7,7 +7,7 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
7
7
|
|
|
8
8
|
## 1.30.0
|
|
9
9
|
|
|
10
|
-
*W przygotowaniu: bety do 1.30.0-beta.
|
|
10
|
+
*W przygotowaniu: bety do 1.30.0-beta.4. Sekcja będzie kompletna z wydaniem.*
|
|
11
11
|
|
|
12
12
|
- **Dane sprawdzane z oryginałem.** Urodzenie, chrzest, ślub, zgon lub pochówek, który cytuje pierwotny zapis, ale
|
|
13
13
|
pozostaje prawdopodobny lub możliwy, agent sprawdzi z tym oryginałem: obejrzy skan i albo podniesie daną do
|
|
@@ -28,7 +28,7 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
28
28
|
aplikacji Strom lub w stromie, agent nigdy nie zmienia: tylko proponuje – również nie przez plik wczytany przez `strom
|
|
29
29
|
sync`. Propozycje agenta są rozpoznawalne w `strom conflict list` i `show` i zamykają się same, gdy proponowana
|
|
30
30
|
wartość już obowiązuje. Badanie założone wcześniej zostanie po aktualizacji raz oznaczone (które dane przyszły z
|
|
31
|
-
przejętego drzewa, które są użytkownika): żadna wartość się nie zmienia, a `strom fixes undo origins` cofa oznaczenia
|
|
31
|
+
przejętego drzewa, które są użytkownika): żadna wartość się nie zmienia, a `strom fixes undo origins` cofa oznaczenia; ile wartości i w ilu rekordach oznaczono, mówi `strom fixes show origins`.
|
|
32
32
|
Propozycja, której wartość zmieniła się od jej powstania (zmienił ją użytkownik), jest nieaktualna: nie można jej
|
|
33
33
|
przyjąć – nic nie zostanie zapisane na nowszej wartości – można ją tylko zamknąć, zachowując wartość. Czego propozycja
|
|
34
34
|
nie uniesie (przyczyna zmieniona razem z datą), mówi wynik synchronizacji, nigdy nie ginie.
|
|
@@ -51,7 +51,7 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
51
51
|
użytkownika, logowania i tokeny są pominięte lub zastąpione stałymi kodami – i nic nie jest wysyłane: plik wysyła sam
|
|
52
52
|
użytkownik, na adres podany przez polecenie. `--about fetch|sync|agent|install|windows` dodaje szczegóły jednego
|
|
53
53
|
obszaru (tabela jest w `strom error --help`), `--where` mówi, gdzie problem wystąpił, `--note` opisuje go słowami
|
|
54
|
-
użytkownika; dane wskazanych osób, rodzin lub księgi tylko z `--with-data` i za zgodą użytkownika. Poproszony
|
|
54
|
+
użytkownika (trafia tak, jak została napisana – zastępowane są tylko nazwy znane badaniu); dane wskazanych osób, rodzin lub księgi tylko z `--with-data` i za zgodą użytkownika. Poproszony
|
|
55
55
|
o zgłoszenie problemu agent pyta, gdzie wystąpił, uruchamia polecenie i podaje ścieżkę – pliku nigdy nie wysyła, nie
|
|
56
56
|
otwiera ani nie przepisuje do czatu. W menu: Konserwacja → Zgłosić problem. Badanie jest tylko czytane, także
|
|
57
57
|
uszkodzone.
|
|
@@ -64,6 +64,7 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
64
64
|
jest gotowe. Most nie kończy się już, gdy dysk badania jest na chwilę niedostępny, a drugi most tego samego badania
|
|
65
65
|
uruchomiony dodatkowo kończy się od razu, zamiast działać dalej niezauważony.
|
|
66
66
|
Aplikacji, która ma już najnowsze drzewo, nic nie jest wysyłane ponownie.
|
|
67
|
+
Aplikacja, która o to poprosi, dostaje drzewo z obrazami oznaczonymi według ich zawartości i wczytuje tylko te, których jeszcze nie ma.
|
|
67
68
|
|
|
68
69
|
- **Dana pokazana lub zmieniona w terminalu** (`strom event show`, `strom event edit`) jest wypisywana w języku
|
|
69
70
|
badania. W aplikacji Strom drzewo przejęte do badania nie ma już jako odnośnika całego drzewa pierwszego wiersza z
|
package/README.md
CHANGED
|
@@ -120,6 +120,10 @@ npm: `npm install -g strom-research@latest`. What is new in each version:
|
|
|
120
120
|
neither see nor click
|
|
121
121
|
- `strom doctor` checks everything strom needs and fixes it with your yes;
|
|
122
122
|
`strom uninstall` removes strom again (your research stays)
|
|
123
|
+
- `strom error` packs a report of a problem into one ZIP for you to send: the
|
|
124
|
+
people's names, places and notes replaced by codes, nothing sent by strom; a
|
|
125
|
+
note given with `--note` goes as written (only names the research knows are
|
|
126
|
+
replaced)
|
|
123
127
|
|
|
124
128
|
**Everywhere**
|
|
125
129
|
- Windows, macOS and Linux; strom brings its own official Node, needs no admin
|
package/dist/commands/error.js
CHANGED
|
@@ -79,14 +79,15 @@ register({
|
|
|
79
79
|
"bridge to the Strom app, the research in numbers only (counts, strom check, git, downloads, sessions) and strom's\n" +
|
|
80
80
|
"technical logs of the last days, with the commands that ended with an error. Names, places, notes, paths with the\n" +
|
|
81
81
|
"user's name and e-mails are replaced by codes; logins, keys and tokens never go. The ZIP goes to the downloads\n" +
|
|
82
|
-
"folder (else the current one); strom sends nothing — the user sends it. Nothing in the research is written
|
|
82
|
+
"folder (else the current one); strom sends nothing — the user sends it. Nothing in the research is written. A note\n" +
|
|
83
|
+
"(--note) goes as written: only names the research knows are replaced in it.\n" +
|
|
83
84
|
"\n" +
|
|
84
85
|
REPORT_TABLE,
|
|
85
86
|
options: [
|
|
86
87
|
{ name: "about", type: "string", multiple: true, value: "<area>", description: "details of an area too: fetch, sync, agent, install, windows" },
|
|
87
88
|
{ name: "since", type: "string", value: "<2d|1w|YYYY-MM-DD>", description: "how far back the logs go (default 7 days)" },
|
|
88
89
|
{ name: "where", type: "string", value: "<chat|terminal|app|unknown>", description: "where the problem happened, as the user says: chat (a conversation with an agent), terminal (strom without an agent), app (the Strom app), unknown" },
|
|
89
|
-
{ name: "note", type: "string", value: "<text>", max: 2000, description: "the problem in the user's own words
|
|
90
|
+
{ name: "note", type: "string", value: "<text>", max: 2000, description: "the problem in the user's own words: it goes as written — only names the research knows are replaced by codes, so the user writes no name or place to keep private" },
|
|
90
91
|
{ name: "with-data", type: "boolean", description: "add the data of the persons, families and books named (names, facts, citations, how sure each is — no images, notes or transcripts) as data.json; the person is asked" },
|
|
91
92
|
{ name: "person", type: "string", multiple: true, value: "<P…>", description: "with --with-data: a person the problem is about" },
|
|
92
93
|
{ name: "family", type: "string", multiple: true, value: "<F…>", description: "with --with-data: a family the problem is about" },
|
|
@@ -847,7 +847,12 @@ export const ORIGINS = {
|
|
|
847
847
|
agentWork: true,
|
|
848
848
|
detect: (tree) => {
|
|
849
849
|
const f = originFixes(tree);
|
|
850
|
-
|
|
850
|
+
// marked by itself (at the start of this strom, or once more for the family tree's values): how many, and examples
|
|
851
|
+
const marks = f.fixes.length ? [] : originsDone(tree).filter((m) => m.kind !== "source" && m.kind !== "ids");
|
|
852
|
+
const owners = new Set(marks.map((m) => (m.kind === "fact" ? m.owner : m.kind === "name" || m.kind === "sex" ? m.person : "")));
|
|
853
|
+
const people = new Set(marks.flatMap((m) => (m.kind === "name" || m.kind === "sex" ? [m.person] : m.kind === "fact" && m.owner.startsWith("P") ? [m.owner] : [])));
|
|
854
|
+
const done = marks.length ? { count: marks.length, records: owners.size, people: people.size, items: marks, unit: "marks" } : undefined;
|
|
855
|
+
return { items: [], exact: 0, estimated: 0, unjudged: 0, readings: 0, rewrites: f.fixes, unsplit: 0, left: [], ...(done ? { done } : {}) };
|
|
851
856
|
},
|
|
852
857
|
applied: (tree) => originsDone(tree).length,
|
|
853
858
|
};
|
package/dist/commands/fixes.js
CHANGED
|
@@ -399,7 +399,7 @@ function stateData(ctx, tree, s, all = false) {
|
|
|
399
399
|
unsplit: s.found.unsplit ?? 0,
|
|
400
400
|
...(s.found.towns ? { bare: townCount(s.found) } : {}),
|
|
401
401
|
},
|
|
402
|
-
...(done ? { done: { facts: done.count, people: done.people, tasks: done.records, ...(done.at ? { at: done.at } : {}) } } : {}),
|
|
402
|
+
...(done ? { done: done.unit === "marks" ? { marks: done.count, records: done.records, people: done.people } : { facts: done.count, people: done.people, tasks: done.records, ...(done.at ? { at: done.at } : {}) } } : {}),
|
|
403
403
|
items: all ? shown : shown.slice(0, EXAMPLES),
|
|
404
404
|
...(s.found.left ? { left: all ? s.found.left : s.found.left.slice(0, EXAMPLES) } : {}),
|
|
405
405
|
// municipalities with numbers alone after the name: set right only on a person's answer for each (strom fixes run)
|
package/dist/core/live.js
CHANGED
|
@@ -46,8 +46,22 @@
|
|
|
46
46
|
// ETag (feature ged.etag) told by the head and the variant (none for a file with images left
|
|
47
47
|
// for later); If-None-Match naming it: 304, no body, nothing made or waited for (with ?stale=1
|
|
48
48
|
// the older one's ETag, its 304 still X-Strom-Stale); ETag and X-Strom-* shown to the app's page
|
|
49
|
-
// (Access-Control-Expose-Headers), If-None-Match let through its preflight
|
|
50
|
-
//
|
|
49
|
+
// (Access-Control-Expose-Headers), If-None-Match let through its preflight.
|
|
50
|
+
// ?images=ref (feature ged.imagesByHash, spec 071): each excerpt by reference, not in the file —
|
|
51
|
+
// 2 FILE strom-image:<sha256 of the JPEG's bytes> with 3 _MIME, _WIDTH, _HEIGHT, _BYTES; a variant
|
|
52
|
+
// of its own (its own ETag, with ?stale=1 too), its images kept by their hashes as it is made
|
|
53
|
+
// (.strom/cache/live-images: those the kept files name and those of the last hour, the rest
|
|
54
|
+
// go); X-Strom-Images: ref | data says which file came (another value asked: data, as always);
|
|
55
|
+
// packed (Content-Encoding: gzip, once for each file) for an app that takes it (Accept-Encoding),
|
|
56
|
+
// the file with its images in it never (an older app gets it as always)
|
|
57
|
+
// GET <token>/image/<sha256> one image the file names by reference: the JPEG, Cache-Control private, a year, immutable,
|
|
58
|
+
// ETag its hash (If-None-Match: 304); never made because it is asked for — 404 image.unknown
|
|
59
|
+
// (the app takes the file with its images in it), 400 image.sha
|
|
60
|
+
// POST <token>/images several: {"images": [sha256…]} (1–IMAGES_AT_ONCE) → {images: [{sha, mime, bytes, data (base64)}],
|
|
61
|
+
// missing: [not here], more: [not in this answer, its size reached: asked again]}; read only,
|
|
62
|
+
// with its Content-Length (one cut short is no answer), never packed (base64 of JPEGs packs
|
|
63
|
+
// little and slowly: the app waits longer for a packed one); 400 images.body
|
|
64
|
+
// GET <token>/images.ged the same as tree.ged (the address an older strom gave)
|
|
51
65
|
// GET <token>/log what the research saved, newest first (each commit: when, what, for which task;
|
|
52
66
|
// text: its lines as the user reads them, kinds: what each is about, sources: the S… each
|
|
53
67
|
// names — only when one does; head: the change, as strom history back and the link back take
|
|
@@ -419,6 +433,7 @@ import { opsLogsOf } from "./opslog.js";
|
|
|
419
433
|
import { placeOfWork } from "./workplace.js";
|
|
420
434
|
import { notDownloaded } from "./integrity.js";
|
|
421
435
|
import fs from "node:fs";
|
|
436
|
+
import zlib from "node:zlib";
|
|
422
437
|
import os from "node:os";
|
|
423
438
|
import http from "node:http";
|
|
424
439
|
import path from "node:path";
|
|
@@ -441,6 +456,7 @@ import { orderMode, orderNumbers, workOrder } from "./order.js";
|
|
|
441
456
|
import { phrase } from "./phrases.js";
|
|
442
457
|
import { excerptLevel, excerptSizes, INPUT_MARK, LEVELS, turned } from "./excerpt.js";
|
|
443
458
|
import { endWork, excerptAnswer, excerptOnThread, fixesOnThread, gedOnThread, gedVariant, storedGed, storeGed, tidyStoredGeds, widgetOnThread } from "./liveged.js";
|
|
459
|
+
import { IMAGE_MIME, IMAGE_SHA, imageFile, readImage } from "./liveimages.js";
|
|
444
460
|
import { isStatusPart, splitStatus, StatusKeeper, STATUS_PARTS } from "./livestatus.js";
|
|
445
461
|
import { adoptedAt, adoptedEmpty, adoptionWait, noteAdoptAsked, markSentAgain, undoneSend, undoneSince, failReceived, inboxTrees, markAdopted, noteAdoptFailed, noteNothingSent, pendingAdoption, receiveAdopted, receivedAll, receivedPending, receiveTree, recentSends, stampAppVersion, syncConflicts, SYNC_INBOX, SYNC_MAX_BYTES, namesOf } from "./sync.js";
|
|
446
462
|
import { isArchive, modeOf, settleArchive } from "./mode.js";
|
|
@@ -463,6 +479,12 @@ import { BATCH_ID, batchEstimate, batchLimits, batchPath, batchStatus, idleBatch
|
|
|
463
479
|
const LIVE_IMAGES_MS = 20_000;
|
|
464
480
|
/** The trees for the app kept in memory, one for each variant (two windows of two versions of the app). */
|
|
465
481
|
const GEDS_KEPT = 2;
|
|
482
|
+
/** The images of the tree's file asked at once (POST /images): at most so many hashes. */
|
|
483
|
+
export const IMAGES_AT_ONCE = 500;
|
|
484
|
+
/** …and an answer holds at most so many bytes of them (the rest asked again: `more`). */
|
|
485
|
+
export const IMAGES_ANSWER_BYTES = 8 * 1024 * 1024;
|
|
486
|
+
/** An image by its hash never changes: the browser keeps it a year (it is private: the bridge's address is secret). */
|
|
487
|
+
const IMAGE_CACHE = "private, max-age=31536000, immutable";
|
|
466
488
|
/**
|
|
467
489
|
* How long a change waits to be told while the tree for the app that follows it is made (the app then loads it at
|
|
468
490
|
* once, the tree it shows meanwhile the one before): told without it after so long (STROM_LIVE_CHANGE_WAIT_MS).
|
|
@@ -1300,7 +1322,28 @@ function idsOf(applied, known) {
|
|
|
1300
1322
|
* What the tree's file answers carry beside it: not kept by the browser (the app keeps its tree), and the headers the
|
|
1301
1323
|
* app on its own page reads (CORS shows a page only those named): its ETag, the head it is of, an older one's marks.
|
|
1302
1324
|
*/
|
|
1303
|
-
const GED_HEADERS = { "Cache-Control": "no-store", "Access-Control-Expose-Headers": "ETag, X-Strom-Head, X-Strom-Stale, X-Strom-Head-Now" };
|
|
1325
|
+
const GED_HEADERS = { "Cache-Control": "no-store", "Access-Control-Expose-Headers": "ETag, X-Strom-Head, X-Strom-Stale, X-Strom-Head-Now, X-Strom-Images" };
|
|
1326
|
+
/** The client takes a packed answer (Accept-Encoding: gzip, not refused by q=0). */
|
|
1327
|
+
function takesGzip(req) {
|
|
1328
|
+
return String(req.headers["accept-encoding"] ?? "")
|
|
1329
|
+
.split(",")
|
|
1330
|
+
.some((part) => {
|
|
1331
|
+
const [name, ...params] = part.trim().toLowerCase().split(";");
|
|
1332
|
+
return (name === "gzip" || name === "*") && !params.some((x) => /^\s*q\s*=\s*0(\.0*)?\s*$/u.test(x));
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
/** Vary of a packed answer: what it varied by already (the page asking: Origin) and Accept-Encoding. */
|
|
1336
|
+
function varyGzip(res) {
|
|
1337
|
+
return [res.getHeader("Vary"), "Accept-Encoding"].filter((x) => x !== undefined && x !== "").join(", ");
|
|
1338
|
+
}
|
|
1339
|
+
/** Bytes packed by gzip off the bridge's own thread (zlib's pool). */
|
|
1340
|
+
function gzipped(bytes, level) {
|
|
1341
|
+
return new Promise((resolve, reject) => zlib.gzip(bytes, { level }, (e, out) => (e ? reject(e) : resolve(out))));
|
|
1342
|
+
}
|
|
1343
|
+
/** How the tree's file is asked to carry its images: ?images=ref by reference (spec 071), anything else in it as always. */
|
|
1344
|
+
function imagesAsked(req) {
|
|
1345
|
+
return new URLSearchParams((req.url ?? "").split("?")[1] ?? "").get("images") === "ref" ? "ref" : "data";
|
|
1346
|
+
}
|
|
1304
1347
|
/** The ETag of the tree's file for the app (feature ged.etag): told by the research's head and the file's variant alone. */
|
|
1305
1348
|
export function gedTag(head, variant) {
|
|
1306
1349
|
return `"${crypto.createHash("sha256").update(`${head}\n${variant}`, "utf8").digest("hex").slice(0, 32)}"`;
|
|
@@ -1315,7 +1358,7 @@ export function tagMatches(req, tag) {
|
|
|
1315
1358
|
.map((t) => t.trim().replace(/^W\//u, ""))
|
|
1316
1359
|
.some((t) => t === "*" || t === tag);
|
|
1317
1360
|
}
|
|
1318
|
-
export const BRIDGE_FEATURES = ["sync.again", "sync.undoneSince", "sync.takenBack", "sync.conflictEdit", "sync.since", "sync.ids", "family.noCouple", "family.alone", "adopt.transfer", "adopt.empty", "material.list", "person.titles", "media.codes", "hypothesis.links", "status.recent", "spend.readers", "hypothesis.intree", "archive.permission", "task.check", "waiting.groups", "waiting.sent", "waiting.note", "batch.kept", "live.end", "whats.new", "terminal.choice", "person.marriedSurname", "phone", "read.now", "read.sync", "excerpt.get", "log.sources", "material.assign", "material.thumb", "seal.foreign", "tree.state", "disk.full", "tree.notDownloaded", "sync.removed", "tree.kind", "experiments", "experiments.off", "experiments.link", "experiments.split", "history.events", "history.hide", "experiments.pace", "history.first", "history.regions", "history.hide.all", "history.skip", "history.map", "history.delete", "history.delete.restore", "stories.history", "history.place", "surnames.suggest", "surnames.read", "lineage.read", "duplicates.judge", "quality.dismiss", "quality.read", "person.primary", "fixes.list", "fixes.towns", "history.back", "places.identify", "places.answer", "places.undo", "tasks.offLine", "status.busy", "history.kinds", "history.align", "places.nameKinds", "directions.edit", "directions.order", "directions.found", "directions.people", "offLine.branches", "queue.own", "story.sources", "queue.page", "status.parts", "waiting.answer", "browser.state", "working.place", "working.family", "hypotheses.decide", "sources.confirm", "read.sourceTask", "read.sourceTask.unsure", "read.choose", "read.choices.now", "read.source", "read.sourceEntry", "read.blindText", "read.kinds", "read.variantKind", "read.readerState", "live.idle", "live.stop", "live.start", "sources.proposal", "sources.proposal.undo", "origin", "origin.ids", "verify", "verify.bulk", "facts.confirm", "verify.stop", "ged.stale", "facts.confirm.value", "ged.etag"];
|
|
1361
|
+
export const BRIDGE_FEATURES = ["sync.again", "sync.undoneSince", "sync.takenBack", "sync.conflictEdit", "sync.since", "sync.ids", "family.noCouple", "family.alone", "adopt.transfer", "adopt.empty", "material.list", "person.titles", "media.codes", "hypothesis.links", "status.recent", "spend.readers", "hypothesis.intree", "archive.permission", "task.check", "waiting.groups", "waiting.sent", "waiting.note", "batch.kept", "live.end", "whats.new", "terminal.choice", "person.marriedSurname", "phone", "read.now", "read.sync", "excerpt.get", "log.sources", "material.assign", "material.thumb", "seal.foreign", "tree.state", "disk.full", "tree.notDownloaded", "sync.removed", "tree.kind", "experiments", "experiments.off", "experiments.link", "experiments.split", "history.events", "history.hide", "experiments.pace", "history.first", "history.regions", "history.hide.all", "history.skip", "history.map", "history.delete", "history.delete.restore", "stories.history", "history.place", "surnames.suggest", "surnames.read", "lineage.read", "duplicates.judge", "quality.dismiss", "quality.read", "person.primary", "fixes.list", "fixes.towns", "history.back", "places.identify", "places.answer", "places.undo", "tasks.offLine", "status.busy", "history.kinds", "history.align", "places.nameKinds", "directions.edit", "directions.order", "directions.found", "directions.people", "offLine.branches", "queue.own", "story.sources", "queue.page", "status.parts", "waiting.answer", "browser.state", "working.place", "working.family", "hypotheses.decide", "sources.confirm", "read.sourceTask", "read.sourceTask.unsure", "read.choose", "read.choices.now", "read.source", "read.sourceEntry", "read.blindText", "read.kinds", "read.variantKind", "read.readerState", "live.idle", "live.stop", "live.start", "sources.proposal", "sources.proposal.undo", "origin", "origin.ids", "verify", "verify.bulk", "facts.confirm", "verify.stop", "ged.stale", "facts.confirm.value", "ged.etag", "ged.imagesByHash"];
|
|
1319
1362
|
/**
|
|
1320
1363
|
* What the bridge says it does to the app of that version: BRIDGE_FEATURES, but origin.ids only where its /tree.ged
|
|
1321
1364
|
* carries the original IDs (the gate of the origins, the same version of the app as the file goes by) — an app that is
|
|
@@ -2373,7 +2416,7 @@ export function serveLive(root, env) {
|
|
|
2373
2416
|
};
|
|
2374
2417
|
// the app's version the tree was last asked for by: made for it again when a commit comes, before the change is told
|
|
2375
2418
|
// (a bridge taking over from one of an older strom: the version the app asked that one with)
|
|
2376
|
-
let gedFollow = env.STROM_LIVE_GED_FOR !== undefined ? { version: env.STROM_LIVE_GED_FOR || undefined } : undefined;
|
|
2419
|
+
let gedFollow = env.STROM_LIVE_GED_FOR !== undefined ? { version: env.STROM_LIVE_GED_FOR || undefined, ...(env.STROM_LIVE_GED_IMAGES === "ref" ? { images: "ref" } : {}) } : undefined;
|
|
2377
2420
|
// a change told once the tree that goes with it is made (sayChange: set once the bridge listens)
|
|
2378
2421
|
let sayChange;
|
|
2379
2422
|
// the files kept on disk written one after another
|
|
@@ -2536,12 +2579,31 @@ export function serveLive(root, env) {
|
|
|
2536
2579
|
* The tree for the app as it is now (at its head; made again for another head, version of the app or links), with its
|
|
2537
2580
|
* ETag (feature ged.etag): the app that has it already (If-None-Match) gets 304 and no body.
|
|
2538
2581
|
*/
|
|
2539
|
-
const giveGed = async (req, res, version) => {
|
|
2540
|
-
const made = await makeGed(version);
|
|
2582
|
+
const giveGed = async (req, res, version, images) => {
|
|
2583
|
+
const made = await makeGed(version, images);
|
|
2541
2584
|
const tag = gedTagOf(made);
|
|
2542
2585
|
if (tag && tagMatches(req, tag))
|
|
2543
|
-
return void res.writeHead(304, { ...GED_HEADERS, ETag: tag, "X-Strom-Head": made.head }).end();
|
|
2544
|
-
|
|
2586
|
+
return void res.writeHead(304, { ...GED_HEADERS, ETag: tag, "X-Strom-Head": made.head, "X-Strom-Images": images }).end();
|
|
2587
|
+
await sendGed(req, res, made, images, { ...(tag ? { ETag: tag } : {}), "X-Strom-Head": made.head });
|
|
2588
|
+
};
|
|
2589
|
+
// the file by reference packed once (gzip): what the app loads after each change is a few per cent of the whole file
|
|
2590
|
+
const packed = new WeakMap();
|
|
2591
|
+
/**
|
|
2592
|
+
* A tree's file for the app given: the one by reference packed (Content-Encoding: gzip) for an app that takes it
|
|
2593
|
+
* (Accept-Encoding: gzip; a browser always does), the whole file as always (an older app gets nothing new).
|
|
2594
|
+
*/
|
|
2595
|
+
const sendGed = async (req, res, made, images, extra) => {
|
|
2596
|
+
const head = { "Content-Type": "text/plain; charset=utf-8", ...GED_HEADERS, ...extra, "X-Strom-Images": images };
|
|
2597
|
+
if (images === "ref" && takesGzip(req)) {
|
|
2598
|
+
let gz = packed.get(made);
|
|
2599
|
+
if (!gz)
|
|
2600
|
+
packed.set(made, (gz = gzipped(made.bytes, 6)));
|
|
2601
|
+
const bytes = await gz;
|
|
2602
|
+
if (res.destroyed)
|
|
2603
|
+
return;
|
|
2604
|
+
return void res.writeHead(200, { ...head, "Content-Encoding": "gzip", Vary: varyGzip(res), "Content-Length": String(bytes.length) }).end(bytes);
|
|
2605
|
+
}
|
|
2606
|
+
res.writeHead(200, { ...head, ...(images === "ref" ? { Vary: varyGzip(res) } : {}), "Content-Length": String(made.bytes.length) }).end(made.bytes);
|
|
2545
2607
|
};
|
|
2546
2608
|
// the variant each file made is of (its ETag is told by its head and variant)
|
|
2547
2609
|
const madeFor = new WeakMap();
|
|
@@ -2554,22 +2616,22 @@ export function serveLive(root, env) {
|
|
|
2554
2616
|
* The app has the tree of the head now already (If-None-Match its ETag): 304 at once, nothing made, nothing waited for
|
|
2555
2617
|
* — but only for a file made whole (one with images left for later has no ETag the app could hold).
|
|
2556
2618
|
*/
|
|
2557
|
-
const gedUnchanged = (req, res, version) => {
|
|
2619
|
+
const gedUnchanged = (req, res, version, images) => {
|
|
2558
2620
|
if (!req.headers["if-none-match"])
|
|
2559
2621
|
return false;
|
|
2560
2622
|
const h = head(root);
|
|
2561
|
-
const { variant } = variantOf(version);
|
|
2623
|
+
const { variant } = variantOf(version, images);
|
|
2562
2624
|
const tag = gedTag(h, variant);
|
|
2563
2625
|
if (!tagMatches(req, tag))
|
|
2564
2626
|
return false;
|
|
2565
|
-
res.writeHead(304, { ...GED_HEADERS, ETag: tag, "X-Strom-Head": h }).end();
|
|
2627
|
+
res.writeHead(304, { ...GED_HEADERS, ETag: tag, "X-Strom-Head": h, "X-Strom-Images": images }).end();
|
|
2566
2628
|
return true;
|
|
2567
2629
|
};
|
|
2568
2630
|
/** What a tree's file for the app of that version is made by beyond the head (core/liveged.ts gedVariant). */
|
|
2569
|
-
const variantOf = (version) => {
|
|
2631
|
+
const variantOf = (version, images = "data") => {
|
|
2570
2632
|
const offered = links(env);
|
|
2571
2633
|
const opens = appOpensLinks(new Settings(env, {}), version) ? offered.join(" ") : "";
|
|
2572
|
-
return { offered, variant: gedVariant(root, env, version, opens) };
|
|
2634
|
+
return { offered, variant: gedVariant(root, env, version, opens, images) };
|
|
2573
2635
|
};
|
|
2574
2636
|
// the file being made now and what for (one at a time: the requests for the same wait for it together)
|
|
2575
2637
|
let making;
|
|
@@ -2579,10 +2641,10 @@ export function serveLive(root, env) {
|
|
|
2579
2641
|
* answering everything else meanwhile, and kept on disk — but a file with images left for later (the time to make
|
|
2580
2642
|
* them ran out), made again next time.
|
|
2581
2643
|
*/
|
|
2582
|
-
const makeGed = async (version) => {
|
|
2644
|
+
const makeGed = async (version, images = "data") => {
|
|
2583
2645
|
for (;;) {
|
|
2584
2646
|
const h = head(root);
|
|
2585
|
-
const { offered, variant } = variantOf(version);
|
|
2647
|
+
const { offered, variant } = variantOf(version, images);
|
|
2586
2648
|
// made again for another version of the app (two windows, two versions: each gets what it reads)
|
|
2587
2649
|
const kept = geds.get(variant);
|
|
2588
2650
|
if (kept && kept.head === h) {
|
|
@@ -2602,7 +2664,7 @@ export function serveLive(root, env) {
|
|
|
2602
2664
|
madeFor.set(stored, variant);
|
|
2603
2665
|
return stored;
|
|
2604
2666
|
}
|
|
2605
|
-
const made = await gedOnThread({ root, env, head: h, version, links: offered, budgetMs: LIVE_IMAGES_MS });
|
|
2667
|
+
const made = await gedOnThread({ root, env, head: h, version, links: offered, budgetMs: LIVE_IMAGES_MS, ...(images === "ref" ? { images } : {}) });
|
|
2606
2668
|
madeFor.set(made, variant);
|
|
2607
2669
|
if (made.head === h && !made.left.sources.some((x) => x.omitted.why === "later"))
|
|
2608
2670
|
storing = storing.then(() => storeGed(root, variant, made)).catch((e) => noteLive(root, `the tree's file not kept on disk: ${errorText(e)}`));
|
|
@@ -2629,24 +2691,114 @@ export function serveLive(root, env) {
|
|
|
2629
2691
|
* made meanwhile and told by the event change (from the head the app has). Nothing made of its variant yet (the first
|
|
2630
2692
|
* time, another strom or app): made now, as without it.
|
|
2631
2693
|
*/
|
|
2632
|
-
const giveStale = async (req, res, version) => {
|
|
2694
|
+
const giveStale = async (req, res, version, images) => {
|
|
2633
2695
|
const h = head(root);
|
|
2634
|
-
const { variant } = variantOf(version);
|
|
2696
|
+
const { variant } = variantOf(version, images);
|
|
2635
2697
|
const older = geds.get(variant) ?? (await storedGed(root, env, variant));
|
|
2636
2698
|
if (older)
|
|
2637
2699
|
madeFor.set(older, variant);
|
|
2638
2700
|
if (older?.head === h)
|
|
2639
2701
|
keepGed(variant, older);
|
|
2640
2702
|
if (!older || older.head === h)
|
|
2641
|
-
return afterQuiet(() => giveGed(req, res, version).catch((e) => failed(req, res, e)));
|
|
2703
|
+
return afterQuiet(() => giveGed(req, res, version, images).catch((e) => failed(req, res, e)));
|
|
2642
2704
|
// the older one with its own ETag: the app holding it already gets 304 (still told it is older), the new one made
|
|
2643
2705
|
const tag = gedTagOf(older);
|
|
2644
|
-
const stale = { "X-Strom-Head": older.head, "X-Strom-Stale": "1", "X-Strom-Head-Now": h };
|
|
2706
|
+
const stale = { "X-Strom-Head": older.head, "X-Strom-Stale": "1", "X-Strom-Head-Now": h, "X-Strom-Images": images };
|
|
2645
2707
|
if (tag && tagMatches(req, tag))
|
|
2646
2708
|
res.writeHead(304, { ...GED_HEADERS, ETag: tag, ...stale }).end();
|
|
2647
2709
|
else
|
|
2648
|
-
|
|
2649
|
-
afterQuiet(() => makeGed(version).then((made) => sayChange?.(older.head, made.head), (e) => noteLive(root, `the tree for the app not made: ${errorText(e)}`)));
|
|
2710
|
+
await sendGed(req, res, older, images, { ...(tag ? { ETag: tag } : {}), ...stale });
|
|
2711
|
+
afterQuiet(() => makeGed(version, images).then((made) => sayChange?.(older.head, made.head), (e) => noteLive(root, `the tree for the app not made: ${errorText(e)}`)));
|
|
2712
|
+
};
|
|
2713
|
+
/**
|
|
2714
|
+
* One image of the tree's file by its hash (GET /image/<sha256>, spec 071): its JPEG as kept when a file was made
|
|
2715
|
+
* with it (core/liveimages.ts) — never made because it is asked for. Unchanging (its content is its name): kept by
|
|
2716
|
+
* the browser for a year, ETag its hash (If-None-Match: 304). Refused: 400 image.sha, 404 image.unknown (not here:
|
|
2717
|
+
* the app takes the whole file instead).
|
|
2718
|
+
*/
|
|
2719
|
+
const giveImage = async (req, res, sha) => {
|
|
2720
|
+
const json = (code, body) => void res.writeHead(code, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" }).end(JSON.stringify(body));
|
|
2721
|
+
if (!IMAGE_SHA.test(sha))
|
|
2722
|
+
return json(400, refusal("/image/<sha256>: the 64 hex of an image the tree's file names (2 FILE strom-image:…)", "image.sha", { sha: sha.slice(0, 64) }));
|
|
2723
|
+
const tag = `"${sha}"`;
|
|
2724
|
+
const headers = { "Cache-Control": IMAGE_CACHE, ETag: tag, "Access-Control-Expose-Headers": "ETag" };
|
|
2725
|
+
// the browser has it (its name is its content): nothing read
|
|
2726
|
+
if (tagMatches(req, tag) && fs.existsSync(imageFile(root, sha)))
|
|
2727
|
+
return void res.writeHead(304, headers).end();
|
|
2728
|
+
const bytes = await readImage(root, sha);
|
|
2729
|
+
if (!bytes)
|
|
2730
|
+
return json(404, refusal(`no image ${sha} here: the tree's file with its images in it (/tree.ged without ?images=ref) has them all`, "image.unknown", { sha }));
|
|
2731
|
+
res.writeHead(200, { "Content-Type": IMAGE_MIME, "Content-Length": String(bytes.length), ...headers }).end(bytes);
|
|
2732
|
+
};
|
|
2733
|
+
/**
|
|
2734
|
+
* Several images of the tree's file by their hashes (POST /images {"images": [sha256…]}, spec 071): read only. Each
|
|
2735
|
+
* given whole as base64 with its hash, kind and size, in the order asked, until the answer holds IMAGES_ANSWER_BYTES
|
|
2736
|
+
* of them (one at least); those beyond in `more` (asked again), those not here in `missing` (the app takes the whole
|
|
2737
|
+
* file for them). The answer has its length: one cut short is never taken as whole; it is never packed (gzip). Refused: 400 images.body (not
|
|
2738
|
+
* {"images": [64 hex…]}, none, more than IMAGES_AT_ONCE).
|
|
2739
|
+
*/
|
|
2740
|
+
const giveImages = async (req, res) => {
|
|
2741
|
+
const json = (code, body) => {
|
|
2742
|
+
if (res.headersSent)
|
|
2743
|
+
return;
|
|
2744
|
+
const text = JSON.stringify(body);
|
|
2745
|
+
res.writeHead(code, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store", "Content-Length": String(Buffer.byteLength(text)) }).end(text);
|
|
2746
|
+
};
|
|
2747
|
+
const max = 128 * 1024;
|
|
2748
|
+
const chunks = [];
|
|
2749
|
+
let size = 0;
|
|
2750
|
+
for await (const c of req) {
|
|
2751
|
+
size += c.length;
|
|
2752
|
+
if (size <= max)
|
|
2753
|
+
chunks.push(c);
|
|
2754
|
+
}
|
|
2755
|
+
const bad = () => json(400, refusal(`the body: {"images": ["<sha256>", …]}, 1 to ${IMAGES_AT_ONCE} of them`, "images.body", { max: String(IMAGES_AT_ONCE) }));
|
|
2756
|
+
if (size > max)
|
|
2757
|
+
return bad();
|
|
2758
|
+
let asked;
|
|
2759
|
+
try {
|
|
2760
|
+
asked = JSON.parse(Buffer.concat(chunks).toString("utf8"))?.images;
|
|
2761
|
+
}
|
|
2762
|
+
catch {
|
|
2763
|
+
return bad();
|
|
2764
|
+
}
|
|
2765
|
+
if (!Array.isArray(asked) || !asked.length || asked.length > IMAGES_AT_ONCE || asked.some((x) => typeof x !== "string" || !IMAGE_SHA.test(x.toLowerCase())))
|
|
2766
|
+
return bad();
|
|
2767
|
+
const shas = [...new Set(asked.map((x) => x.toLowerCase()))];
|
|
2768
|
+
const cap = Number(env.STROM_LIVE_IMAGES_BYTES ?? IMAGES_ANSWER_BYTES);
|
|
2769
|
+
const images = [];
|
|
2770
|
+
const missing = [];
|
|
2771
|
+
const more = [];
|
|
2772
|
+
let held = 0;
|
|
2773
|
+
for (const sha of shas) {
|
|
2774
|
+
// the app gone meanwhile: nothing more read (its request read whole is no sign: it ends as it is read)
|
|
2775
|
+
if (res.destroyed)
|
|
2776
|
+
return;
|
|
2777
|
+
if (images.length && held >= cap) {
|
|
2778
|
+
// the answer full: only whether it is here (the next answer reads it whole, and says missing one gone since)
|
|
2779
|
+
if (await fs.promises.stat(imageFile(root, sha)).then(() => true, () => false))
|
|
2780
|
+
more.push(sha);
|
|
2781
|
+
else
|
|
2782
|
+
missing.push(sha);
|
|
2783
|
+
continue;
|
|
2784
|
+
}
|
|
2785
|
+
const bytes = await readImage(root, sha);
|
|
2786
|
+
if (!bytes) {
|
|
2787
|
+
missing.push(sha);
|
|
2788
|
+
continue;
|
|
2789
|
+
}
|
|
2790
|
+
// one that would take the answer over its size waits for the next (but the first always comes)
|
|
2791
|
+
if (images.length && held + bytes.length > cap) {
|
|
2792
|
+
more.push(sha);
|
|
2793
|
+
held = cap;
|
|
2794
|
+
continue;
|
|
2795
|
+
}
|
|
2796
|
+
held += bytes.length;
|
|
2797
|
+
images.push({ sha, mime: IMAGE_MIME, bytes: bytes.length, data: bytes.toString("base64") });
|
|
2798
|
+
}
|
|
2799
|
+
// never packed, though the app takes it: base64 of JPEGs packs about a quarter, slower to pack than to send
|
|
2800
|
+
// (the app waited for its answers; the slim tree.ged is packed still)
|
|
2801
|
+
json(200, { images, missing, more });
|
|
2650
2802
|
};
|
|
2651
2803
|
/**
|
|
2652
2804
|
* What the app would load to have every image of the research (/excerpts?missing=1): the sources whose excerpts the
|
|
@@ -2655,7 +2807,7 @@ export function serveLive(root, env) {
|
|
|
2655
2807
|
*/
|
|
2656
2808
|
const giveLeft = async (res, version) => {
|
|
2657
2809
|
const h = head(root);
|
|
2658
|
-
const now = left && left.head === h ? left : (await makeGed(version)).left;
|
|
2810
|
+
const now = left && left.head === h ? left : (await makeGed(version, gedFollow?.images)).left;
|
|
2659
2811
|
const tree = Tree.open(root, env);
|
|
2660
2812
|
const shared = new Settings(env, {}).shared()?.value;
|
|
2661
2813
|
const level = excerptLevel(now.level) ?? LEVELS[1];
|
|
@@ -2798,7 +2950,7 @@ export function serveLive(root, env) {
|
|
|
2798
2950
|
const origin = allowedOrigin(req.headers.origin);
|
|
2799
2951
|
const version = appVersionOf(req, new Settings(env, {}));
|
|
2800
2952
|
// what the app sends may change what /status says without a commit (a send waiting, a reading, a batch): made again
|
|
2801
|
-
if (req.method !== "GET" && req.method !== "OPTIONS")
|
|
2953
|
+
if (req.method !== "GET" && req.method !== "OPTIONS" && !(req.method === "POST" && what === "images"))
|
|
2802
2954
|
res.once("finish", () => keeper.forget());
|
|
2803
2955
|
if (origin) {
|
|
2804
2956
|
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
@@ -3011,6 +3163,11 @@ export function serveLive(root, env) {
|
|
|
3011
3163
|
writeFor(req, res, origin, experimentsWrite());
|
|
3012
3164
|
return;
|
|
3013
3165
|
}
|
|
3166
|
+
// the images of the tree's file by their hashes, several at once (read only: nothing written, nothing made)
|
|
3167
|
+
if (req.method === "POST" && t === token && what === "images" && !sub) {
|
|
3168
|
+
giveImages(req, res).catch((e) => failed(req, res, e));
|
|
3169
|
+
return;
|
|
3170
|
+
}
|
|
3014
3171
|
if ((req.method === "GET" || req.method === "POST") && t === token && what === "phone") {
|
|
3015
3172
|
phone(req, res, origin, sub, act);
|
|
3016
3173
|
return;
|
|
@@ -3245,16 +3402,21 @@ export function serveLive(root, env) {
|
|
|
3245
3402
|
logs.ask(h).then(answer, (e) => failed(req, res, e));
|
|
3246
3403
|
}
|
|
3247
3404
|
else if (what === "tree.ged" || what === "images.ged") {
|
|
3248
|
-
|
|
3405
|
+
// the images by reference (?images=ref, feature ged.imagesByHash), else in the file as always
|
|
3406
|
+
const images = imagesAsked(req);
|
|
3407
|
+
gedFollow = { version, images };
|
|
3249
3408
|
// the app has the tree of the head now (its ETag, feature ged.etag): 304 at once, nothing made
|
|
3250
|
-
if (gedUnchanged(req, res, version))
|
|
3409
|
+
if (gedUnchanged(req, res, version, images))
|
|
3251
3410
|
return;
|
|
3252
3411
|
// the last one made at once, the new one told by an event (feature ged.stale)
|
|
3253
3412
|
if (new URLSearchParams((req.url ?? "").split("?")[1] ?? "").get("stale") === "1")
|
|
3254
|
-
giveStale(req, res, version).catch((e) => failed(req, res, e));
|
|
3413
|
+
giveStale(req, res, version, images).catch((e) => failed(req, res, e));
|
|
3255
3414
|
// made when the commits stop coming (an agent's commands one after another): once for them all
|
|
3256
3415
|
else
|
|
3257
|
-
afterQuiet(() => giveGed(req, res, version).catch((e) => failed(req, res, e)));
|
|
3416
|
+
afterQuiet(() => giveGed(req, res, version, images).catch((e) => failed(req, res, e)));
|
|
3417
|
+
}
|
|
3418
|
+
else if (what === "image" && sub && !act) {
|
|
3419
|
+
giveImage(req, res, decoded(sub).toLowerCase()).catch((e) => failed(req, res, e));
|
|
3258
3420
|
}
|
|
3259
3421
|
else if (what === "events") {
|
|
3260
3422
|
statusVersion = version;
|
|
@@ -6226,7 +6388,7 @@ export function serveLive(root, env) {
|
|
|
6226
6388
|
// a bridge taking over from one whose app followed the tree: its tree made before the app asks again
|
|
6227
6389
|
if (gedFollow) {
|
|
6228
6390
|
const follow = gedFollow;
|
|
6229
|
-
setTimeout(() => void makeGed(follow.version).catch((e) => noteLive(root, `the tree for the app not made: ${errorText(e)}`)), 3000).unref?.();
|
|
6391
|
+
setTimeout(() => void makeGed(follow.version, follow.images).catch((e) => noteLive(root, `the tree for the app not made: ${errorText(e)}`)), 3000).unref?.();
|
|
6230
6392
|
}
|
|
6231
6393
|
// sends left waiting when the bridge before ended (written at once): written now, one after another
|
|
6232
6394
|
setTimeout(() => {
|
|
@@ -6301,7 +6463,7 @@ export function serveLive(root, env) {
|
|
|
6301
6463
|
};
|
|
6302
6464
|
let child;
|
|
6303
6465
|
try {
|
|
6304
|
-
child = spawnBridge(root, env, { STROM_LIVE_RENEWED: disk.version, STROM_LIVE_STATUS_FOR: statusVersion ?? "", ...(gedFollow ? { STROM_LIVE_GED_FOR: gedFollow.version ?? "" } : {}) });
|
|
6466
|
+
child = spawnBridge(root, env, { STROM_LIVE_RENEWED: disk.version, STROM_LIVE_STATUS_FOR: statusVersion ?? "", ...(gedFollow ? { STROM_LIVE_GED_FOR: gedFollow.version ?? "", ...(gedFollow.images === "ref" ? { STROM_LIVE_GED_IMAGES: "ref" } : {}) } : {}) });
|
|
6305
6467
|
}
|
|
6306
6468
|
catch (e) {
|
|
6307
6469
|
renewing = false;
|
|
@@ -6455,12 +6617,12 @@ export function serveLive(root, env) {
|
|
|
6455
6617
|
const follow = gedFollow;
|
|
6456
6618
|
if (tell && follow && changeWaitMs > 0) {
|
|
6457
6619
|
untold ??= { since: Date.now() };
|
|
6458
|
-
const ready = geds.get(variantOf(follow.version).variant)?.head === h;
|
|
6620
|
+
const ready = geds.get(variantOf(follow.version, follow.images).variant)?.head === h;
|
|
6459
6621
|
if (!ready && Date.now() - untold.since < changeWaitMs) {
|
|
6460
6622
|
tell = false;
|
|
6461
6623
|
if (!prebuilding && !(at && Date.now() - Date.parse(at) < quietMs)) {
|
|
6462
6624
|
prebuilding = true;
|
|
6463
|
-
makeGed(follow.version)
|
|
6625
|
+
makeGed(follow.version, follow.images)
|
|
6464
6626
|
.catch((e) => noteLive(root, `the tree for the app not made: ${errorText(e)}`))
|
|
6465
6627
|
.finally(() => (prebuilding = false));
|
|
6466
6628
|
}
|
package/dist/core/liveged.js
CHANGED
|
@@ -21,6 +21,7 @@ import { refusal } from "./receive.js";
|
|
|
21
21
|
import { actsAsArchive } from "./state.js";
|
|
22
22
|
import { verifyMarks } from "./verify.js";
|
|
23
23
|
import { readsAgain } from "./sourceread.js";
|
|
24
|
+
import { putImage, sweepImages } from "./liveimages.js";
|
|
24
25
|
/** The tree for the app at a head, for a version of the app (made where it is called: on a thread of its own in the bridge). */
|
|
25
26
|
export function buildGed(ask) {
|
|
26
27
|
const { root, env, head: h, version } = ask;
|
|
@@ -67,21 +68,29 @@ export function buildGed(ask) {
|
|
|
67
68
|
sources: images ? tree.list("source").flatMap((s) => (s.retracted ? [] : [{ source: s, omitted: images.omitted(s) }])).filter((x) => !!x.omitted) : [],
|
|
68
69
|
};
|
|
69
70
|
const offered = opens ? ask.links : [];
|
|
70
|
-
|
|
71
|
+
// the images by reference: each kept by its content's hash as the file names it (the same bytes the file would carry)
|
|
72
|
+
const named = new Set();
|
|
73
|
+
const imageRef = ask.images === "ref" ? (jpeg) => {
|
|
74
|
+
const sha = putImage(root, jpeg);
|
|
75
|
+
named.add(sha);
|
|
76
|
+
return sha;
|
|
77
|
+
} : undefined;
|
|
78
|
+
const text = exportGedcom(tree, { for: "strom", ...(imageRef ? { imageRef } : {}), ...(h ? { head: h } : {}), ...(surnameGroups ? { surnameGroups } : {}), ...(lines ? { lines } : {}), ...(placeRecords ? { placeRecords } : {}), ...(origins ? { origins } : {}), ...(verify ? { verify } : {}), ...(images ? { excerpts: images.of } : {}), ...(opens ? { clips: true, research: true } : {}), ...(edges ? { edges } : {}), ...(storyDrafts ? { storyDrafts } : {}), ...(coupleResi ? { coupleResi } : {}), ...(sourceReads ? { sourceReads } : {}), ...(confirms ? { confirms } : {}), ...(factStatus ? { factStatus } : {}), ...(archive ? { archive } : {}), ...(turnsExcerpts ? { turnsExcerpts } : {}), ...(noCouple ? { noCouple } : {}), ...(titles ? { titles } : {}), ...(hypothesisLinks ? { hypothesisLinks } : {}), ...(hypothesisDecider ? { hypothesisDecider } : {}), ...(conflictSides ? { conflictSides } : {}), ...(readings ? { readings } : {}), ...(original ? { original } : {}), ...(omitted ? { omitted: images.omitted } : {}), ...(offered.length ? { links: offered, ...(linkScheme(env) !== LINK_SCHEME ? { linkScheme: linkScheme(env) } : {}) } : {}) }).text;
|
|
71
79
|
// its bytes in a buffer of their own: handed to the bridge's thread without a copy
|
|
72
80
|
const bytes = Buffer.from(new ArrayBuffer(Buffer.byteLength(text)));
|
|
73
81
|
bytes.write(text);
|
|
74
|
-
return { head: h, version: version ?? "", links: offered.join(" "), bytes, left };
|
|
82
|
+
return { head: h, version: version ?? "", links: offered.join(" "), bytes, left, ...(imageRef ? { images: [...named].sort() } : {}) };
|
|
75
83
|
}
|
|
76
84
|
/**
|
|
77
85
|
* What a tree's file for the app is made by beyond the research's head: the app's version, the links offered, this
|
|
78
86
|
* strom, and what of this computer changes it (the images' settings and folder, the link scheme, the copy of the app,
|
|
79
87
|
* a research acting as an archive). Two asks of one variant at one head get the same file.
|
|
80
88
|
*/
|
|
81
|
-
export function gedVariant(root, env, version, links) {
|
|
89
|
+
export function gedVariant(root, env, version, links, images = "data") {
|
|
82
90
|
const tree = Tree.open(root, env);
|
|
83
91
|
const settings = new Settings(env, {});
|
|
84
|
-
|
|
92
|
+
// the images by reference: a variant of its own (its own ETag); the file with them in it as before (its ETag kept)
|
|
93
|
+
return JSON.stringify({ strom: VERSION, app: version ?? "", links, excerpts: settings.excerpts(tree.config), shared: settings.shared()?.value ?? "", scheme: linkScheme(env), copy: stromAppUrl(settings), archive: actsAsArchive(tree), ...(images === "ref" ? { images } : {}) });
|
|
85
94
|
}
|
|
86
95
|
/**
|
|
87
96
|
* Where the bridge keeps the last file it made of each variant (.strom/cache/live-ged): it outlives the bridge (a
|
|
@@ -91,8 +100,11 @@ export function gedVariant(root, env, version, links) {
|
|
|
91
100
|
export function gedStoreDir(root) {
|
|
92
101
|
return path.join(root, ".strom", "cache", "live-ged");
|
|
93
102
|
}
|
|
94
|
-
/**
|
|
95
|
-
|
|
103
|
+
/**
|
|
104
|
+
* The variants kept on disk (each about the size of its file): the newest, the rest go — three, so that an app loading
|
|
105
|
+
* the images by reference keeps its file and the whole one it falls back to beside the file of another window.
|
|
106
|
+
*/
|
|
107
|
+
const STORED_VARIANTS = 3;
|
|
96
108
|
const storedName = (variant) => crypto.createHash("sha256").update(variant).digest("hex").slice(0, 16);
|
|
97
109
|
/** A file written whole or not at all (beside it, then put in its place). */
|
|
98
110
|
async function writeWhole(file, data) {
|
|
@@ -115,6 +127,7 @@ export async function storeGed(root, variant, made) {
|
|
|
115
127
|
links: made.links,
|
|
116
128
|
bytes: made.bytes.length,
|
|
117
129
|
left: { head: made.left.head, level: made.left.level, sources: made.left.sources.map((x) => ({ id: x.source.id, omitted: x.omitted })) },
|
|
130
|
+
...(made.images ? { images: made.images } : {}),
|
|
118
131
|
};
|
|
119
132
|
await writeWhole(path.join(dir, `${name}.ged`), made.bytes);
|
|
120
133
|
await writeWhole(path.join(dir, `${name}.json`), JSON.stringify(stamp));
|
|
@@ -144,8 +157,34 @@ export async function storeGed(root, variant, made) {
|
|
|
144
157
|
if (at !== undefined && Date.now() - at > 3600_000)
|
|
145
158
|
await fs.promises.rm(path.join(dir, f), { force: true });
|
|
146
159
|
}
|
|
160
|
+
// the images no kept file names any more (and not named within the hour) go
|
|
161
|
+
await sweepImages(root, await keptImages(root));
|
|
162
|
+
}
|
|
163
|
+
/** The hashes of the images the files kept on disk name (those with the images by reference). */
|
|
164
|
+
export async function keptImages(root) {
|
|
165
|
+
const dir = gedStoreDir(root);
|
|
166
|
+
const keep = new Set();
|
|
167
|
+
let files;
|
|
168
|
+
try {
|
|
169
|
+
files = await fs.promises.readdir(dir);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return keep;
|
|
173
|
+
}
|
|
174
|
+
for (const f of files) {
|
|
175
|
+
if (!/^[0-9a-f]{16}\.json$/.test(f))
|
|
176
|
+
continue;
|
|
177
|
+
try {
|
|
178
|
+
for (const sha of JSON.parse(await fs.promises.readFile(path.join(dir, f), "utf8")).images ?? [])
|
|
179
|
+
keep.add(sha);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// not whole: its images go once nothing else names them
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return keep;
|
|
147
186
|
}
|
|
148
|
-
/** The files kept on disk by another strom (its bridge gone, never given again): removed. */
|
|
187
|
+
/** The files kept on disk by another strom (its bridge gone, never given again): removed — and the images none names. */
|
|
149
188
|
export async function tidyStoredGeds(root) {
|
|
150
189
|
const dir = gedStoreDir(root);
|
|
151
190
|
let files;
|
|
@@ -153,7 +192,7 @@ export async function tidyStoredGeds(root) {
|
|
|
153
192
|
files = await fs.promises.readdir(dir);
|
|
154
193
|
}
|
|
155
194
|
catch {
|
|
156
|
-
|
|
195
|
+
files = [];
|
|
157
196
|
}
|
|
158
197
|
for (const f of files) {
|
|
159
198
|
const m = /^([0-9a-f]{16})\.json$/.exec(f);
|
|
@@ -170,6 +209,7 @@ export async function tidyStoredGeds(root) {
|
|
|
170
209
|
for (const ext of ["json", "ged"])
|
|
171
210
|
await fs.promises.rm(path.join(dir, `${m[1]}.${ext}`), { force: true });
|
|
172
211
|
}
|
|
212
|
+
await sweepImages(root, await keptImages(root));
|
|
173
213
|
}
|
|
174
214
|
/**
|
|
175
215
|
* The file kept on disk for a variant: of that head (`head`), or the last one made whatever its head (none: nothing
|
|
@@ -190,7 +230,7 @@ export async function storedGed(root, env, variant, head) {
|
|
|
190
230
|
const source = tree.get(x.id);
|
|
191
231
|
return source ? [{ source, omitted: x.omitted }] : [];
|
|
192
232
|
});
|
|
193
|
-
return { head: stamp.head, version: stamp.version, links: stamp.links, bytes, left: { head: stamp.left.head, level: stamp.left.level, sources } };
|
|
233
|
+
return { head: stamp.head, version: stamp.version, links: stamp.links, bytes, left: { head: stamp.left.head, level: stamp.left.level, sources }, ...(stamp.images ? { images: stamp.images } : {}) };
|
|
194
234
|
}
|
|
195
235
|
catch {
|
|
196
236
|
return undefined;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The images of the tree's file for the Strom app kept by their content (spec 071): the bridge's file with the images
|
|
2
|
+
// by reference (GET /tree.ged?images=ref, feature ged.imagesByHash) names each excerpt by the SHA-256 of its JPEG's bytes
|
|
3
|
+
// (2 FILE strom-image:<sha256>), and the app loads only those it does not have yet (GET /image/<sha256>, POST /images).
|
|
4
|
+
//
|
|
5
|
+
// An image is kept here only as a file is made with it (core/liveged.ts buildGed): the bridge never makes an image
|
|
6
|
+
// because it is asked for one — an image it does not have is 404, and the app takes the whole file instead. Each file
|
|
7
|
+
// is written whole (beside it, then put in its place) under its own hash, and read back only when its bytes still give
|
|
8
|
+
// that hash (one that does not is removed and counts as not here): a file changed or cut short is never given as
|
|
9
|
+
// another's. What is kept is bounded: the images the files kept on disk name (core/liveged.ts storeGed), and those made
|
|
10
|
+
// within the last hour (a file being made, or given a moment ago); everything else goes as a file is kept.
|
|
11
|
+
import crypto from "node:crypto";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
/** The reference to an image in the tree's file for the app (2 FILE strom-image:<sha256>). */
|
|
15
|
+
export const IMAGE_REF = "strom-image:";
|
|
16
|
+
/** What an image kept here is (every excerpt is a JPEG). */
|
|
17
|
+
export const IMAGE_MIME = "image/jpeg";
|
|
18
|
+
/** An image's hash as the bridge takes it: SHA-256, 64 lowercase hex. */
|
|
19
|
+
export const IMAGE_SHA = /^[0-9a-f]{64}$/u;
|
|
20
|
+
/** How long an image no kept file names stays (a file being made, or given a moment ago the app loads its images of). */
|
|
21
|
+
export const IMAGE_GRACE_MS = 3600_000;
|
|
22
|
+
/** Where the images are kept (.strom/cache/live-images/<the hash's first two>/<hash>.jpg): a cache strom makes again. */
|
|
23
|
+
export function imageStoreDir(root) {
|
|
24
|
+
return path.join(root, ".strom", "cache", "live-images");
|
|
25
|
+
}
|
|
26
|
+
/** The file of an image by its hash. */
|
|
27
|
+
export function imageFile(root, sha) {
|
|
28
|
+
return path.join(imageStoreDir(root), sha.slice(0, 2), `${sha}.jpg`);
|
|
29
|
+
}
|
|
30
|
+
/** The SHA-256 of an image's bytes (64 lowercase hex). */
|
|
31
|
+
export function imageSha(bytes) {
|
|
32
|
+
return crypto.createHash("sha256").update(bytes).digest("hex");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An image kept by its hash (on the thread making the file): written whole when it is not here yet (or here but of
|
|
36
|
+
* another size: cut short), else only its time renewed (it is named again: not removed within the hour). Its hash.
|
|
37
|
+
*/
|
|
38
|
+
export function putImage(root, bytes) {
|
|
39
|
+
const sha = imageSha(bytes);
|
|
40
|
+
const file = imageFile(root, sha);
|
|
41
|
+
const size = fs.statSync(file, { throwIfNoEntry: false })?.size;
|
|
42
|
+
if (size === bytes.length) {
|
|
43
|
+
const now = new Date();
|
|
44
|
+
try {
|
|
45
|
+
fs.utimesSync(file, now, now);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// removed meanwhile: written again below
|
|
49
|
+
}
|
|
50
|
+
if (fs.existsSync(file))
|
|
51
|
+
return sha;
|
|
52
|
+
}
|
|
53
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
54
|
+
const part = `${file}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.part`;
|
|
55
|
+
fs.writeFileSync(part, bytes);
|
|
56
|
+
fs.renameSync(part, file);
|
|
57
|
+
return sha;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* An image's bytes by its hash, only when they still give it (one that does not is removed: changed or cut short on
|
|
61
|
+
* disk). Undefined: not here.
|
|
62
|
+
*/
|
|
63
|
+
export async function readImage(root, sha) {
|
|
64
|
+
if (!IMAGE_SHA.test(sha))
|
|
65
|
+
return undefined;
|
|
66
|
+
const file = imageFile(root, sha);
|
|
67
|
+
let bytes;
|
|
68
|
+
try {
|
|
69
|
+
bytes = await fs.promises.readFile(file);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
if (imageSha(bytes) === sha)
|
|
75
|
+
return bytes;
|
|
76
|
+
await fs.promises.rm(file, { force: true }).catch(() => undefined);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The images no kept file names and not named within `graceMs` removed (and parts left by a thread that ended under
|
|
81
|
+
* them); how many went.
|
|
82
|
+
*/
|
|
83
|
+
export async function sweepImages(root, keep, graceMs = IMAGE_GRACE_MS, now = Date.now()) {
|
|
84
|
+
const dir = imageStoreDir(root);
|
|
85
|
+
let gone = 0;
|
|
86
|
+
let subs;
|
|
87
|
+
try {
|
|
88
|
+
subs = await fs.promises.readdir(dir);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
for (const sub of subs) {
|
|
94
|
+
if (!/^[0-9a-f]{2}$/u.test(sub))
|
|
95
|
+
continue;
|
|
96
|
+
const at = path.join(dir, sub);
|
|
97
|
+
let files;
|
|
98
|
+
try {
|
|
99
|
+
files = await fs.promises.readdir(at);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let left = files.length;
|
|
105
|
+
for (const f of files) {
|
|
106
|
+
const sha = /^([0-9a-f]{64})\.jpg$/u.exec(f)?.[1];
|
|
107
|
+
if (sha && keep.has(sha))
|
|
108
|
+
continue;
|
|
109
|
+
const time = (await fs.promises.stat(path.join(at, f)).catch(() => undefined))?.mtimeMs;
|
|
110
|
+
if (time === undefined || now - time < graceMs)
|
|
111
|
+
continue;
|
|
112
|
+
await fs.promises.rm(path.join(at, f), { force: true }).catch(() => undefined);
|
|
113
|
+
left--;
|
|
114
|
+
if (sha)
|
|
115
|
+
gone++;
|
|
116
|
+
}
|
|
117
|
+
if (!left)
|
|
118
|
+
await fs.promises.rmdir(at).catch(() => undefined);
|
|
119
|
+
}
|
|
120
|
+
return gone;
|
|
121
|
+
}
|
package/dist/core/tree.js
CHANGED
|
@@ -32,7 +32,7 @@ export const TREE_FILE = "strom.json";
|
|
|
32
32
|
export const SEAL_FOREIGN = "seal.foreign";
|
|
33
33
|
// between releases the candidate being made (a bridge run from the sources says what it is: the Strom app goes by it);
|
|
34
34
|
// at a release the release's own (package.json)
|
|
35
|
-
export const VERSION = "1.30.0-beta.
|
|
35
|
+
export const VERSION = "1.30.0-beta.4";
|
|
36
36
|
/** What a new research is settled with from the start: nothing an older strom counted otherwise to set right in it. */
|
|
37
37
|
export const NEW_TREE_SETTLED = ["readers-1", "proven-originals-1", "origins-1", "verify-originals-1", "origins-tree-1"];
|
|
38
38
|
const GITIGNORE = `# Strom Research — local state and large files are not versioned
|
package/dist/gedcom/export.js
CHANGED
|
@@ -35,6 +35,7 @@ import { quay } from "../core/evidence.js";
|
|
|
35
35
|
import { VERSION } from "../core/tree.js";
|
|
36
36
|
import { dataUrl, turned } from "../core/excerpt.js";
|
|
37
37
|
import { excerptPage, sourcePage } from "../core/scanlink.js";
|
|
38
|
+
import { IMAGE_MIME, IMAGE_REF } from "../core/liveimages.js";
|
|
38
39
|
import { numbersOnly } from "../core/streets.js";
|
|
39
40
|
import { factRef, nameRef, sexRef } from "../core/origin.js";
|
|
40
41
|
import { proposalKind } from "../core/proposals.js";
|
|
@@ -620,7 +621,15 @@ export function exportGedcom(tree, opts = {}) {
|
|
|
620
621
|
const page = excerptPage(e.url, s);
|
|
621
622
|
if (page)
|
|
622
623
|
w.text(2, "_URL", page);
|
|
623
|
-
|
|
624
|
+
if (opts.imageRef) {
|
|
625
|
+
w.line(2, "FILE", `${IMAGE_REF}${opts.imageRef(e.jpeg)}`);
|
|
626
|
+
w.line(3, "_MIME", IMAGE_MIME);
|
|
627
|
+
w.line(3, "_WIDTH", String(e.width));
|
|
628
|
+
w.line(3, "_HEIGHT", String(e.height));
|
|
629
|
+
w.line(3, "_BYTES", String(e.jpeg.length));
|
|
630
|
+
}
|
|
631
|
+
else
|
|
632
|
+
w.wrapped(2, "FILE", dataUrl(e));
|
|
624
633
|
// the original it is cut from, by its content: the app knows the research has it (and sends it not again)
|
|
625
634
|
const original = tree.get(e.media);
|
|
626
635
|
if (original?.sha)
|
package/dist/gedcom/validate.js
CHANGED
|
@@ -112,6 +112,8 @@ const EXTENSIONS = new Set([
|
|
|
112
112
|
"_STROM_ORIG",
|
|
113
113
|
// an excerpt's original by its content, and how its picture lies
|
|
114
114
|
"_STROM_SHA", "_STROM_ORIENT",
|
|
115
|
+
// an excerpt by reference in the bridge's file (FILE strom-image:<sha256>): its kind, pixels and size
|
|
116
|
+
"_MIME", "_WIDTH", "_HEIGHT", "_BYTES",
|
|
115
117
|
// the bounds of a lineage the person set (on a person), and the header's mark that the file says them
|
|
116
118
|
"_STROM_LINE", "_STROM_LINES",
|
|
117
119
|
// the research's place records and each fact's place pointing to its record
|