@cardinali-studio/adminkit 2.2.48 → 2.2.50
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/dist/app/App.js +6 -6
- package/dist/app/app.css +67 -1
- package/dist/app/delivery.js +7 -7
- package/dist/app/guide/TransferGuide.js +1 -1
- package/dist/app/lib/deliveries.d.ts +6 -0
- package/dist/app/lib/delivery-capabilities.d.ts +31 -0
- package/dist/app/lib/delivery-capabilities.js +115 -0
- package/dist/app/lib/delivery-checkpoint-pipeline.d.ts +81 -0
- package/dist/app/lib/delivery-checkpoint-pipeline.js +195 -0
- package/dist/app/lib/delivery-finalize.d.ts +21 -0
- package/dist/app/lib/delivery-finalize.js +42 -0
- package/dist/app/lib/delivery-multipart-large.d.ts +18 -0
- package/dist/app/lib/delivery-multipart-large.js +28 -0
- package/dist/app/lib/delivery-network.d.ts +7 -1
- package/dist/app/lib/delivery-network.js +85 -18
- package/dist/app/lib/delivery-part-pipeline.d.ts +79 -0
- package/dist/app/lib/delivery-part-pipeline.js +270 -0
- package/dist/app/lib/delivery-upload-coordinator.d.ts +112 -0
- package/dist/app/lib/delivery-upload-coordinator.js +229 -0
- package/dist/app/lib/delivery-upload.d.ts +19 -3
- package/dist/app/lib/delivery-upload.js +226 -29
- package/dist/app/lib/upload-queue.d.ts +5 -0
- package/dist/app/lib/upload-queue.js +54 -29
- package/dist/app/routes/Deliveries.d.ts +9 -3
- package/dist/app/routes/Deliveries.js +299 -164
- package/dist/app/routes/DeliveryDashboard.js +1 -1
- package/dist/app/routes/DeliveryEmail.d.ts +8 -1
- package/dist/app/routes/DeliveryEmail.js +63 -23
- package/dist/app/routes/Overview.js +5 -5
- package/dist/app/routes/UploadDock.js +4 -3
- package/dist/form/media/MediaGrid.js +1 -1
- package/dist/functions/_shared/b2.js +108 -19
- package/dist/functions/_shared/delivery-activation.js +98 -0
- package/dist/functions/_shared/delivery-download-bundle.js +280 -0
- package/dist/functions/_shared/delivery-email.js +92 -13
- package/dist/functions/_shared/delivery-file-names.js +19 -0
- package/dist/functions/_shared/delivery-finalization-paid.js +31 -0
- package/dist/functions/_shared/delivery-finalization-storage.js +64 -0
- package/dist/functions/_shared/delivery-manifest-free.js +74 -0
- package/dist/functions/_shared/delivery-manifest.js +277 -20
- package/dist/functions/_shared/delivery-multipart-verification.js +68 -0
- package/dist/functions/_shared/delivery-request.js +74 -0
- package/dist/functions/_shared/delivery-storage-access.js +14 -0
- package/dist/functions/_shared/delivery-upload-admission.js +221 -0
- package/dist/functions/_shared/delivery-upload-contract.js +44 -0
- package/dist/functions/_shared/delivery-upload-free.js +80 -0
- package/dist/functions/_shared/delivery-upload-policy.js +64 -0
- package/dist/functions/_shared/delivery-upload-session.js +365 -0
- package/dist/functions/_shared/delivery-work-budget.js +49 -0
- package/dist/functions/_shared/diagnostics.js +59 -0
- package/dist/functions/api/deliveries.js +61 -17
- package/dist/functions/api/delivery/multipart.js +156 -16
- package/dist/functions/delivery-public/assets/client.js +59 -54
- package/dist/functions/delivery-public/assets/delivery.css +6 -2
- package/dist/functions/delivery-public/index.js +43 -15
- package/dist/functions/delivery-public/migrations/0015_delivery_activation_intents.sql +12 -0
- package/dist/functions/delivery-public/migrations/0016_delivery_multipart_verification.sql +16 -0
- package/dist/functions/delivery-public/migrations/0017_delivery_upload_admission.sql +38 -0
- package/dist/functions/delivery-public/migrations/0018_delivery_upload_sessions.sql +26 -0
- package/dist/functions/delivery-public/migrations/0019_delivery_manifest_fragments.sql +27 -0
- package/dist/functions/delivery-public/migrations/0020_delivery_email_reply_to.sql +1 -0
- package/dist/functions/index.js +3 -1
- package/dist/theme.css +2 -1
- package/package.json +1 -1
|
@@ -46,7 +46,7 @@ export function DeliveryDashboard({ onCreate, onOpen }) {
|
|
|
46
46
|
const running = checking || data?.storage.status === "running";
|
|
47
47
|
useEffect(() => { const timer = setTimeout(() => void load(), running || (data?.storage.enabled && !data.storage.checkedAt) ? 3000 : 60_000); return () => clearTimeout(timer); }, [data, running, load]);
|
|
48
48
|
const storage = data?.storage, snapshot = storage?.snapshot;
|
|
49
|
-
return _jsxs("section", { className: "dd-dashboard", "aria-label": "Dashboard consegne", children: [_jsxs("header", { className: "dd-heading", children: [_jsxs("div", { children: [_jsx("p", { className: "dd-eyebrow", children: "Consegne" }), _jsx("h2", { children: "Panoramica transfer" }), _jsx("p", { children: "Disponibilit\u00E0, richieste di download e spazio realmente occupato." })] }), _jsxs("div", { className: "dd-heading-actions", children: [_jsxs("a", { className: "ak-btn", href: typeof window === "undefined" ? "?adminkit-guide=transfer" : transferGuideHref(window.location.href), target: "_blank", rel: "noopener noreferrer", "aria-label": "Guida ai Transfer (si apre in una nuova scheda)", children: ["Guida ai Transfer ", _jsx(Icon.out, {})] }), _jsx("button", { className: "ak-btn ak-btn-primary", onClick: onCreate, children: "Nuovo transfer" })] })] }), error && _jsxs("div", { className: "dd-error", role: "alert", children: [error, " ", _jsx("button", { className: "ak-btn", onClick: () => void load(), children: "Riprova" })] }), _jsxs("div", { className: "dd-metrics", children: [_jsx(Metric, { label: "Transfer attivi", value: data?.active, note: "Pubblicati, disponibili e con un link valido" }), _jsx(Metric, { label: "Spazio transfer attivi", value: bytes(storage?.activeBytes), note: storage?.checkedAt ? "
|
|
49
|
+
return _jsxs("section", { className: "dd-dashboard", "aria-label": "Dashboard consegne", children: [_jsxs("header", { className: "dd-heading", children: [_jsxs("div", { children: [_jsx("p", { className: "dd-eyebrow", children: "Consegne" }), _jsx("h2", { children: "Panoramica transfer" }), _jsx("p", { children: "Disponibilit\u00E0, richieste di download e spazio realmente occupato." })] }), _jsxs("div", { className: "dd-heading-actions", children: [_jsxs("a", { className: "ak-btn", href: typeof window === "undefined" ? "?adminkit-guide=transfer" : transferGuideHref(window.location.href), target: "_blank", rel: "noopener noreferrer", "aria-label": "Guida ai Transfer (si apre in una nuova scheda)", children: ["Guida ai Transfer ", _jsx(Icon.out, {})] }), _jsx("button", { className: "ak-btn ak-btn-primary", onClick: onCreate, children: "Nuovo transfer" })] })] }), error && _jsxs("div", { className: "dd-error", role: "alert", children: [error, " ", _jsx("button", { className: "ak-btn", onClick: () => void load(), children: "Riprova" })] }), _jsxs("div", { className: "dd-metrics", children: [_jsx(Metric, { label: "Transfer attivi", value: data?.active, note: "Pubblicati, disponibili e con un link valido" }), _jsx(Metric, { label: "Spazio transfer attivi", value: bytes(storage?.activeBytes), note: storage?.checkedAt ? "Aggiornato il " + date(storage.checkedAt) : storage?.enabled ? "In attesa della prima verifica" : "Dato non disponibile" }), _jsx(Metric, { label: "Con download richiesto", value: data?.withRequests, note: "Almeno una richiesta di download" }), _jsx(Metric, { label: "Senza richieste", value: data?.withoutRequests, note: "Nessuna richiesta di download registrata" })] }), site().deliveryPricing && _jsx(DeliveryCostEstimate, { totalBytes: snapshot?.totalBytes, pricing: site().deliveryPricing }), (storage?.enabled || snapshot) && _jsxs("section", { className: "dd-storage", "aria-label": "Spazio utilizzato", children: [_jsxs("div", { className: "dd-storage-head", children: [_jsxs("div", { children: [_jsxs("div", { className: "dd-title-row", children: [_jsx("h3", { children: "Spazio utilizzato" }), _jsx("span", { className: "dd-status" + (running ? " is-running" : storage?.error ? " is-error" : ""), children: running ? "Verifica in corso" : storage?.error ? "Verifica non riuscita" : storage?.checkedAt ? "Verificato" : "Da verificare" })] }), _jsx("p", { children: storage?.checkedAt ? `Ultima verifica completata: ${date(storage.checkedAt)}. Controllo automatico ogni ora.` : "Verifica quanto spazio occupano i tuoi transfer." })] }), _jsx("button", { className: "ak-btn", disabled: running || !storage?.enabled, onClick: () => void load(true), children: running ? "Verifica in corso…" : "Verifica ora" })] }), storage?.error && _jsxs("p", { className: "dd-notice", role: "status", children: ["Non \u00E8 stato possibile verificare lo spazio. ", snapshot ? "I valori si riferiscono all’ultima verifica." : "Riprova tra poco."] }), _jsxs("div", { className: "dd-storage-grid", children: [_jsx(Metric, { label: "Spazio totale", value: bytes(snapshot?.totalBytes), note: snapshot ? `${snapshot.currentObjects} ${snapshot.currentObjects === 1 ? "elemento archiviato" : "elementi archiviati"} · ${snapshot.objectVersions} ${snapshot.objectVersions === 1 ? "versione" : "versioni"}` : "Nessun risultato ancora disponibile" }), _jsx(Metric, { label: "Versioni nascoste", value: bytes(snapshot?.hiddenBytes), note: "Byte conservati nelle versioni precedenti" }), _jsx(Metric, { label: "Upload incompleti", value: bytes(snapshot?.incompleteBytes), note: snapshot ? `${snapshot.incompleteUploads} caricamenti da completare` : "File in attesa di completamento" }), _jsx(Metric, { label: "Senza consegna associata", value: bytes(snapshot?.unassignedBytes), note: "Dati senza un riferimento nei transfer" })] }), _jsx("p", { className: "dd-footnote", children: "Versioni nascoste e upload incompleti sono inclusi nel totale. I dati senza consegna possono includerli." })] }), _jsxs("section", { className: "dd-transfers", children: [_jsxs("div", { className: "dd-title-row", children: [_jsx("h3", { children: "Transfer attivi" }), _jsxs("span", { children: [data?.requestedDownloads ?? "—", " richieste di download complessive"] })] }), _jsx("p", { className: "dd-footnote", children: "Una richiesta indica l\u2019uso del pulsante di download; non conferma che il file sia stato ricevuto per intero." }), !data ? _jsx("p", { className: "ak-hint", role: "status", children: "Carico la panoramica\u2026" }) : !data.transfers.length ? _jsx("p", { className: "dd-empty", children: "Nessun transfer attivo. Crea un nuovo transfer per iniziare." }) :
|
|
50
50
|
_jsx("div", { className: "dd-table-wrap", children: _jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Transfer" }), _jsx("th", { children: "Spazio occupato" }), _jsx("th", { children: "Download richiesti" }), _jsx("th", { children: "Scadenza file" })] }) }), _jsx("tbody", { children: data.transfers.map(t => _jsxs("tr", { children: [_jsx("td", { children: _jsxs("button", { className: "dd-transfer-link", onClick: () => onOpen(t.id), children: [_jsx("strong", { children: t.clientName || t.title }), t.clientName && _jsx("span", { children: t.title })] }) }), _jsx("td", { children: bytes(t.storedBytes) }), _jsx("td", { children: _jsx("span", { className: "dd-request" + (!t.downloadCount ? " is-pending" : ""), children: t.downloadCount ? `${t.downloadCount} ${t.downloadCount === 1 ? "richiesta" : "richieste"}` : "Nessuna richiesta" }) }), _jsx("td", { children: t.expiresAt ? new Intl.DateTimeFormat("it-IT", { dateStyle: "medium" }).format(new Date(t.expiresAt)) : "Senza scadenza" })] }, t.id)) })] }) })] })] });
|
|
51
51
|
}
|
|
52
52
|
function Metric({ label, value, note }) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface EmailPreferences {
|
|
2
2
|
recipientEmail: string;
|
|
3
|
+
replyToEmail?: string;
|
|
3
4
|
notifyOwner: boolean;
|
|
4
5
|
sendRecipient: boolean;
|
|
5
6
|
}
|
|
@@ -8,6 +9,8 @@ interface EmailState {
|
|
|
8
9
|
enabled: boolean;
|
|
9
10
|
ownerEnabled: boolean;
|
|
10
11
|
ownerEmail: string;
|
|
12
|
+
fromEmail?: string;
|
|
13
|
+
replyToEditable?: boolean;
|
|
11
14
|
settingsVersion?: number;
|
|
12
15
|
settingsEditable?: boolean;
|
|
13
16
|
notifyDownloads?: boolean;
|
|
@@ -20,12 +23,16 @@ interface EmailState {
|
|
|
20
23
|
recipient: string;
|
|
21
24
|
state: string;
|
|
22
25
|
sentAt: string | null;
|
|
26
|
+
createdAt?: string;
|
|
23
27
|
reason?: 'ready' | 'download';
|
|
24
28
|
}>;
|
|
25
29
|
migrationRequired?: boolean;
|
|
26
30
|
}
|
|
27
31
|
export declare function saveTransferEmailPreferences(id: string, p: EmailPreferences): Promise<EmailState>;
|
|
28
|
-
export declare function DeliveryEmail({ id, value, onChange, busy, onState, unsaved }: {
|
|
32
|
+
export declare function DeliveryEmail({ id, value, onChange, busy, onState, unsaved, hydratePreferences, canResend, activityTarget }: {
|
|
33
|
+
activityTarget?: HTMLElement | null;
|
|
34
|
+
canResend?: boolean;
|
|
35
|
+
hydratePreferences?: boolean;
|
|
29
36
|
id?: string;
|
|
30
37
|
value: EmailPreferences;
|
|
31
38
|
onChange: (v: EmailPreferences) => void;
|
|
@@ -1,25 +1,40 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
async function request(url, body) {
|
|
5
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
async function request(url, body) {
|
|
5
|
+
const unavailable = 'Email momentaneamente non disponibile. Riprova tra poco.';
|
|
6
|
+
let response;
|
|
7
|
+
try {
|
|
8
|
+
response = await fetch(url, { credentials: 'same-origin', ...(body ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}) });
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw Error('Controlla la connessione e riprova.');
|
|
12
|
+
}
|
|
13
|
+
const value = await response.json().catch(() => null);
|
|
14
|
+
if (!response.ok || !value?.ok)
|
|
15
|
+
throw Error(response.status < 500 && value?.error ? value.error : unavailable);
|
|
16
|
+
return value.email;
|
|
17
|
+
}
|
|
6
18
|
export async function saveTransferEmailPreferences(id, p) { return request('/admin/api/deliveries', { action: 'emailPreferences', id, ...p }); }
|
|
7
|
-
export function DeliveryEmail({ id, value, onChange, busy, onState, unsaved = false }) {
|
|
8
|
-
const [state, setState] = useState(null), [error, setError] = useState(''), [working, setWorking] = useState(false), [confirm, setConfirm] = useState(null);
|
|
19
|
+
export function DeliveryEmail({ id, value, onChange, busy, onState, unsaved = false, hydratePreferences = true, canResend = true, activityTarget }) {
|
|
20
|
+
const [state, setState] = useState(null), [error, setError] = useState(''), [working, setWorking] = useState(false), [resendError, setResendError] = useState(''), [confirm, setConfirm] = useState(null);
|
|
9
21
|
useEffect(() => {
|
|
10
22
|
let alive = true;
|
|
11
23
|
setState(null);
|
|
12
24
|
setError('');
|
|
25
|
+
setResendError('');
|
|
26
|
+
setConfirm(null);
|
|
13
27
|
// Configuration is readable without a transfer; no recipient data is returned.
|
|
14
28
|
request('/admin/api/deliveries?email=1' + (id ? '&id=' + encodeURIComponent(id) : ''))
|
|
15
29
|
.then(v => { if (alive) {
|
|
16
30
|
setState(v);
|
|
17
|
-
if (id)
|
|
31
|
+
if (id && hydratePreferences)
|
|
18
32
|
onState?.(v.preferences);
|
|
19
33
|
} }).catch(e => { if (alive)
|
|
20
34
|
setError(e.message); });
|
|
21
35
|
return () => { alive = false; };
|
|
22
36
|
}, [id]);
|
|
37
|
+
const previouslyBusy = useRef(busy);
|
|
23
38
|
const pending = state?.messages.some(m => m.state === 'pending' || m.state === 'sending') || false;
|
|
24
39
|
useEffect(() => {
|
|
25
40
|
if (!id)
|
|
@@ -27,24 +42,49 @@ export function DeliveryEmail({ id, value, onChange, busy, onState, unsaved = fa
|
|
|
27
42
|
let active = true;
|
|
28
43
|
const refresh = () => request('/admin/api/deliveries?email=1&id=' + encodeURIComponent(id)).then(v => { if (active)
|
|
29
44
|
setState(v); }).catch(() => { });
|
|
30
|
-
if (!busy)
|
|
45
|
+
if (previouslyBusy.current && !busy)
|
|
31
46
|
void refresh();
|
|
47
|
+
previouslyBusy.current = busy;
|
|
32
48
|
const timer = busy || pending ? setInterval(refresh, 5000) : null;
|
|
33
49
|
return () => { active = false; if (timer)
|
|
34
50
|
clearInterval(timer); };
|
|
35
51
|
}, [id, busy, pending]);
|
|
36
|
-
const labels = { pending: 'In attesa
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
const labels = { pending: 'In attesa', sending: 'Invio in corso', sent: 'Inviata', failed: 'Invio non riuscito', review: 'Verifica con chi doveva riceverla prima di reinviare.', cancelled: 'Annullata' };
|
|
53
|
+
const config = state?.configuration;
|
|
54
|
+
const sender = config?.ownerEmail || config?.fromEmail || '';
|
|
55
|
+
const history = state?.messages || [];
|
|
56
|
+
const targets = new Set();
|
|
57
|
+
const issues = history.filter(message => {
|
|
58
|
+
const target = [message.kind, message.reason || 'ready', message.recipient].join('|');
|
|
59
|
+
if (targets.has(target))
|
|
60
|
+
return false;
|
|
61
|
+
targets.add(target);
|
|
62
|
+
return message.state === 'failed' || message.state === 'review';
|
|
63
|
+
});
|
|
64
|
+
const messages = history.filter(message => message.kind === 'recipient' || issues.includes(message));
|
|
65
|
+
const resendKinds = ['owner', 'recipient'].filter(kind => kind === 'owner' ? config?.ownerEnabled && config?.notifyReady !== false : value.sendRecipient && value.recipientEmail);
|
|
66
|
+
const showResend = canResend && config?.enabled && resendKinds.length > 0;
|
|
67
|
+
const activity = id && (messages.length > 0 || showResend) ? (_jsxs("details", { className: "dl-email-activity", children: [_jsxs("summary", { children: [messages.length ? 'Cronologia email' : 'Opzioni email', issues.length > 0 && _jsx("span", { className: "dl-email-attention", children: "Invio da verificare" })] }), messages.length > 0 && _jsx("ul", { className: "dl-email-log", "aria-label": "Stato delle email", children: messages.map(message => {
|
|
68
|
+
const label = message.kind === 'recipient' ? 'Link al destinatario'
|
|
69
|
+
: message.reason === 'download' ? 'Avviso di download al titolare' : 'Conferma di caricamento al titolare';
|
|
70
|
+
const at = message.sentAt || message.createdAt;
|
|
71
|
+
return _jsxs("li", { children: [_jsx("strong", { children: label }), _jsx("span", { children: message.recipient }), _jsxs("span", { children: [labels[message.state] || 'Stato non disponibile', at && _jsxs(_Fragment, { children: [" \u00B7 ", _jsx("time", { dateTime: at, children: new Date(at).toLocaleString('it-IT', { dateStyle: 'short', timeStyle: 'short' }) })] })] })] }, message.id);
|
|
72
|
+
}) }), showResend && _jsx("div", { className: "dl-link-actions", children: resendKinds.map(kind => _jsxs("button", { type: "button", className: "ak-btn", disabled: busy || working || unsaved, title: unsaved ? "Salva prima le modifiche del transfer" : undefined, onClick: () => { setResendError(''); setConfirm(kind); }, children: ["Reinvia ", kind === 'owner' ? 'notifica al titolare' : 'email al destinatario'] }, kind)) }), confirm && _jsxs("div", { className: "dl-email-confirm", children: [_jsxs("p", { children: ["Reinviare l\u2019email a ", confirm === 'owner' ? config?.ownerEmail : value.recipientEmail, "?"] }), _jsx("button", { type: "button", className: "ak-btn ak-btn-primary", disabled: working || busy, onClick: async () => {
|
|
73
|
+
setWorking(true);
|
|
74
|
+
setResendError('');
|
|
75
|
+
try {
|
|
76
|
+
await saveTransferEmailPreferences(id, value);
|
|
77
|
+
setState(await request('/admin/api/deliveries', { action: 'emailSend', id, kind: confirm }));
|
|
78
|
+
setConfirm(null);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
setResendError(e instanceof Error ? e.message : 'Invio non riuscito');
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
setWorking(false);
|
|
85
|
+
}
|
|
86
|
+
}, children: "Conferma invio" }), _jsx("button", { className: "ak-btn", type: "button", disabled: working, onClick: () => setConfirm(null), children: "Annulla" })] }), resendError && _jsx("p", { className: "ak-error", role: "alert", children: resendError })] })) : null;
|
|
87
|
+
return _jsxs("section", { className: "dl-email dl-quick-email", "aria-label": "Indirizzi email", children: [_jsxs("label", { className: "dl-field", children: [_jsx("span", { children: "Email del destinatario" }), _jsx("input", { type: "email", autoComplete: "off", pattern: "[^ @]+@[^ @]+[.][^ @]+", maxLength: 254, value: value.sendRecipient ? value.recipientEmail : '', placeholder: "cliente@esempio.it", disabled: busy || !config?.enabled, onChange: event => onChange({ ...value, recipientEmail: event.target.value, sendRecipient: !!event.target.value.trim() }) }), _jsx("small", { children: error || (state && !config?.enabled ? 'Puoi condividere questo transfer tramite link.' : 'Lascia vuoto per ottenere solo il link.') })] }), _jsxs("label", { className: "dl-field", children: [_jsx("span", { children: "Email del mittente" }), _jsx("input", { type: "email", autoComplete: "email", pattern: "[^ @]+@[^ @]+[.][^ @]+", maxLength: 254, value: value.replyToEmail ?? sender, readOnly: !config?.replyToEditable, disabled: busy || !config?.enabled, placeholder: sender || 'Indirizzo del sito', onChange: event => onChange({ ...value, replyToEmail: event.target.value }) }), config?.enabled && _jsx("small", { children: "Le risposte arrivano a questo indirizzo." })] }), activityTarget ? createPortal(activity, activityTarget) : activityTarget === undefined ? activity : null] });
|
|
48
88
|
}
|
|
49
89
|
export function DeliveryEmailConfiguration() {
|
|
50
90
|
const [config, setConfig] = useState(null), [owner, setOwner] = useState(''), [downloads, setDownloads] = useState(true), [ready, setReady] = useState(true), [busy, setBusy] = useState(false), [error, setError] = useState(''), [notice, setNotice] = useState('');
|
|
@@ -59,7 +99,7 @@ export function DeliveryEmailConfiguration() {
|
|
|
59
99
|
setError(e instanceof Error ? e.message : 'Impostazioni non disponibili');
|
|
60
100
|
} };
|
|
61
101
|
useEffect(() => { void load(); }, []);
|
|
62
|
-
return _jsxs("section", { className: "dl-card dl-email-config", "aria-labelledby": "dl-email-settings-title", children: [_jsxs("div", { className: "dl-section-head", children: [_jsx("h3", { id: "dl-email-settings-title", children: "Email dei Transfer" }), _jsx("p", { children: "Notifiche al titolare e invio automatico del link ai destinatari." })] }), _jsx("p", { children:
|
|
102
|
+
return _jsxs("section", { className: "dl-card dl-email-config", "aria-labelledby": "dl-email-settings-title", children: [_jsxs("div", { className: "dl-section-head", children: [_jsx("h3", { id: "dl-email-settings-title", children: "Email dei Transfer" }), _jsx("p", { children: "Notifiche al titolare e invio automatico del link ai destinatari." })] }), config && !config.enabled && _jsx("p", { children: "L\u2019invio email \u00E8 disattivato. Puoi condividere i transfer tramite link." }), _jsxs("form", { onSubmit: async (e) => { e.preventDefault(); setBusy(true); setError(''); setNotice(''); try {
|
|
63
103
|
const v = await request('/admin/api/deliveries', { action: 'emailSettings', ownerEmail: owner, notifyDownloads: downloads, notifyReady: ready, settingsVersion: config?.settingsVersion ?? 0 });
|
|
64
104
|
setConfig(v.configuration);
|
|
65
105
|
setOwner(v.configuration.ownerEmail);
|
|
@@ -70,5 +110,5 @@ export function DeliveryEmailConfiguration() {
|
|
|
70
110
|
}
|
|
71
111
|
finally {
|
|
72
112
|
setBusy(false);
|
|
73
|
-
} }, children: [_jsxs("label", { className: "dl-field", children: [_jsx("span", { children: "Email del titolare" }), _jsx("input", { type: "email", autoComplete: "email", maxLength: 254, value: owner, disabled: busy || !config?.settingsEditable, onChange: e => { setOwner(e.target.value); setNotice(''); }, placeholder: "titolare@esempio.it" }), _jsx("small", { children: "Riceve gli avvisi dei Transfer ed \u00E8 l\u2019indirizzo a cui i destinatari possono rispondere. Lascia vuoto per disattivare gli avvisi al titolare." })] }), _jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: ready, disabled: busy || !config?.settingsEditable, onChange: e => { setReady(e.target.checked); setNotice(''); } }), _jsxs("span", { children: [_jsx("strong", { children: "Avvisami quando il transfer \u00E8 pronto" }), _jsx("small", { children: "
|
|
113
|
+
} }, children: [_jsxs("label", { className: "dl-field", children: [_jsx("span", { children: "Email del titolare" }), _jsx("input", { type: "email", autoComplete: "email", maxLength: 254, value: owner, disabled: busy || !config?.settingsEditable, onChange: e => { setOwner(e.target.value); setNotice(''); }, placeholder: "titolare@esempio.it" }), _jsx("small", { children: "Riceve gli avvisi dei Transfer ed \u00E8 l\u2019indirizzo a cui i destinatari possono rispondere. Lascia vuoto per disattivare gli avvisi al titolare." })] }), _jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: ready, disabled: busy || !config?.settingsEditable, onChange: e => { setReady(e.target.checked); setNotice(''); } }), _jsxs("span", { children: [_jsx("strong", { children: "Avvisami quando il transfer \u00E8 pronto" }), _jsx("small", { children: "Ricevi una conferma quando i file sono pronti, anche dopo un\u2019aggiunta al transfer." })] })] }), _jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: downloads, disabled: busy || !config?.settingsEditable, onChange: e => { setDownloads(e.target.checked); setNotice(''); } }), _jsxs("span", { children: [_jsx("strong", { children: "Avvisami quando viene avviato un download" }), _jsx("small", { children: "Ricevi una notifica quando qualcuno avvia il download." })] })] }), _jsxs("div", { className: "dl-link-actions", children: [_jsx("button", { className: "ak-btn ak-btn-primary", type: "submit", disabled: busy || !config?.settingsEditable, children: busy ? 'Salvo…' : 'Salva impostazioni email' }), _jsx("button", { className: "ak-btn", type: "button", disabled: busy, onClick: () => void load(), children: "Ricarica" })] })] }), error && _jsx("p", { role: "alert", className: "ak-error", children: error }), notice && _jsx("p", { role: "status", children: notice })] });
|
|
74
114
|
}
|
|
@@ -65,15 +65,15 @@ export function Overview({ deliveries, expiring, requests, pending, features, bo
|
|
|
65
65
|
const hasBookings = features?.appointments === true;
|
|
66
66
|
// Senza «Visitatori» la riga in cima ha tre riquadri, che devono coprire le dodici colonne.
|
|
67
67
|
const statSpan = hasAnalytics ? 3 : 4;
|
|
68
|
-
return (_jsxs("div", { className: "ov", children: [_jsxs("div", { className: "ov-bar", children: [_jsx("p", { className: "ov-bar-hi", children: "Tutto quello che \u00E8 successo mentre non guardavi." }), _jsx("button", { className: "ak-btn ak-btn-quiet", disabled: storage.busy || analytics.busy, onClick: () => { void storage.load(true); analytics.reload(); }, children: storage.busy || analytics.busy ? "Aggiorno…" : "Aggiorna" })] }), _jsxs("div", { className: "ov-grid", children: [hasAnalytics && (_jsx(Stat, { span: 3, label: "Visitatori", icon: Icon.eye, tone: "blue", hint: RANGE_LABEL[analytics.range], value: totals ? int(totals.visitors.value) : null, quiet: analytics.data && !analytics.data.configured ? "Statistiche non collegate" : undefined, delta: totals?.visitors })), _jsx(Stat, { span: statSpan, label: "Transfer attivi", icon: Icon.delivery, tone: "accent", hint: uploading.length ? `+${uploading.length} in caricamento` : `${downloads} download`, value: deliveries ? String(active.length) : null, onClick: () => go("/deliveries") }), _jsx(Stat, { span: statSpan, label: "Spazio in uso", icon: Icon.archive, tone: "quiet", hint: storage.data ? `${int(storage.data.r2.objects)} foto · ${int(storage.data.b2.files)} file trasferiti` : "Media e transfer", value: storage.data ? size(bytes) : null, quiet: storage.error ?? undefined }), _jsxs("button", { className: "ov-tile ov-cta", "data-span": statSpan, onClick: () => go("/deliveries"), children: [_jsxs("span", { className: "ov-cta-copy", children: [_jsx("strong", { children: "Transfer" }), _jsx("span", { children: "Manda le foto a un cliente" })] }), _jsx("span", { className: "ov-cta-go", "aria-hidden": "true", children: _jsx(Icon.delivery, {}) }), _jsx("span", { className: "ov-cta-bars", "aria-hidden": "true", children: BARS.map((h, i) => _jsx("i", { style: { height: `${h}%` } }, i)) }), expiring > 0 && _jsxs("span", { className: "ov-cta-badge", children: [expiring, " in scadenza"] })] }), !hasAnalytics ? (known && _jsx(LockedCard, { feature: "analytics", go: go })) : (_jsxs("section", { className: "ov-tile ov-chart", "data-span": "8", children: [_jsxs("header", { className: "ov-tile-head", children: [_jsxs("div", { children: [_jsx("h2", { children: "Visite al sito" }), _jsxs("p", { children: ["Pagine viste e sessioni", analytics.data?.providerLabel ? `, da ${analytics.data.providerLabel}` : ""] })] }), _jsx("div", { className: "ov-range", role: "group", "aria-label": "Periodo", children: Object.keys(RANGE_LABEL).map((r) => (_jsx("button", { className: "ov-range-btn" + (analytics.range === r ? " is-on" : ""), onClick: () => analytics.setRange(r), children: RANGE_LABEL[r] }, r))) })] }), !analytics.data ? (_jsx("p", { className: "ak-hint ov-pad", children: "Carico\u2026" })) : !analytics.data.configured ? (_jsx(NotConnected, { providers: analytics.data.providers ?? [] })) : (_jsxs(_Fragment, { children: [analytics.error && _jsx("p", { className: "ak-error ov-pad", children: analytics.error }), _jsxs("div", { className: "ov-chart-figures", children: [_jsx(Figure, { label: "Pagine viste", metric: analytics.data.totals?.pageviews }), _jsx(Figure, { label: "Sessioni", metric: analytics.data.totals?.visits }), _jsx(Figure, { label: "Visitatori", metric: analytics.data.totals?.visitors }), _jsx(Figure, { label: "Tempo medio", metric: averageTime(analytics.data.totals), format: seconds })] }), _jsx(Chart, { points: analytics.data.series ?? [], unit: analytics.data.unit ?? "day" })] }))] })), _jsxs("section", { className: "ov-tile", "data-span": "4", children: [_jsx("header", { className: "ov-tile-head", children: _jsxs("div", { children: [_jsx("h2", { children: "Archivi" }), _jsx("p", { children: "Quanto occupano le due librerie" })] }) }), storage.error ? _jsx("p", { className: "ak-error ov-pad", children: storage.error })
|
|
68
|
+
return (_jsxs("div", { className: "ov", children: [_jsxs("div", { className: "ov-bar", children: [_jsx("p", { className: "ov-bar-hi", children: "Tutto quello che \u00E8 successo mentre non guardavi." }), _jsx("button", { className: "ak-btn ak-btn-quiet", disabled: storage.busy || analytics.busy, onClick: () => { void storage.load(true); analytics.reload(); }, children: storage.busy || analytics.busy ? "Aggiorno…" : "Aggiorna" })] }), _jsxs("div", { className: "ov-grid", children: [hasAnalytics && (_jsx(Stat, { span: 3, label: "Visitatori", icon: Icon.eye, tone: "blue", hint: RANGE_LABEL[analytics.range], value: totals ? int(totals.visitors.value) : null, quiet: analytics.data && !analytics.data.configured ? "Statistiche non collegate" : undefined, delta: totals?.visitors })), _jsx(Stat, { span: statSpan, label: "Transfer attivi", icon: Icon.delivery, tone: "accent", hint: uploading.length ? `+${uploading.length} in caricamento` : `${downloads} ${downloads === 1 ? "richiesta" : "richieste"} di download`, value: deliveries ? String(active.length) : null, onClick: () => go("/deliveries") }), _jsx(Stat, { span: statSpan, label: "Spazio in uso", icon: Icon.archive, tone: "quiet", hint: storage.data ? `${int(storage.data.r2.objects)} foto · ${int(storage.data.b2.files)} file trasferiti` : "Media e transfer", value: storage.data ? size(bytes) : null, quiet: storage.error ?? undefined }), _jsxs("button", { className: "ov-tile ov-cta", "data-span": statSpan, onClick: () => go("/deliveries"), children: [_jsxs("span", { className: "ov-cta-copy", children: [_jsx("strong", { children: "Transfer" }), _jsx("span", { children: "Manda le foto a un cliente" })] }), _jsx("span", { className: "ov-cta-go", "aria-hidden": "true", children: _jsx(Icon.delivery, {}) }), _jsx("span", { className: "ov-cta-bars", "aria-hidden": "true", children: BARS.map((h, i) => _jsx("i", { style: { height: `${h}%` } }, i)) }), expiring > 0 && _jsxs("span", { className: "ov-cta-badge", children: [expiring, " in scadenza"] })] }), !hasAnalytics ? (known && _jsx(LockedCard, { feature: "analytics", go: go })) : (_jsxs("section", { className: "ov-tile ov-chart", "data-span": "8", children: [_jsxs("header", { className: "ov-tile-head", children: [_jsxs("div", { children: [_jsx("h2", { children: "Visite al sito" }), _jsxs("p", { children: ["Pagine viste e sessioni", analytics.data?.providerLabel ? `, da ${analytics.data.providerLabel}` : ""] })] }), _jsx("div", { className: "ov-range", role: "group", "aria-label": "Periodo", children: Object.keys(RANGE_LABEL).map((r) => (_jsx("button", { className: "ov-range-btn" + (analytics.range === r ? " is-on" : ""), onClick: () => analytics.setRange(r), children: RANGE_LABEL[r] }, r))) })] }), !analytics.data ? (_jsx("p", { className: "ak-hint ov-pad", children: "Carico\u2026" })) : !analytics.data.configured ? (_jsx(NotConnected, { providers: analytics.data.providers ?? [] })) : (_jsxs(_Fragment, { children: [analytics.error && _jsx("p", { className: "ak-error ov-pad", children: analytics.error }), _jsxs("div", { className: "ov-chart-figures", children: [_jsx(Figure, { label: "Pagine viste", metric: analytics.data.totals?.pageviews }), _jsx(Figure, { label: "Sessioni", metric: analytics.data.totals?.visits }), _jsx(Figure, { label: "Visitatori", metric: analytics.data.totals?.visitors }), _jsx(Figure, { label: "Tempo medio", metric: averageTime(analytics.data.totals), format: seconds })] }), _jsx(Chart, { points: analytics.data.series ?? [], unit: analytics.data.unit ?? "day" })] }))] })), _jsxs("section", { className: "ov-tile", "data-span": "4", children: [_jsx("header", { className: "ov-tile-head", children: _jsxs("div", { children: [_jsx("h2", { children: "Archivi" }), _jsx("p", { children: "Quanto occupano le due librerie" })] }) }), storage.error ? _jsx("p", { className: "ak-error ov-pad", children: storage.error })
|
|
69
69
|
: !storage.data ? _jsx("p", { className: "ak-hint ov-pad", children: "Conto gli oggetti\u2026" })
|
|
70
70
|
: (_jsxs("div", { className: "ov-store", children: [_jsxs("div", { className: "ov-store-rows", children: [_jsx(StoreRow, { name: "Media del sito", where: "R2", bytes: storage.data.r2.bytes, total: bytes, detail: `${int(storage.data.r2.objects)} file`, onClick: () => go("/media") }), _jsx(StoreRow, { name: "Transfer", where: "Spazio", bytes: storage.data.b2.bytes, total: bytes, detail: `${int(storage.data.b2.packages)} pacchetti · ${int(storage.data.b2.files)} file`, onClick: () => go("/deliveries") }), _jsx(StoreRow, { name: "Cestino", where: "R2", bytes: storage.data.r2.trashBytes, total: bytes, detail: storage.data.r2.trashObjects
|
|
71
71
|
? `${int(storage.data.r2.trashObjects)} file recuperabili — svuotalo per liberare spazio`
|
|
72
72
|
: "vuoto", onClick: () => go("/trash") })] }), _jsxs("dl", { className: "ov-store-notes", children: [storage.data.b2.pendingBytes > 0 && (_jsxs(_Fragment, { children: [_jsx("dt", { children: "In cancellazione" }), _jsxs("dd", { children: [size(storage.data.b2.pendingBytes), ", spariscono da soli entro sette giorni"] })] })), storage.data.r2.partial && (_jsxs(_Fragment, { children: [_jsx("dt", { children: "Attenzione" }), _jsx("dd", { children: "Il conteggio dei media si \u00E8 fermato ai primi 20.000 oggetti: il totale \u00E8 per difetto." })] }))] })] }))] }), !hasBookings
|
|
73
73
|
? known && _jsx(LockedCard, { feature: "appointments", go: go })
|
|
74
|
-
: _jsx(BookingsCard, { rows: bookings, pending: bookingsPending, error: bookingsError, go: go }), _jsxs("section", { className: "ov-tile", "data-span": "8", children: [_jsxs("header", { className: "ov-tile-head", children: [_jsxs("div", { children: [_jsx("h2", { children: "Ultimi transfer" }), _jsx("p", { children: "
|
|
75
|
-
: recent.length === 0 ? _jsx("p", { className: "ak-hint ov-pad", children: "Nessun transfer
|
|
76
|
-
: (_jsxs("table", { className: "ov-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Transfer" }), _jsx("th", { children: "
|
|
74
|
+
: _jsx(BookingsCard, { rows: bookings, pending: bookingsPending, error: bookingsError, go: go }), _jsxs("section", { className: "ov-tile", "data-span": "8", children: [_jsxs("header", { className: "ov-tile-head", children: [_jsxs("div", { children: [_jsx("h2", { children: "Ultimi transfer" }), _jsx("p", { children: "Richieste di download per transfer" })] }), _jsx("button", { className: "ov-more", onClick: () => go("/deliveries"), children: "Tutti" })] }), !deliveries ? _jsx("p", { className: "ak-hint ov-pad", children: "Carico\u2026" })
|
|
75
|
+
: recent.length === 0 ? _jsx("p", { className: "ak-hint ov-pad", children: "Nessun transfer disponibile." })
|
|
76
|
+
: (_jsxs("table", { className: "ov-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Transfer" }), _jsx("th", { children: "Pubblicato" }), _jsx("th", { children: "Peso" }), _jsx("th", { className: "ov-num", children: "Richieste" }), _jsx("th", {})] }) }), _jsx("tbody", { children: recent.map((d) => (_jsxs("tr", { onClick: () => go(`/deliveries/${d.id}`), children: [_jsxs("td", { children: [_jsx("span", { className: "ov-row-main", children: d.title || "Senza nome" }), _jsx("span", { className: "ov-row-sub", children: d.clientName || "—" })] }), _jsx("td", { className: "ov-when", children: day(d.activatedAt || d.updatedAt) }), _jsx("td", { className: "ov-when", children: size(d.storedBytes) }), _jsx("td", { className: "ov-num" + (d.downloadCount ? "" : " is-zero"), children: d.downloadCount }), _jsx("td", { className: "ov-state", children: _jsx(StatusPill, { delivery: d }) })] }, d.id))) })] }))] }), _jsxs("section", { className: "ov-tile", "data-span": "4", children: [_jsxs("header", { className: "ov-tile-head", children: [_jsxs("div", { children: [_jsx("h2", { children: "Ultima richiesta" }), _jsx("p", { children: pending > 0 ? `${pending} ${pending === 1 ? "non letta" : "non lette"}` : "Dal form del sito" })] }), _jsx("button", { className: "ov-more", onClick: () => go("/requests"), children: "Tutte" })] }), !requests ? _jsx("p", { className: "ak-hint ov-pad", children: "Carico\u2026" })
|
|
77
77
|
: requests.length === 0 ? _jsx("p", { className: "ak-hint ov-pad", children: "Nessuna richiesta, per ora." })
|
|
78
78
|
: _jsx(LastRequest, { row: requests[0], go: go })] }), hasAnalytics && _jsx(Top, { span: 4, title: "Pagine pi\u00F9 viste", note: RANGE_LABEL[analytics.range], rows: analytics.data?.pages ?? [], ready: !!analytics.data?.configured, label: (name) => name === "/" ? "/ (home)" : name }), hasAnalytics && _jsx(Top, { span: 4, title: "Da dove arrivano", note: "Siti che portano al tuo", rows: analytics.data?.referrers ?? [], ready: !!analytics.data?.configured, label: (name) => name.replace(/^https?:\/\//, "") })] })] }));
|
|
79
79
|
}
|
|
@@ -220,7 +220,7 @@ function StatusPill({ delivery }) {
|
|
|
220
220
|
if (expired)
|
|
221
221
|
return _jsx("span", { className: "dl-pill", children: "Scaduto" });
|
|
222
222
|
if (delivery.downloadCount > 0)
|
|
223
|
-
return _jsx("span", { className: "dl-pill is-downloaded", children: "
|
|
223
|
+
return _jsx("span", { className: "dl-pill is-downloaded", children: "Download richiesto" });
|
|
224
224
|
return _jsx("span", { className: "dl-pill is-ready", children: "Attivo" });
|
|
225
225
|
}
|
|
226
226
|
/* ---- Formati ------------------------------------------------------------------------- */
|
|
@@ -11,6 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
11
11
|
* sempre.
|
|
12
12
|
*/
|
|
13
13
|
import { useEffect, useState } from "react";
|
|
14
|
+
import { deliveryProgressPercent } from "../lib/delivery-upload";
|
|
14
15
|
import { cancelUpload, dismissUpload, isBusy, pauseUpload, resumeUpload, retryUpload, useUploads, } from "../lib/upload-queue";
|
|
15
16
|
import { dismissMediaUpload, useMediaUploads, } from "../../form/media/media-upload-queue.js";
|
|
16
17
|
export function UploadDock() {
|
|
@@ -28,7 +29,7 @@ export function UploadDock() {
|
|
|
28
29
|
}, [busy]);
|
|
29
30
|
if (!jobs.length && !mediaJobs.length)
|
|
30
31
|
return null;
|
|
31
|
-
return (_jsxs("aside", { className: "uk" + (open ? "" : " is-closed"), "aria-label": "Caricamenti", children: [_jsxs("button", { className: "uk-head", onClick: () => setOpen((value) => !value), "aria-expanded": open, children: [_jsx("span", { className: "uk-head-text", children: summary(jobs, mediaJobs) }), _jsx("span", { className: "uk-chevron", "aria-hidden": "true", children: open ? "▾" : "▴" })] }), open && (_jsxs("ul", { className: "uk-list", children: [mediaJobs.map((job) => _jsx(MediaJob, { job: job }, job.id)), jobs.map((job) => (_jsxs("li", { className: "uk-job is-" + job.state, children: [_jsxs("div", { className: "uk-job-top", children: [_jsx("strong", { children: job.title }), _jsx("span", { children: line(job) })] }), isBusy(job) && (_jsx("div", { className: "uk-track", children: _jsx("i", { style: { width: `${percent(job)}%` } }) })), job.error && _jsx("p", { className: "uk-error", children: job.error }), _jsxs("div", { className: "uk-job-actions", children: [job.state === "running" && (_jsx("button", { className: "ak-btn", onClick: () => pauseUpload(job.id), children: "Pausa" })), job.state === "paused" && (_jsx("button", { className: "ak-btn", onClick: () => resumeUpload(job.id), children: "Riprendi" })), isBusy(job) && job.state !== "cancelling" && (confirmStop === job.id ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "uk-confirm", children: "I file
|
|
32
|
+
return (_jsxs("aside", { className: "uk" + (open ? "" : " is-closed"), "aria-label": "Caricamenti", children: [_jsxs("button", { className: "uk-head", onClick: () => setOpen((value) => !value), "aria-expanded": open, children: [_jsx("span", { className: "uk-head-text", children: summary(jobs, mediaJobs) }), _jsx("span", { className: "uk-chevron", "aria-hidden": "true", children: open ? "▾" : "▴" })] }), open && (_jsxs("ul", { className: "uk-list", children: [mediaJobs.map((job) => _jsx(MediaJob, { job: job }, job.id)), jobs.map((job) => (_jsxs("li", { className: "uk-job is-" + job.state, children: [_jsxs("div", { className: "uk-job-top", children: [_jsx("strong", { children: job.title }), _jsx("span", { children: line(job) })] }), isBusy(job) && (_jsx("div", { className: "uk-track", children: _jsx("i", { style: { width: `${percent(job)}%` } }) })), job.error && _jsx("p", { className: "uk-error", children: job.error }), _jsxs("div", { className: "uk-job-actions", children: [job.state === "running" && (_jsx("button", { className: "ak-btn", onClick: () => pauseUpload(job.id), children: "Pausa" })), job.state === "paused" && (_jsx("button", { className: "ak-btn", onClick: () => resumeUpload(job.id), children: "Riprendi" })), isBusy(job) && job.state !== "cancelling" && (confirmStop === job.id ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "uk-confirm", children: "I file di questo caricamento verranno rimossi." }), _jsx("button", { className: "ak-btn", onClick: () => setConfirmStop(null), children: "No" }), _jsx("button", { className: "ak-btn dl-danger-btn", onClick: () => { cancelUpload(job.id); setConfirmStop(null); }, children: "Annulla il caricamento" })] })) : (_jsx("button", { className: "ak-btn ak-btn-quiet", onClick: () => setConfirmStop(job.id), children: "Annulla" }))), job.state === "failed" && job.retryable && _jsx("button", { className: "ak-btn", onClick: () => void retryUpload(job.id), children: "Riprova" }), !isBusy(job) && (_jsx("button", { className: "ak-btn ak-btn-quiet", onClick: () => dismissUpload(job.id), children: "Togli dall'elenco" }))] })] }, job.id)))] }))] }));
|
|
32
33
|
}
|
|
33
34
|
function MediaJob({ job }) {
|
|
34
35
|
const conversionPercent = job.total ? (job.conversionDone / job.total) * 100 : 0;
|
|
@@ -79,7 +80,7 @@ function line(job) {
|
|
|
79
80
|
const progress = job.progress;
|
|
80
81
|
if (!progress)
|
|
81
82
|
return "Preparo…";
|
|
82
|
-
const phase = progress.phase === "originals" ? "Carico
|
|
83
|
+
const phase = progress.phase === "originals" ? "Carico gli originali"
|
|
83
84
|
: progress.phase === "derivatives" ? "Preparo le anteprime"
|
|
84
85
|
: "Ultimi controlli";
|
|
85
86
|
return `${phase} · ${progress.doneFiles} di ${progress.totalFiles}`;
|
|
@@ -88,5 +89,5 @@ function percent(job) {
|
|
|
88
89
|
const progress = job.progress;
|
|
89
90
|
if (!progress || !progress.totalFiles)
|
|
90
91
|
return 3;
|
|
91
|
-
return Math.max(3,
|
|
92
|
+
return Math.max(3, deliveryProgressPercent(progress));
|
|
92
93
|
}
|
|
@@ -176,7 +176,7 @@ export function MediaGrid({ lib, notice, onPick, onCancel }) {
|
|
|
176
176
|
(manage ? lib.view(i) : lib.toggle(f.key)); }, children: [_jsx("img", { className: "mg-img", draggable: false, src: f.url, alt: "", loading: "lazy",
|
|
177
177
|
/* Il rapporto è noto prima che l'immagine arrivi (lo dà l'elenco): la cella
|
|
178
178
|
riserva subito l'ingombro giusto e la griglia non salta mentre si carica. */
|
|
179
|
-
style: { aspectRatio: f.w && f.h ? `${f.w} / ${f.h}` : "3 / 2" } }), manage && altStatus && (_jsx("span", { className: `mg-alt-badge is-${altStatus}`, children: altStatus === "missing" ? "ALT da completare" : altStatus === "decorative" ? "Decorativa" : "ALT completo" })), _jsx("button", { className: "mg-check", "aria-label": on ? "Deseleziona" : "Seleziona"
|
|
179
|
+
style: { aspectRatio: f.w && f.h ? `${f.w} / ${f.h}` : "3 / 2" } }), manage && altStatus && (_jsx("span", { className: `mg-alt-badge is-${altStatus}`, children: altStatus === "missing" ? "ALT da completare" : altStatus === "decorative" ? "Decorativa" : "ALT completo" })), _jsx("button", { className: "mg-check", "aria-pressed": on, "aria-label": manage ? (on ? "Deseleziona" : "Seleziona") : `${on ? "Deseleziona" : "Seleziona"} ${f.name}`, disabled: locked, onClick: (e) => { e.stopPropagation(); lib.toggle(f.key); }, children: on ? "✓" : "" })] }), _jsx("figcaption", { className: "mg-cap", title: f.name, children: f.name })] }, f.key));
|
|
180
180
|
}) }), !lib.busy && lib.shown.length === 0 && (_jsx("p", { className: "ak-hint", children: lib.prefix === "" && lib.folders.length
|
|
181
181
|
? "Nessuna foto fuori dalle cartelle. Scegline una qui a fianco."
|
|
182
182
|
: "Nessun file qui." })), lib.mode === "pick" && (_jsxs("footer", { className: "mg-foot", children: [_jsxs("span", { className: "ak-hint", children: [sel.size, " selezionate"] }), _jsx("span", { className: "ak-spacer" }), _jsx("button", { className: "ak-btn ak-btn-quiet", disabled: locked, onClick: () => onCancel?.(), children: "Annulla" }), _jsxs("button", { className: "ak-btn ak-btn-primary", disabled: locked || !sel.size, onClick: () => onPick?.(lib.shown.filter((f) => sel.has(f.key))), children: ["Usa ", sel.size > 0 ? `(${sel.size})` : ""] })] }))] }), _jsx(Lightbox, { lib: lib }), _jsx(UploadDialog, { lib: lib })] }));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DIAGNOSTICS } from "./diagnostics.js";
|
|
1
2
|
/* Client Backblaze B2 attraverso l'API S3-compatible.
|
|
2
3
|
*
|
|
3
4
|
* Le chiamate di controllo (create/complete/list/GET) sono firmate qui con SigV4.
|
|
@@ -5,8 +6,27 @@
|
|
|
5
6
|
* PUT a breve durata che il browser usa direttamente verso il bucket privato.
|
|
6
7
|
*/
|
|
7
8
|
|
|
9
|
+
import { storageControlRequest } from "./delivery-storage-access.js";
|
|
10
|
+
|
|
8
11
|
const enc = new TextEncoder();
|
|
9
12
|
import {deliveryStorageScope} from './delivery-storage-scope.js';
|
|
13
|
+
import { DELIVERY_WORK_BUDGET } from './delivery-work-budget.js';
|
|
14
|
+
import { freeWork, FREE_UPLOAD_UNIT, needsPaid } from './delivery-upload-free.js';
|
|
15
|
+
|
|
16
|
+
async function controlText(env,response) {
|
|
17
|
+
if(!freeWork(env))return response.text();
|
|
18
|
+
const budget=freeWork(env),limit=Math.min(FREE_UPLOAD_UNIT.dataBytes,FREE_UPLOAD_UNIT.metadataBytes-budget.used.metadataBytes);
|
|
19
|
+
const reader=response.body?.getReader(),chunks=[];let size=0;
|
|
20
|
+
try{
|
|
21
|
+
if(Number(response.headers.get('content-length'))>limit)throw needsPaid();
|
|
22
|
+
if(reader)for(;;){const {value,done}=await reader.read();if(done)break;size+=value.byteLength;
|
|
23
|
+
if(size>limit)throw needsPaid();chunks.push(value);}
|
|
24
|
+
}finally{await reader?.cancel();}
|
|
25
|
+
budget.readBytes(size);
|
|
26
|
+
const data=new Uint8Array(size);let offset=0;
|
|
27
|
+
for(const chunk of chunks){data.set(chunk,offset);offset+=chunk.byteLength;}
|
|
28
|
+
return new TextDecoder('utf-8',{fatal:true}).decode(data);
|
|
29
|
+
}
|
|
10
30
|
|
|
11
31
|
export function b2Configured(env) {
|
|
12
32
|
return !!(env.B2_ENDPOINT && env.B2_REGION && env.B2_BUCKET &&
|
|
@@ -53,13 +73,38 @@ export async function b2Request(env, method, key, options = {}) {
|
|
|
53
73
|
`SignedHeaders=${signedNames.join(";")}, Signature=${signature}`);
|
|
54
74
|
|
|
55
75
|
const listing = options.query && ("versions" in options.query || "uploads" in options.query);
|
|
56
|
-
|
|
76
|
+
env[DELIVERY_WORK_BUDGET]?.external();
|
|
77
|
+
const started = performance.now();
|
|
78
|
+
const step = { component: 'b2', operation: method.toUpperCase(), stage: options.query?.uploadId ? 'multipart' : listing ? 'listing' : /manifest/.test(key) ? 'manifest' : 'object' };
|
|
79
|
+
try {
|
|
80
|
+
const response = await fetch(url, { method, headers, body, ...(env[DELIVERY_WORK_BUDGET] ? { redirect: 'error' } : {}), signal: options.signal ?? (method === "GET" && !options.query?.uploadId && !listing ? undefined : AbortSignal.timeout(60_000)) });
|
|
81
|
+
env[DIAGNOSTICS]?.record({ ...step, status: response.status, ok: response.ok, durationMs: Math.round(performance.now() - started), providerRequestId: response.headers.get('x-amz-request-id') });
|
|
82
|
+
return response;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
env[DIAGNOSTICS]?.record({ ...step, ok: false, durationMs: Math.round(performance.now() - started) });
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
57
87
|
}
|
|
58
88
|
|
|
59
89
|
export async function b2PresignUploadPart(env, key, uploadId, partNumber, expires = 900) {
|
|
60
90
|
return presignObject(env, "PUT", key, { partNumber: String(partNumber), uploadId }, expires, 3600);
|
|
61
91
|
}
|
|
62
92
|
|
|
93
|
+
// Request-local derivation only: never retain credentials/signing keys across
|
|
94
|
+
// requests, dates, regions or installations.
|
|
95
|
+
export async function b2PresignUploadParts(env, key, uploadId, partNumbers) {
|
|
96
|
+
if (!Array.isArray(partNumbers) || !partNumbers.length || partNumbers.length > 4 ||
|
|
97
|
+
new Set(partNumbers).size !== partNumbers.length ||
|
|
98
|
+
partNumbers.some(n => !Number.isInteger(n) || n < 1 || n > 10_000)) throw new Error('Gruppo di parti non valido');
|
|
99
|
+
deliveryStorageScope(env, 'PUT', key, { uploadId });
|
|
100
|
+
assertConfig(env);
|
|
101
|
+
const amzDate = stamp(new Date());
|
|
102
|
+
const signer = { amzDate, key: await signingKey(env.B2_APPLICATION_KEY, amzDate.slice(0, 8), env.B2_REGION) };
|
|
103
|
+
return Promise.all(partNumbers.map(async partNumber => ({ partNumber,
|
|
104
|
+
url: await presignObject(env, 'PUT', key, { partNumber: String(partNumber), uploadId }, 900, 3600, signer),
|
|
105
|
+
})));
|
|
106
|
+
}
|
|
107
|
+
|
|
63
108
|
export async function b2PresignPutObject(env, key, expires = 900) {
|
|
64
109
|
return presignObject(env, "PUT", key, {}, expires, 3600);
|
|
65
110
|
}
|
|
@@ -73,13 +118,12 @@ export async function b2PresignGetObject(env, key, options = {}) {
|
|
|
73
118
|
return presignObject(env, "GET", key, query, options.expires ?? 86_400, 604_800);
|
|
74
119
|
}
|
|
75
120
|
|
|
76
|
-
async function presignObject(env, method, key, query, expires, maxExpires) {
|
|
121
|
+
async function presignObject(env, method, key, query, expires, maxExpires, signer) {
|
|
77
122
|
query = deliveryStorageScope(env, method, key, query);
|
|
78
123
|
assertConfig(env);
|
|
79
124
|
const url = objectUrl(env, key);
|
|
80
125
|
addQuery(url, query);
|
|
81
|
-
const
|
|
82
|
-
const amzDate = stamp(now);
|
|
126
|
+
const amzDate = signer?.amzDate || stamp(new Date());
|
|
83
127
|
const date = amzDate.slice(0, 8);
|
|
84
128
|
const scope = `${date}/${env.B2_REGION}/s3/aws4_request`;
|
|
85
129
|
url.searchParams.set("X-Amz-Algorithm", "AWS4-HMAC-SHA256");
|
|
@@ -98,17 +142,19 @@ async function presignObject(env, method, key, query, expires, maxExpires) {
|
|
|
98
142
|
const stringToSign = [
|
|
99
143
|
"AWS4-HMAC-SHA256", amzDate, scope, await sha256Bytes(enc.encode(canonical)),
|
|
100
144
|
].join("\n");
|
|
101
|
-
const signature = hex(await hmac(await signingKey(env.B2_APPLICATION_KEY, date, env.B2_REGION), stringToSign));
|
|
145
|
+
const signature = hex(await hmac(signer?.key || await signingKey(env.B2_APPLICATION_KEY, date, env.B2_REGION), stringToSign));
|
|
102
146
|
url.searchParams.set("X-Amz-Signature", signature);
|
|
103
147
|
return url.toString();
|
|
104
148
|
}
|
|
105
149
|
|
|
150
|
+
export const b2ControlRequest = storageControlRequest(b2Request);
|
|
151
|
+
|
|
106
152
|
export async function b2CreateMultipart(env, key, contentType = "application/zip") {
|
|
107
|
-
const res = await
|
|
153
|
+
const res = await b2ControlRequest(env, "POST", key, {
|
|
108
154
|
query: { uploads: "" },
|
|
109
155
|
headers: { "Content-Type": contentType },
|
|
110
156
|
});
|
|
111
|
-
const text = await res
|
|
157
|
+
const text = await controlText(env,res);
|
|
112
158
|
if (!res.ok) throw new Error(`B2 create multipart ${res.status}: ${text.slice(0, 300)}`);
|
|
113
159
|
const uploadId = xml(text, "UploadId");
|
|
114
160
|
if (!uploadId) throw new Error("B2 non ha restituito uploadId");
|
|
@@ -119,30 +165,35 @@ export async function b2CompleteMultipart(env, key, uploadId, parts) {
|
|
|
119
165
|
const body = `<CompleteMultipartUpload>${parts.map((p) =>
|
|
120
166
|
`<Part><PartNumber>${p.partNumber}</PartNumber><ETag>${escapeXml(p.etag)}</ETag></Part>`
|
|
121
167
|
).join("")}</CompleteMultipartUpload>`;
|
|
122
|
-
const res = await
|
|
168
|
+
const res = await b2ControlRequest(env, "POST", key, {
|
|
123
169
|
query: { uploadId },
|
|
124
170
|
headers: { "Content-Type": "application/xml" },
|
|
125
171
|
body,
|
|
126
172
|
});
|
|
127
|
-
const text = await res
|
|
173
|
+
const text = await controlText(env,res);
|
|
128
174
|
if (!res.ok || /<Error[>\s]/.test(text)) throw new Error(`B2 complete multipart ${res.status}: ${text.slice(0, 300)}`);
|
|
129
175
|
return { etag: xml(text, "ETag"), versionId: xml(text, "VersionId") };
|
|
130
176
|
}
|
|
131
177
|
|
|
132
178
|
export async function b2AbortMultipart(env, key, uploadId) {
|
|
133
|
-
const res = await
|
|
179
|
+
const res = await b2ControlRequest(env, "DELETE", key, { query: { uploadId } });
|
|
134
180
|
if (!res.ok && res.status !== 404) {
|
|
135
181
|
throw new Error(`B2 abort multipart ${res.status}: ${(await res.text()).slice(0, 300)}`);
|
|
136
182
|
}
|
|
137
183
|
}
|
|
138
184
|
|
|
139
185
|
export async function b2ListParts(env, key, uploadId) {
|
|
186
|
+
if(freeWork(env)) {
|
|
187
|
+
const page=await b2ListPartsPage(env,key,uploadId,0,{contiguous:false});
|
|
188
|
+
if(page.truncated)throw needsPaid();
|
|
189
|
+
return page.parts;
|
|
190
|
+
}
|
|
140
191
|
const parts = [];
|
|
141
192
|
let marker = "";
|
|
142
193
|
for (let page = 0; page < 10; page++) {
|
|
143
194
|
const query = { uploadId, "max-parts": "1000" };
|
|
144
195
|
if (marker) query["part-number-marker"] = marker;
|
|
145
|
-
const res = await
|
|
196
|
+
const res = await b2ControlRequest(env, "GET", key, { query });
|
|
146
197
|
const text = await res.text();
|
|
147
198
|
if (!res.ok) throw Object.assign(new Error(`B2 list parts ${res.status}: ${text.slice(0, 300)}`), { status: res.status });
|
|
148
199
|
for (const block of text.matchAll(/<Part>([\s\S]*?)<\/Part>/g)) {
|
|
@@ -159,6 +210,41 @@ export async function b2ListParts(env, key, uploadId) {
|
|
|
159
210
|
return parts.filter((p) => Number.isInteger(p.partNumber) && p.partNumber > 0 && p.etag);
|
|
160
211
|
}
|
|
161
212
|
|
|
213
|
+
// New bounded verifier only; the legacy reconciliation contract is unchanged.
|
|
214
|
+
export async function b2ListPartsPage(env, key, uploadId, marker = 0, {contiguous=true}={}) {
|
|
215
|
+
if (!Number.isSafeInteger(marker) || marker < 0 || marker >= 10_000) throw new Error('Marker multipart non valido');
|
|
216
|
+
const res = await b2ControlRequest(env, 'GET', key, { query: { uploadId, 'max-parts': '32', 'part-number-marker': String(marker) } });
|
|
217
|
+
let text;
|
|
218
|
+
if(freeWork(env))text=await controlText(env,res);
|
|
219
|
+
else {
|
|
220
|
+
const reader = res.body?.getReader(), chunks = []; let size = 0;
|
|
221
|
+
try {
|
|
222
|
+
if (Number(res.headers.get('content-length')) > 32768) throw new Error('Risposta ListParts troppo grande');
|
|
223
|
+
if (reader) for (;;) {
|
|
224
|
+
const { value, done } = await reader.read(); if (done) break;
|
|
225
|
+
size += value.length;
|
|
226
|
+
if (size > 32768) throw new Error('Risposta ListParts troppo grande');
|
|
227
|
+
chunks.push(value);
|
|
228
|
+
}
|
|
229
|
+
} finally { await reader?.cancel(); }
|
|
230
|
+
if (!res.ok) throw Object.assign(new Error(`B2 list parts ${res.status}`), { status: res.status });
|
|
231
|
+
const data = new Uint8Array(size); let offset = 0;
|
|
232
|
+
for (const chunk of chunks) { data.set(chunk, offset); offset += chunk.length; }
|
|
233
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
234
|
+
}
|
|
235
|
+
if(!res.ok)throw Object.assign(new Error(`B2 list parts ${res.status}`),{status:res.status});
|
|
236
|
+
const truncated = xml(text, 'IsTruncated').toLowerCase();
|
|
237
|
+
if (!['true','false'].includes(truncated) || !/<ListPartsResult[>\s]/.test(text)) throw new Error('Risposta ListParts non valida');
|
|
238
|
+
const parts = [...text.matchAll(/<Part>([\s\S]*?)<\/Part>/g)].map(([, part]) => ({
|
|
239
|
+
partNumber: Number(xml(part, 'PartNumber')), etag: xml(part, 'ETag'), size: Number(xml(part, 'Size')),
|
|
240
|
+
}));
|
|
241
|
+
if (parts.length > 32 || parts.some((p, i) => !Number.isSafeInteger(p.partNumber)||p.partNumber<1||p.partNumber>10000||
|
|
242
|
+
(contiguous?p.partNumber!==marker+i+1:p.partNumber<=(i?parts[i-1].partNumber:marker)) || !p.etag || p.etag.length > 256 || !Number.isSafeInteger(p.size) || p.size < 1)) throw new Error('Pagina multipart non valida');
|
|
243
|
+
const next = Number(xml(text, 'NextPartNumberMarker'));
|
|
244
|
+
if (truncated === 'true' && (!parts.length || next !== parts.at(-1).partNumber || next >= 10_000)) throw new Error('Cursore multipart non valido');
|
|
245
|
+
return { parts, truncated: truncated === 'true' };
|
|
246
|
+
}
|
|
247
|
+
|
|
162
248
|
export async function b2PutSmall(env, key, body, contentType) {
|
|
163
249
|
let lastFailure = "";
|
|
164
250
|
for (let attempt = 0; attempt < 5; attempt++) {
|
|
@@ -167,18 +253,19 @@ export async function b2PutSmall(env, key, body, contentType) {
|
|
|
167
253
|
/* Ogni tentativo passa di nuovo da b2Request: data e firma SigV4 vengono
|
|
168
254
|
rigenerate. Il PUT è idempotente perché il manifest usa sempre la
|
|
169
255
|
stessa chiave immutabile del pacchetto. */
|
|
170
|
-
res = await
|
|
256
|
+
res = await b2ControlRequest(env, "PUT", key, {
|
|
171
257
|
headers: { "Content-Type": contentType },
|
|
172
258
|
body,
|
|
173
259
|
});
|
|
174
260
|
} catch (error) {
|
|
261
|
+
if (error.code === 'upload_budget_exceeded'||error.retryable===false) throw error;
|
|
175
262
|
lastFailure = error instanceof Error ? error.message : String(error);
|
|
176
263
|
if (attempt === 4) throw new Error(`B2 put: ${lastFailure}`);
|
|
177
264
|
await retryDelay(null, attempt);
|
|
178
265
|
continue;
|
|
179
266
|
}
|
|
180
|
-
if (res.ok) return;
|
|
181
|
-
const detail = (await res
|
|
267
|
+
if (res.ok) { await res.body?.cancel(); return; }
|
|
268
|
+
const detail = (await controlText(env,res)).replace(/\s+/g, " ").trim().slice(0, 300);
|
|
182
269
|
lastFailure = `${res.status}${detail ? `: ${detail}` : ""}`;
|
|
183
270
|
if (!transientStatus(res.status) || attempt === 4) {
|
|
184
271
|
throw new Error(`B2 put ${lastFailure}`);
|
|
@@ -194,20 +281,22 @@ export function b2Get(env, key, range) {
|
|
|
194
281
|
}
|
|
195
282
|
|
|
196
283
|
export async function b2Head(env, key) {
|
|
197
|
-
const res = await
|
|
198
|
-
if (res.status === 404) return null;
|
|
284
|
+
const res = await b2ControlRequest(env, "HEAD", key);
|
|
285
|
+
if (res.status === 404) { await res.body?.cancel(); return null; }
|
|
199
286
|
if ([403, 500, 502, 503, 504].includes(res.status)) {
|
|
200
287
|
// Some edge paths reject HEAD while the same SigV4 GET succeeds. Request
|
|
201
288
|
// exactly one byte and validate Content-Range; never buffer a whole ZIP.
|
|
202
289
|
await res.body?.cancel();
|
|
203
290
|
return b2RangeMetadata(env, key);
|
|
204
291
|
}
|
|
205
|
-
if (!res.ok) throw new Error(`B2 head ${res.status}`);
|
|
206
|
-
|
|
292
|
+
if (!res.ok) { await res.body?.cancel(); throw new Error(`B2 head ${res.status}`); }
|
|
293
|
+
const metadata = { bytes: Number(res.headers.get("content-length")), etag: (res.headers.get("etag") || "").replaceAll('"', "") };
|
|
294
|
+
await res.body?.cancel();
|
|
295
|
+
return metadata;
|
|
207
296
|
}
|
|
208
297
|
|
|
209
298
|
export async function b2RangeMetadata(env, key) {
|
|
210
|
-
const partial = await
|
|
299
|
+
const partial = await b2ControlRequest(env, "GET", key, {headers: {Range: "bytes=0-0"}});
|
|
211
300
|
const range = /^bytes 0-0\/(\d+)$/.exec(partial.headers.get("content-range") || "");
|
|
212
301
|
await partial.body?.cancel();
|
|
213
302
|
if (partial.status === 404) return null;
|