@cardinali-studio/adminkit 2.2.49 → 2.2.51
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 +110 -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 +318 -189
- 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/DeliveryRecipientPreview.d.ts +14 -0
- package/dist/app/routes/DeliveryRecipientPreview.js +49 -0
- 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 +98 -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/api/deliveries.js +58 -17
- package/dist/functions/api/delivery/multipart.js +152 -15
- 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
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { DeliveryRecipientPreview } from "./DeliveryRecipientPreview";
|
|
2
3
|
import { DeliveryEmailConfiguration, DeliveryEmail, saveTransferEmailPreferences } from "./DeliveryEmail";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* diversi per lo stesso oggetto, con etichette diverse per lo stesso campo e — il peggio —
|
|
7
|
-
* default opposti sugli stessi due interruttori. Qui il transfer nuovo è semplicemente questa
|
|
8
|
-
* schermata con i campi vuoti.
|
|
9
|
-
*
|
|
10
|
-
* La forma viene da WeTransfer, allargata allo spazio che abbiamo: a sinistra la colonna del
|
|
11
|
-
* lavoro (file, nome, messaggio, link), a destra le opzioni raggruppate. Sotto, a piena
|
|
12
|
-
* larghezza, la copertina — che ha bisogno di una griglia di foto e in una colonna stretta non
|
|
13
|
-
* ci sta.
|
|
14
|
-
*
|
|
15
|
-
* Due parole che NON esistono più, e perché:
|
|
16
|
-
* «attivazione» non corrispondeva a niente che l'utente volesse fare. Il link funziona da
|
|
17
|
-
* quando esiste; lo stato («in preparazione» → «pronto») lo sa già il sistema
|
|
18
|
-
* e adesso se lo calcola invece di farselo dire con un pulsante. `activate`
|
|
19
|
-
* resta nell'API e lo chiama il salvataggio quando i file sono a posto.
|
|
20
|
-
* «pacchetto» nel 95% dei casi ce n'è uno solo: non ha bisogno di un nome proprio. Si
|
|
21
|
-
* chiama «file», e l'etichetta la eredita dal nome del transfer.
|
|
22
|
-
*
|
|
23
|
-
* Il vocabolario completo (e il perché di ogni parola) sta in DELIVERY-REDESIGN.md §2.
|
|
24
|
-
*/
|
|
25
|
-
import { useEffect, useRef, useState } from "react";
|
|
26
|
-
import { deliverySelectionName, deliverySourceFingerprint, uploadDeliveryHeroObject, preflightDeliverySelection, } from "../lib/delivery-upload";
|
|
4
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { assertUploadCoordinatorSelection, prepareUploadSession, validateNewUploadNegotiation } from '../lib/delivery-upload-coordinator.js';
|
|
6
|
+
import { deliveryProgressPercent, deliveryRelativeName, deliverySelectionName, deliverySourceFingerprint, uploadDeliveryHeroObject, preflightDeliverySelection, } from "../lib/delivery-upload";
|
|
27
7
|
import { isBusy, startUpload, uploadFor, useUploadCompletions, useUploads, } from "../lib/upload-queue";
|
|
8
|
+
import { Icon } from "../ui/icons.js";
|
|
9
|
+
import { transferErrorMessage as errorText } from "../lib/delivery-network.js";
|
|
28
10
|
import { filesFromDrop } from "../lib/delivery-drop";
|
|
29
11
|
/* ============================================================================================
|
|
30
12
|
La colonna: elenco dei transfer
|
|
31
13
|
========================================================================================== */
|
|
14
|
+
export function DeliveryNavHeading({ settingsOpen, onSettings }) {
|
|
15
|
+
return _jsxs("div", { className: "dl-col-heading", children: [_jsx("span", { className: "col-title", children: "Transfer" }), _jsx("button", { type: "button", className: "dl-settings-shortcut", "aria-label": "Impostazioni Transfer", title: "Impostazioni Transfer", "aria-current": settingsOpen ? "page" : undefined, onClick: onSettings, children: _jsx(Icon.settings, {}) })] });
|
|
16
|
+
}
|
|
32
17
|
export function NewDeliveryButton({ onCreate, disabled }) {
|
|
33
18
|
return (_jsx("button", { className: "ak-btn ak-btn-primary", disabled: disabled, onClick: onCreate, children: "Nuovo transfer" }));
|
|
34
19
|
}
|
|
@@ -46,7 +31,8 @@ export function DeliveriesTotal({ rows }) {
|
|
|
46
31
|
const bytes = rows.reduce((sum, row) => sum + (row.storedBytes || 0), 0);
|
|
47
32
|
return (_jsxs("p", { className: "dl-total", children: [rows.length, " transfer \u00B7 ", formatBytes(bytes)] }));
|
|
48
33
|
}
|
|
49
|
-
|
|
34
|
+
const emptyCovers = [];
|
|
35
|
+
export function DeliveryWorkspace({ delivery: fromServer, defaultHeroes = emptyCovers, busy, onAction, onRefresh, onReload, onRead, onDeleted, onOpen, onSelected, }) {
|
|
50
36
|
/* Il transfer «corrente» può venire dal server (l'ho aperto dall'elenco) o essere nato qui
|
|
51
37
|
dentro al primo file rilasciato. Nel secondo caso resta in questo stato finché non si
|
|
52
38
|
ricarica l'elenco. */
|
|
@@ -57,15 +43,46 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
57
43
|
const [heroes, setHeroes] = useState(fromServer?.heroes || []);
|
|
58
44
|
const [heroesClean, setHeroesClean] = useState(fromServer?.heroes || []);
|
|
59
45
|
const [saving, setSaving] = useState(false);
|
|
46
|
+
const [activityTarget, setActivityTarget] = useState(null);
|
|
60
47
|
const [emailPreferences, setEmailPreferences] = useState({ recipientEmail: '', notifyOwner: false, sendRecipient: false });
|
|
61
48
|
const [emailClean, setEmailClean] = useState({ recipientEmail: '', notifyOwner: false, sendRecipient: false });
|
|
62
49
|
const emailDirty = JSON.stringify(emailPreferences) !== JSON.stringify(emailClean);
|
|
63
50
|
const persistEmail = async (id) => {
|
|
64
|
-
if (emailDirty
|
|
51
|
+
if (emailDirty) {
|
|
65
52
|
await saveTransferEmailPreferences(id, emailPreferences);
|
|
66
53
|
setEmailClean({ ...emailPreferences });
|
|
67
54
|
}
|
|
68
55
|
};
|
|
56
|
+
const [advanced, setAdvanced] = useState(false);
|
|
57
|
+
const [filesShown, setFilesShown] = useState(12);
|
|
58
|
+
const [selection, setSelection] = useState([]);
|
|
59
|
+
const [coverFiles, setCoverFiles] = useState([]);
|
|
60
|
+
const [preparing, setPreparing] = useState(false);
|
|
61
|
+
const previewCovers = useMemo(() => {
|
|
62
|
+
if (coverFiles.length)
|
|
63
|
+
return coverFiles;
|
|
64
|
+
return heroes.length ? heroes.map(hero => hero.previewUrl).filter(Boolean) : defaultHeroes;
|
|
65
|
+
}, [coverFiles, heroes, defaultHeroes]);
|
|
66
|
+
const quickFields = useRef(null);
|
|
67
|
+
const fileInputs = useRef(null);
|
|
68
|
+
const optionsTitle = useRef(null);
|
|
69
|
+
const toggleRef = useRef(null);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!advanced)
|
|
72
|
+
return;
|
|
73
|
+
optionsTitle.current?.focus();
|
|
74
|
+
const dismiss = (event) => {
|
|
75
|
+
if (event.key !== "Escape" || event.defaultPrevented)
|
|
76
|
+
return;
|
|
77
|
+
const workspace = toggleRef.current?.closest(".dl-work");
|
|
78
|
+
if (event.target !== document.body && event.target instanceof Node && !workspace?.contains(event.target))
|
|
79
|
+
return;
|
|
80
|
+
setAdvanced(false);
|
|
81
|
+
toggleRef.current?.focus();
|
|
82
|
+
};
|
|
83
|
+
window.addEventListener("keydown", dismiss);
|
|
84
|
+
return () => window.removeEventListener("keydown", dismiss);
|
|
85
|
+
}, [advanced]);
|
|
69
86
|
const [jpegEnabled, setJpegEnabled] = useState(false);
|
|
70
87
|
const [downloadLabelsEnabled, setDownloadLabelsEnabled] = useState(false);
|
|
71
88
|
useEffect(() => {
|
|
@@ -91,8 +108,6 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
91
108
|
const [loadingImages, setLoadingImages] = useState(false);
|
|
92
109
|
const [previewAttempt, setPreviewAttempt] = useState(0);
|
|
93
110
|
const [copied, setCopied] = useState(null);
|
|
94
|
-
const folderRef = useRef(null);
|
|
95
|
-
const filesRef = useRef(null);
|
|
96
111
|
const coverRef = useRef(null);
|
|
97
112
|
const resumeRef = useRef(null);
|
|
98
113
|
const startingRef = useRef(false);
|
|
@@ -103,9 +118,9 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
103
118
|
React, così uscire da questa schermata non lo interrompe. Qui lo si guarda e basta. */
|
|
104
119
|
const jobs = useUploads();
|
|
105
120
|
const job = delivery ? uploadFor(delivery.id, jobs) : undefined;
|
|
106
|
-
const uploading = isBusy(job) ||
|
|
121
|
+
const uploading = isBusy(job) || preparing;
|
|
107
122
|
const heroesDirty = !sameHeroes(heroes, heroesClean);
|
|
108
|
-
const dirty = !same(draft, clean) || heroesDirty || emailDirty;
|
|
123
|
+
const dirty = !same(draft, clean) || heroesDirty || coverFiles.length > 0 || emailDirty;
|
|
109
124
|
const photos = packages.filter(pkg => pkg.state === "ready").flatMap((pkg) => [...pkg.images, ...(moreImages[pkg.id]?.images || [])].map((image) => ({ pkg, image })));
|
|
110
125
|
async function loadMoreImages() {
|
|
111
126
|
if (loadingImages || !delivery)
|
|
@@ -132,18 +147,16 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
132
147
|
}
|
|
133
148
|
}
|
|
134
149
|
useEffect(() => { setMoreImages({}); }, [delivery?.id]);
|
|
150
|
+
const editingSnapshot = useRef(fromServer);
|
|
135
151
|
useEffect(() => {
|
|
136
|
-
if (!fromServer)
|
|
152
|
+
if (!fromServer || fromServer === editingSnapshot.current || dirty)
|
|
137
153
|
return;
|
|
154
|
+
editingSnapshot.current = fromServer;
|
|
138
155
|
setDraft(draftOf(fromServer));
|
|
139
156
|
setClean(draftOf(fromServer));
|
|
140
157
|
setHeroes(fromServer.heroes);
|
|
141
158
|
setHeroesClean(fromServer.heroes);
|
|
142
|
-
}, [fromServer]);
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
folderRef.current?.setAttribute("webkitdirectory", "");
|
|
145
|
-
folderRef.current?.setAttribute("directory", "");
|
|
146
|
-
}, []);
|
|
159
|
+
}, [fromServer, dirty]);
|
|
147
160
|
/* Quando un caricamento finisce — anche mentre si stava guardando un'altra sezione — questa
|
|
148
161
|
schermata rilegge il proprio transfer: i file appena chiusi devono comparire senza che
|
|
149
162
|
nessuno ricarichi niente a mano. */
|
|
@@ -163,24 +176,32 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
163
176
|
Il caricamento vero, la chiusura del pacchetto e l'attivazione li fa la coda,
|
|
164
177
|
che non muore quando questa schermata sparisce. */
|
|
165
178
|
const beginUpload = async (files, resume = null) => {
|
|
166
|
-
if (!files.length || startingRef.current)
|
|
179
|
+
if (!files.length || startingRef.current || isBusy(job) || !quickFields.current?.reportValidity())
|
|
167
180
|
return;
|
|
181
|
+
setPreparing(true);
|
|
168
182
|
startingRef.current = true;
|
|
169
183
|
setFailure(null);
|
|
170
184
|
setNotice(null);
|
|
171
185
|
let target = delivery;
|
|
172
186
|
let packageId = resume?.id || "";
|
|
187
|
+
let uploadSession = resume?.uploadSession;
|
|
173
188
|
let options = resume ? { galleryEnabled: resume.galleryEnabled, webEnabled: resume.webEnabled, webFormat: resume.webFormat || "webp" } : { galleryEnabled: draft.gallery, webEnabled: draft.light, webFormat: draft.light ? draft.webFormat : "webp" };
|
|
174
189
|
try {
|
|
190
|
+
assertUploadCoordinatorSelection(uploadSession);
|
|
175
191
|
// Verifica i limiti fisici prima della richiesta delle capacità del sito.
|
|
176
|
-
preflightDeliverySelection(files, { ...options, manifestVersion: 2 });
|
|
177
|
-
const capabilities = resume ? { manifestVersion: resume.manifestVersion || 1 } :
|
|
192
|
+
const checked = preflightDeliverySelection(files, { ...options, manifestVersion: 2 });
|
|
193
|
+
const capabilities = resume && !uploadSession ? { manifestVersion: resume.manifestVersion || 1 } :
|
|
178
194
|
await onAction({ action: "capabilities" }, { reload: false });
|
|
195
|
+
if (!resume)
|
|
196
|
+
validateNewUploadNegotiation(capabilities);
|
|
179
197
|
options.manifestVersion = capabilities.manifestVersion;
|
|
180
|
-
const { sourceBytes } = preflightDeliverySelection(files, options);
|
|
198
|
+
const { sourceBytes } = options.manifestVersion === 2 ? checked : preflightDeliverySelection(files, options);
|
|
181
199
|
/* L'impronta si legge PRIMA di creare qualsiasi cosa: se il browser ha perso il
|
|
182
200
|
permesso su un file, non resta un transfer a metà né un oggetto orfano. */
|
|
183
201
|
const fingerprint = await deliverySourceFingerprint(files, options.manifestVersion);
|
|
202
|
+
if (resume && resume.sourceFingerprint !== fingerprint) {
|
|
203
|
+
throw new Error("Questi non sono gli stessi file di prima. Riseleziona la cartella o i file del caricamento interrotto.");
|
|
204
|
+
}
|
|
184
205
|
const title = draft.title.trim() || deliverySelectionName(files) || "Transfer";
|
|
185
206
|
if (!target) {
|
|
186
207
|
change({ title });
|
|
@@ -191,55 +212,80 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
191
212
|
setMade(target);
|
|
192
213
|
}
|
|
193
214
|
await persistEmail(target.id);
|
|
194
|
-
|
|
195
|
-
|
|
215
|
+
// quickCreate already persists title, expiry and download labels.
|
|
216
|
+
const detailsChanged = delivery ? !same(draft, clean) :
|
|
217
|
+
!!(draft.clientName || draft.description || draft.licenseNotes || draft.ctaEnabled);
|
|
218
|
+
if (detailsChanged) {
|
|
219
|
+
target = (await onAction({
|
|
220
|
+
action: "update", id: target.id, version: editingSnapshot.current?.version ?? target.version, title,
|
|
196
221
|
clientName: draft.clientName, description: draft.description, licenseNotes: draft.licenseNotes,
|
|
197
|
-
ctaEnabled: draft.ctaEnabled, ctaLabel: draft.ctaLabel, ctaUrl: draft.ctaUrl,
|
|
198
|
-
|
|
222
|
+
ctaEnabled: draft.ctaEnabled, ctaLabel: draft.ctaLabel, ctaUrl: draft.ctaUrl,
|
|
223
|
+
...(downloadLabelsEnabled ? { downloadOriginalsLabel: draft.downloadOriginalsLabel, downloadWebLabel: draft.downloadWebLabel } : {}),
|
|
224
|
+
expiresAt: target.expiresAt, filesExpiresAt: draft.duration === "keep" ? target.filesExpiresAt : expiryFrom(draft.duration),
|
|
199
225
|
}, { reload: false })).delivery;
|
|
200
|
-
const currentLink = primaryLink(target);
|
|
201
|
-
if (!currentLink)
|
|
202
|
-
await onAction({ action: 'createLink', id: target.id, label: 'Link del cliente', pin: draft.pin }, { reload: false });
|
|
203
|
-
else if ((currentLink.pin || '') !== draft.pin)
|
|
204
|
-
await onAction({ action: 'updateLink', id: target.id, linkId: currentLink.id, label: currentLink.label, pin: draft.pin, expiresAt: currentLink.expiresAt }, { reload: false });
|
|
205
226
|
}
|
|
227
|
+
const currentLink = primaryLink(target);
|
|
228
|
+
if (!currentLink)
|
|
229
|
+
await onAction({ action: "createLink", id: target.id, label: "Link del cliente", pin: draft.pin }, { reload: false });
|
|
230
|
+
else if ((currentLink.pin || "") !== draft.pin)
|
|
231
|
+
await onAction({ action: "updateLink", id: target.id,
|
|
232
|
+
linkId: currentLink.id, label: currentLink.label, pin: draft.pin, expiresAt: currentLink.expiresAt }, { reload: false });
|
|
206
233
|
if (resume) {
|
|
207
|
-
if (resume.sourceFingerprint !== fingerprint) {
|
|
208
|
-
throw new Error("Questi non sono gli stessi file di prima. Riseleziona esattamente la cartella " +
|
|
209
|
-
"(o i file) del caricamento interrotto.");
|
|
210
|
-
}
|
|
211
234
|
options = { galleryEnabled: resume.galleryEnabled, webEnabled: resume.webEnabled, webFormat: resume.webFormat || "webp", manifestVersion: resume.manifestVersion || 1 };
|
|
212
235
|
}
|
|
213
236
|
else {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
237
|
+
const session = await prepareUploadSession({ id: target.id, label: title,
|
|
238
|
+
sourceFingerprint: fingerprint, fileCount: files.length, sourceBytes, ...options }, capabilities, { gate: async () => { } });
|
|
239
|
+
if (session) {
|
|
240
|
+
packageId = session.packageId;
|
|
241
|
+
uploadSession = { version: 1, id: packageId, contractHash: session.contractHash };
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const created = await onAction({
|
|
245
|
+
action: "createPackage", id: target.id, label: title,
|
|
246
|
+
...options, sourceFingerprint: fingerprint, fileCount: files.length,
|
|
247
|
+
sourceBytes,
|
|
248
|
+
}, { reload: false });
|
|
249
|
+
packageId = created.package.id;
|
|
250
|
+
options.webFormat = created.package.webFormat || "webp";
|
|
251
|
+
}
|
|
221
252
|
}
|
|
222
|
-
|
|
253
|
+
if (coverFiles.length || heroesDirty)
|
|
254
|
+
target = await commitCovers(target, packageId);
|
|
255
|
+
// Metadata, link and cover are already saved, including when adding a
|
|
256
|
+
// package to an existing transfer. The next detail read can adopt its version.
|
|
257
|
+
const savedDraft = { ...draft, title, duration: "keep" };
|
|
258
|
+
setDraft(savedDraft);
|
|
259
|
+
setClean(savedDraft);
|
|
260
|
+
setSelection([]);
|
|
261
|
+
resumeRef.current = null;
|
|
262
|
+
const completion = startUpload({ deliveryId: target.id, packageId, title, files, options, uploadSession, sourceFingerprint: fingerprint });
|
|
223
263
|
try {
|
|
224
|
-
await refreshAll(target.id);
|
|
264
|
+
await refreshAll(target.id, true);
|
|
225
265
|
}
|
|
226
266
|
finally {
|
|
227
|
-
startingRef.current = false;
|
|
228
267
|
await completion;
|
|
268
|
+
fileInputs.current?.replaceChildren();
|
|
229
269
|
}
|
|
230
270
|
}
|
|
231
271
|
catch (error) {
|
|
232
|
-
setFailure(
|
|
272
|
+
setFailure(errorText(error) + (packageId
|
|
233
273
|
? " Il caricamento resta qui sotto: puoi riprenderlo riselezionando gli stessi file."
|
|
234
274
|
: ""));
|
|
235
|
-
if (target)
|
|
275
|
+
if (target) {
|
|
236
276
|
await refreshAll(target.id).catch(() => { });
|
|
277
|
+
if (packageId) {
|
|
278
|
+
const fresh = await onRead(target.id);
|
|
279
|
+
resumeRef.current = fresh?.packages.find(pkg => pkg.id === packageId) || resume;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
237
282
|
}
|
|
238
283
|
finally {
|
|
239
284
|
startingRef.current = false;
|
|
285
|
+
setPreparing(false);
|
|
240
286
|
}
|
|
241
287
|
};
|
|
242
|
-
const refreshAll = async (id) => {
|
|
288
|
+
const refreshAll = async (id, syncDraft = false) => {
|
|
243
289
|
if (fromServer) {
|
|
244
290
|
await onRefresh();
|
|
245
291
|
return;
|
|
@@ -252,36 +298,63 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
252
298
|
const fresh = await onRead(id);
|
|
253
299
|
if (fresh) {
|
|
254
300
|
setMade(fresh);
|
|
255
|
-
|
|
301
|
+
const saved = draftOf(fresh, draft);
|
|
302
|
+
setClean(saved);
|
|
303
|
+
if (syncDraft)
|
|
304
|
+
setDraft(saved);
|
|
256
305
|
setHeroesClean(fresh.heroes);
|
|
257
306
|
}
|
|
258
307
|
};
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
/* Safari può revocare i riferimenti File appena si azzera l'input, anche se la FileList
|
|
265
|
-
è già stata copiata: si svuota SOLO a lettura finita. */
|
|
266
|
-
if (files.length)
|
|
267
|
-
void beginUpload(files, resume).finally(() => { input.value = ""; });
|
|
308
|
+
const addFiles = (files) => {
|
|
309
|
+
if (!files.length || startingRef.current)
|
|
310
|
+
return;
|
|
311
|
+
setFailure(null);
|
|
312
|
+
setSelection(current => [...current, ...files]);
|
|
268
313
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
input
|
|
314
|
+
// Keep each native input alive until the queue has finished reading its files (Safari).
|
|
315
|
+
const choose = (folder) => {
|
|
316
|
+
const input = document.createElement("input");
|
|
317
|
+
input.type = "file";
|
|
318
|
+
input.multiple = true;
|
|
319
|
+
if (folder)
|
|
320
|
+
input.setAttribute("webkitdirectory", "");
|
|
321
|
+
input.onchange = () => addFiles(Array.from(input.files || []));
|
|
322
|
+
input.oncancel = () => input.remove();
|
|
323
|
+
fileInputs.current?.append(input);
|
|
324
|
+
input.click();
|
|
274
325
|
};
|
|
275
326
|
/* ---- salvataggio: uno solo, che fa tutto ------------------------------------------- */
|
|
327
|
+
async function commitCovers(target, packageId) {
|
|
328
|
+
const chosen = coverFiles.length ? [] : [...heroes];
|
|
329
|
+
if (coverFiles.length && !packageId)
|
|
330
|
+
return target;
|
|
331
|
+
for (const file of coverFiles) {
|
|
332
|
+
const uploaded = await uploadDeliveryHeroObject(target.id, packageId, file);
|
|
333
|
+
chosen.push({ ...uploaded, previewUrl: "" });
|
|
334
|
+
}
|
|
335
|
+
const { delivery: updated } = await onAction({
|
|
336
|
+
action: "commitHeroes", id: target.id, version: target.version, heroes: chosen,
|
|
337
|
+
}, { reload: false });
|
|
338
|
+
setCoverFiles([]);
|
|
339
|
+
setHeroes(updated.heroes);
|
|
340
|
+
setHeroesClean(updated.heroes);
|
|
341
|
+
return updated;
|
|
342
|
+
}
|
|
276
343
|
const save = async () => {
|
|
277
|
-
if (!delivery)
|
|
344
|
+
if (!delivery || !quickFields.current?.reportValidity())
|
|
278
345
|
return;
|
|
279
346
|
setSaving(true);
|
|
280
347
|
setFailure(null);
|
|
281
348
|
setNotice(null);
|
|
349
|
+
let savedRevision;
|
|
282
350
|
try {
|
|
351
|
+
let target = editingSnapshot.current ?? delivery;
|
|
352
|
+
if (coverFiles.length || !sameHeroes(heroes, heroesClean)) {
|
|
353
|
+
target = await commitCovers(target, packages.find(pkg => pkg.state === "ready")?.id);
|
|
354
|
+
savedRevision = target;
|
|
355
|
+
}
|
|
283
356
|
const updated = (await onAction({
|
|
284
|
-
action: "update", id: delivery.id, version:
|
|
357
|
+
action: "update", id: delivery.id, version: target.version, title: draft.title.trim() || delivery.title,
|
|
285
358
|
clientName: draft.clientName, description: draft.description,
|
|
286
359
|
licenseNotes: draft.licenseNotes, ctaEnabled: draft.ctaEnabled,
|
|
287
360
|
ctaLabel: draft.ctaLabel, ctaUrl: draft.ctaUrl, syncPackageLabel: true,
|
|
@@ -290,9 +363,7 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
290
363
|
filesExpiresAt: draft.duration === "keep"
|
|
291
364
|
? delivery.filesExpiresAt : expiryFrom(draft.duration),
|
|
292
365
|
}, { reload: false })).delivery;
|
|
293
|
-
|
|
294
|
-
await onAction({ action: "commitHeroes", id: delivery.id, version: updated.version, heroes }, { reload: false });
|
|
295
|
-
}
|
|
366
|
+
savedRevision = updated;
|
|
296
367
|
if (link) {
|
|
297
368
|
if ((link.pin || "") !== draft.pin) {
|
|
298
369
|
await onAction({
|
|
@@ -312,11 +383,12 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
312
383
|
}
|
|
313
384
|
setClean({ ...draft, duration: "keep" });
|
|
314
385
|
setDraft((current) => ({ ...current, duration: "keep" }));
|
|
315
|
-
|
|
316
|
-
setNotice(link ? "Salvato" : "Link pronto: ora puoi mandarlo");
|
|
386
|
+
setNotice(coverFiles.length && !ready ? "Le copertine saranno salvate con il primo caricamento." : link ? "Salvato" : "Link pronto: ora puoi mandarlo");
|
|
317
387
|
await refreshAll(updated.id);
|
|
318
388
|
}
|
|
319
389
|
catch (error) {
|
|
390
|
+
if (savedRevision)
|
|
391
|
+
editingSnapshot.current = savedRevision;
|
|
320
392
|
setFailure(errorText(error));
|
|
321
393
|
}
|
|
322
394
|
finally {
|
|
@@ -325,7 +397,9 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
325
397
|
};
|
|
326
398
|
/* ---- copertina --------------------------------------------------------------------- */
|
|
327
399
|
const toggleCover = (packageId, index, previewUrl) => {
|
|
328
|
-
|
|
400
|
+
setCoverFiles([]);
|
|
401
|
+
setHeroes((previous) => {
|
|
402
|
+
const current = coverFiles.length ? [] : previous;
|
|
329
403
|
const has = current.some((item) => item.type === "package" && item.packageId === packageId && item.index === index);
|
|
330
404
|
if (has) {
|
|
331
405
|
return current.filter((item) => !(item.type === "package" && item.packageId === packageId && item.index === index));
|
|
@@ -335,32 +409,18 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
335
409
|
return [...current, { type: "package", packageId, index, previewUrl }];
|
|
336
410
|
});
|
|
337
411
|
};
|
|
338
|
-
const
|
|
412
|
+
const selectCovers = (event) => {
|
|
339
413
|
const input = event.currentTarget;
|
|
340
|
-
const files =
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
setFailure(
|
|
414
|
+
const files = Array.from(input.files || []);
|
|
415
|
+
if (!files.length)
|
|
416
|
+
return;
|
|
417
|
+
if (files.length > 8 || files.some(file => !/\.(jpe?g|png|webp)$/i.test(file.name))) {
|
|
418
|
+
setFailure("Scegli fino a otto immagini JPEG, PNG o WebP.");
|
|
345
419
|
return;
|
|
346
420
|
}
|
|
347
|
-
|
|
421
|
+
setCoverFiles(files);
|
|
348
422
|
setFailure(null);
|
|
349
|
-
|
|
350
|
-
const added = [];
|
|
351
|
-
for (const file of files) {
|
|
352
|
-
const uploaded = await uploadDeliveryHeroObject(delivery.id, pkg.id, file);
|
|
353
|
-
added.push({ ...uploaded, previewUrl: "" });
|
|
354
|
-
}
|
|
355
|
-
setHeroes(added);
|
|
356
|
-
}
|
|
357
|
-
catch (error) {
|
|
358
|
-
setFailure(errorText(error));
|
|
359
|
-
}
|
|
360
|
-
finally {
|
|
361
|
-
setSaving(false);
|
|
362
|
-
input.value = "";
|
|
363
|
-
}
|
|
423
|
+
input.value = "";
|
|
364
424
|
};
|
|
365
425
|
/* ---- azioni di servizio ------------------------------------------------------------ */
|
|
366
426
|
const run = async (payload, done) => {
|
|
@@ -402,67 +462,110 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
402
462
|
}
|
|
403
463
|
};
|
|
404
464
|
const copy = async (value, what) => {
|
|
405
|
-
|
|
465
|
+
try {
|
|
466
|
+
await navigator.clipboard.writeText(value);
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
setFailure("Copia non disponibile. Seleziona il link e copialo manualmente.");
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
406
472
|
setCopied(what);
|
|
407
473
|
setTimeout(() => setCopied(null), 2000);
|
|
408
474
|
};
|
|
409
475
|
const state = delivery ? transferState(delivery) : null;
|
|
410
476
|
const expiry = draft.duration === "keep"
|
|
411
477
|
? delivery?.filesExpiresAt || null : expiryFrom(draft.duration);
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
?
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
478
|
+
const filesExpired = !!expiry && Date.parse(expiry) < Date.now();
|
|
479
|
+
const archived = delivery?.status === "archived";
|
|
480
|
+
const previewFileCount = filesExpired ? 0 : selection.length + packages.reduce((sum, pkg) => sum + (pkg.state === "ready" && (!archived || pkg.webEnabled) ? pkg.fileCount : 0), 0);
|
|
481
|
+
const accessEdited = !!link && (draft.pin !== (link.pin || "") || draft.duration !== clean.duration);
|
|
482
|
+
const sharingPaused = accessEdited || saving;
|
|
483
|
+
const shareMessage = delivery && link ? messageFor(delivery, link) : "";
|
|
484
|
+
const sharingCard = link && delivery ? (_jsxs("section", { className: "dl-card dl-link", "aria-label": "Condivisione del transfer", children: [_jsxs("div", { className: "dl-link-head", children: [_jsx("span", { className: "dl-step", children: "Il link per il cliente" }), _jsx("code", { children: link.url })] }), _jsxs("div", { className: "dl-link-actions", children: [_jsx("button", { className: "ak-btn ak-btn-primary", disabled: sharingPaused, onClick: () => void copy(link.url, "link"), children: copied === "link" ? "Copiato" : "Copia il link" }), _jsx("button", { className: "ak-btn", disabled: sharingPaused, onClick: () => void copy(shareMessage, "messaggio"), children: copied === "messaggio" ? "Copiato" : "Copia il messaggio" }), sharingPaused
|
|
485
|
+
? _jsx("button", { className: "ak-btn", disabled: true, children: "Apri in WhatsApp" })
|
|
486
|
+
: _jsx("a", { className: "ak-btn", target: "_blank", rel: "noreferrer", href: `https://wa.me/?text=${encodeURIComponent(shareMessage)}`, children: "Apri in WhatsApp" }), delivery?.canShortenLinks && link.token.length > 16 && (_jsx("button", { className: "ak-btn", disabled: dirty || saving || busy, title: dirty ? "Salva prima le modifiche del transfer" : "Il vecchio indirizzo continuerà a funzionare", onClick: async () => {
|
|
487
|
+
setSaving(true);
|
|
488
|
+
try {
|
|
489
|
+
await run({ action: "shortenLink", id: delivery.id, linkId: link.id }, "Link accorciato. Anche il vecchio indirizzo resta valido.");
|
|
490
|
+
}
|
|
491
|
+
finally {
|
|
492
|
+
setSaving(false);
|
|
493
|
+
}
|
|
494
|
+
}, children: "Accorcia link" }))] }), accessEdited && _jsx("p", { className: "dl-link-stats", role: "status", children: "Salva le modifiche di accesso o scadenza prima di condividere." }), _jsx("p", { className: "dl-link-stats", children: linkStory(link) }), _jsx("div", { ref: setActivityTarget, className: "dl-link-email" }), link.pin && (_jsxs("p", { className: "dl-link-stats", children: ["Codice di accesso ", _jsx("strong", { children: link.pin }), " \u00B7 Incluso nel messaggio."] }))] })) : null;
|
|
495
|
+
return (_jsxs("div", { className: "dl-work", children: [_jsxs("header", { className: "dl-work-head", children: [_jsxs("div", { className: "dl-work-title", children: [state && _jsx("span", { className: "dl-pill is-" + state.kind, children: state.label }), _jsx("h2", { children: draft.title.trim() || (delivery ? delivery.title : "Nuovo transfer") })] }), _jsxs("div", { className: "dl-work-actions", children: [link && (_jsx("a", { className: "ak-btn", href: link.url, target: "_blank", rel: "noreferrer", children: "Apri pagina pubblica" })), link && (_jsx("button", { className: "ak-btn ak-btn-primary", disabled: !dirty || saving || busy || uploading, onClick: () => void save(), children: saving ? "Salvo…" : "Salva" }))] })] }), (failure || notice) && (_jsxs("p", { role: failure ? "alert" : "status", className: failure ? "ak-error dl-feedback" : "dl-feedback is-ok", children: [failure || notice, _jsx("button", { type: "button", "aria-label": "Chiudi", onClick: () => { setFailure(null); setNotice(null); }, children: "\u00D7" })] })), _jsxs("div", { className: "dl-grid dl-compose-grid" + (advanced ? " is-expanded" : ""), children: [_jsxs("div", { className: "dl-main", children: [ready && sharingCard, _jsxs("div", { className: "dl-compose-card", children: [_jsxs("section", { className: "dl-card dl-upload-card", "aria-labelledby": "dl-files-heading", children: [_jsxs("div", { className: "dl-section-head", children: [_jsx("h3", { id: "dl-files-heading", children: "File da consegnare" }), _jsx("p", { children: "Fino a 150 GB per caricamento." })] }), _jsxs("div", { className: "dl-pick", children: [_jsxs("button", { className: "dl-pick-tile", disabled: uploading, onClick: () => choose(false), children: [_jsx(FileIcon, {}), "Aggiungi file"] }), _jsxs("button", { className: "dl-pick-tile", disabled: uploading, onClick: () => choose(true), children: [_jsx(FolderIcon, {}), "Aggiungi una cartella"] }), _jsx("div", { ref: fileInputs, hidden: true })] }), _jsx(DropArea, { disabled: uploading, resuming: !!resumeRef.current, onFiles: addFiles, onError: (error) => setFailure(errorText(error)) }), !!selection.length && _jsxs("div", { className: "dl-selection", "aria-live": "polite", children: [_jsx("strong", { children: selection.length === 1 ? deliveryRelativeName(selection[0]) : selection.length + " file selezionati" }), _jsx("span", { children: formatBytes(selection.reduce((sum, file) => sum + file.size, 0)) }), _jsx("button", { type: "button", className: "ak-btn ak-btn-quiet", disabled: uploading, onClick: () => {
|
|
496
|
+
setSelection([]);
|
|
497
|
+
fileInputs.current?.replaceChildren();
|
|
498
|
+
}, children: "Svuota selezione" }), selection.length > 1 && _jsxs("details", { className: "dl-selected-list", children: [_jsx("summary", { children: "Mostra file" }), _jsx("ul", { children: selection.slice(0, filesShown).map((file, index) => _jsxs("li", { children: [_jsx("span", { children: deliveryRelativeName(file) }), _jsx("button", { className: "ak-btn", type: "button", disabled: uploading, "aria-label": `Rimuovi ${deliveryRelativeName(file)}`, onClick: () => setSelection(files => files.filter((_, i) => i !== index)), children: "\u00D7" })] }, index)) }), filesShown < selection.length && _jsx("button", { className: "ak-btn", type: "button", onClick: () => setFilesShown(count => count + 50), children: "Mostra altri file" })] })] }), job && isBusy(job) && _jsx(Progress, { job: job }), !!packages.length && (_jsx("ul", { className: "dl-files", children: packages.map((pkg) => (_jsxs("li", { className: "dl-file is-" + pkg.state + (confirmPackage === pkg.id ? " is-confirming" : ""), children: [_jsx("span", { className: "dl-file-icon", "aria-hidden": "true", children: pkg.state === "ready" ? "✓" : "…" }), _jsx(PackageContents, { pkg: pkg, confirming: confirmPackage === pkg.id, job: job?.id === pkg.id ? job : undefined, onAction: onAction }), confirmPackage === pkg.id ? (_jsx(_Fragment, { children: _jsxs("span", { className: "dl-file-actions", children: [_jsx("button", { className: "ak-btn", onClick: () => setConfirmPackage(null), children: "Annulla" }), _jsx("button", { className: "ak-btn dl-danger-btn", disabled: uploading, onClick: () => {
|
|
499
|
+
setConfirmPackage(null);
|
|
500
|
+
void run({ action: "deletePackage", id: delivery?.id, packageId: pkg.id }, "File rimossi");
|
|
501
|
+
}, children: "S\u00EC, rimuovi" })] }) })) : (_jsx(_Fragment, { children: _jsxs("span", { className: "dl-file-actions", children: [pkg.state !== "ready" && !(job?.id === pkg.id && isBusy(job)) && (_jsx("button", { className: "ak-btn", disabled: uploading, onClick: () => { resumeRef.current = pkg; setSelection([]); setNotice(resumeHint); }, children: "Riprendi" })), !(job?.id === pkg.id && isBusy(job)) && (_jsx("button", { className: "ak-btn ak-btn-quiet", disabled: uploading, onClick: () => setConfirmPackage(pkg.id), children: "Rimuovi" }))] }) }))] }, pkg.id))) }))] }), _jsxs("form", { ref: quickFields, className: "dl-card dl-about dl-quick-fields", onSubmit: event => { event.preventDefault(); void beginUpload(selection, resumeRef.current); }, children: [_jsx(DeliveryEmail, { id: delivery?.id, value: emailPreferences, onChange: setEmailPreferences, busy: saving || uploading, unsaved: dirty, activityTarget: activityTarget, canResend: ready, hydratePreferences: !!fromServer, onState: p => { setEmailPreferences(p); setEmailClean(p); } }), _jsx(Field, { label: "Titolo", children: _jsx("input", { disabled: uploading || saving, value: draft.title, placeholder: selection.length ? deliverySelectionName(selection) : "Titolo del transfer", onChange: (e) => change({ title: e.target.value }) }) }), _jsx(Field, { label: "Messaggio", wide: true, children: _jsx("textarea", { disabled: uploading || saving, rows: 3, value: draft.description, onChange: (e) => change({ description: e.target.value }) }) }), _jsxs("div", { className: "dl-compose-actions", children: [_jsx("button", { ref: toggleRef, type: "button", className: "ak-btn dl-options-toggle", "aria-label": "Opzioni del transfer", title: "Opzioni del transfer", "aria-expanded": advanced, "aria-controls": "dl-options", onClick: () => setAdvanced(open => !open), children: "\u2022\u2022\u2022" }), _jsx("button", { className: "ak-btn ak-btn-primary", type: "submit", disabled: !selection.length || uploading || saving || busy, children: preparing ? "Caricamento in corso…" : resumeRef.current ? "Riprendi caricamento" : "Trasferisci" })] })] })] }), !ready && sharingCard, !link && delivery && !uploading && (_jsx("button", { className: "ak-btn", disabled: saving || busy, onClick: () => void save(), children: "Ottieni il link" }))] }), _jsxs("div", { className: "dl-compose-companion", children: [_jsx(DeliveryRecipientPreview, { title: draft.title.trim() || (selection.length ? deliverySelectionName(selection) : delivery?.title) || "Titolo del transfer", clientName: draft.clientName.trim(), message: draft.description, covers: previewCovers, locked: !!draft.pin, fileCount: previewFileCount, downloadLabel: archived ? draft.downloadWebLabel || "Scarica versione leggera" : draft.downloadOriginalsLabel || (previewFileCount === 1 ? "Scarica il file" : "Scarica tutti i file"), expiryLabel: expiry ? `${filesExpired ? "File scaduti il" : "Scaricabili fino al"} ${formatDate(expiry)}` : "", notice: filesExpired ? "I file di questa consegna sono scaduti." : archived ? "Gli originali sono stati archiviati." : "", finalLabel: draft.ctaEnabled && draft.ctaUrl ? draft.ctaLabel || "Lascia una recensione" : "" }), _jsxs("aside", { className: "dl-side", id: "dl-options", "aria-label": "Opzioni del transfer", hidden: !advanced, children: [_jsxs("div", { className: "dl-options-head", children: [_jsx("h3", { tabIndex: -1, ref: optionsTitle, children: "Opzioni del transfer" }), _jsx("button", { type: "button", className: "ak-btn", "aria-label": "Chiudi opzioni", onClick: () => { setAdvanced(false); toggleRef.current?.focus(); }, children: "\u00D7" })] }), _jsxs("fieldset", { className: "dl-option-fields", disabled: uploading || saving, children: [_jsxs(Group, { title: "Opzioni di consegna", note: packages.length
|
|
502
|
+
? "Le opzioni dei file caricati sono bloccate. Per cambiarle, rimuovi e ricarica i file."
|
|
503
|
+
: "Puoi cambiare queste opzioni prima di premere Trasferisci.", children: [_jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: draft.gallery, disabled: !!packages.length, onChange: (e) => change({ gallery: e.target.checked }) }), _jsxs("span", { children: [_jsx("strong", { children: "Galleria" }), _jsx("small", { children: "Mostra le foto in anteprima sulla pagina del transfer." })] })] }), _jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: draft.light, disabled: !!packages.length, onChange: (e) => change({ light: e.target.checked, webFormat: jpegEnabled ? draft.webFormat : "webp" }) }), _jsxs("span", { children: [_jsx("strong", { children: "Aggiungi conversione in bassa risoluzione" }), _jsx("small", { children: "Chi scarica pu\u00F2 scegliere foto pi\u00F9 leggere per web e social, fino a 2048 px sul lato lungo." })] })] }), draft.light && (_jsxs("label", { className: "dl-field", children: [_jsx("span", { children: "Formato della conversione" }), _jsxs("select", { className: "dl-select", "aria-label": "Formato della conversione", value: draft.webFormat, disabled: !!packages.length || uploading, onChange: (e) => change({ webFormat: e.target.value === "jpg" ? "jpg" : "webp" }), children: [_jsx("option", { value: "webp", children: "WebP \u2014 file pi\u00F9 piccoli" }), _jsx("option", { value: "jpg", disabled: !jpegEnabled && draft.webFormat !== "jpg", children: "JPG \u2014 massima compatibilit\u00E0" })] }), _jsxs("small", { children: ["2048 px sul lato lungo, senza ingrandire le foto pi\u00F9 piccole. Qualit\u00E0 ", draft.webFormat === "jpg" ? "82%" : "80%", "."] })] }))] }), _jsx(Group, { title: "Cliente", children: _jsx(Field, { label: "Destinatario", hint: "Nome del cliente o dell\u2019azienda. Facoltativo.", children: _jsx("input", { value: draft.clientName, placeholder: "Es. Azienda Rossi", onChange: (e) => change({ clientName: e.target.value }) }) }) }), _jsxs(Group, { title: "Chi pu\u00F2 aprirlo", children: [_jsxs("label", { className: "dl-radio", children: [_jsx("input", { type: "radio", name: "dl-access", checked: !draft.pin, onChange: () => change({ pin: "" }) }), _jsxs("span", { children: [_jsx("strong", { children: "Chiunque abbia il link" }), _jsx("small", { children: "Chi riceve il link pu\u00F2 aprire il transfer e condividerlo." })] })] }), _jsxs("label", { className: "dl-radio", children: [_jsx("input", { type: "radio", name: "dl-access", checked: !!draft.pin, onChange: () => change({ pin: draft.pin || makeCode() }) }), _jsxs("span", { children: [_jsx("strong", { children: "Link e codice di accesso" }), _jsx("small", { children: "Condividi il codice con il destinatario. Dopo 10 tentativi errati, l\u2019accesso \u00E8 sospeso per un\u2019ora." })] })] }), !!draft.pin && (_jsxs("div", { className: "dl-code", children: [_jsx("input", { "aria-label": "Codice di accesso", value: draft.pin, spellCheck: false, onChange: (e) => change({ pin: e.target.value.toUpperCase() }) }), _jsx("button", { className: "ak-btn", onClick: () => change({ pin: makeCode() }), children: "Rigenera" })] }))] }), downloadLabelsEnabled && (_jsxs(Group, { title: "Testi dei pulsanti di download", note: "Lascia vuoto per usare il testo predefinito. Puoi cambiarli anche dopo l\u2019invio, senza ricaricare i file.", children: [delivery?.status !== "archived" && (_jsx(Field, { label: "Pulsante degli originali", children: _jsx("input", { value: draft.downloadOriginalsLabel, maxLength: 80, placeholder: "Scarica i file", onChange: (e) => change({ downloadOriginalsLabel: e.target.value }) }) })), (packages.length ? packages.some(pkg => pkg.webEnabled) : draft.light) && (_jsx(Field, { label: "Pulsante della versione leggera", children: _jsx("input", { value: draft.downloadWebLabel, maxLength: 80, placeholder: "Versione leggera", onChange: (e) => change({ downloadWebLabel: e.target.value }) }) }))] })), _jsxs(Group, { title: "Scadenza", children: [_jsxs("select", { "aria-label": "Scadenza", className: "dl-select", value: draft.duration, onChange: (e) => change({ duration: e.target.value }), children: [delivery && _jsx("option", { value: "keep", children: delivery.filesExpiresAt
|
|
504
|
+
? `Fino al ${formatDate(delivery.filesExpiresAt)}`
|
|
505
|
+
: "Per sempre" }), _jsx("option", { value: "7", children: "7 giorni" }), _jsx("option", { value: "30", children: "30 giorni" }), _jsx("option", { value: "60", children: "60 giorni" }), _jsx("option", { value: "180", children: "6 mesi" }), _jsx("option", { value: "365", children: "1 anno" }), _jsx("option", { value: "forever", children: "Per sempre" })] }), _jsx("p", { className: "dl-note", children: expiry
|
|
506
|
+
? `Dopo il ${formatDate(expiry)} il link continua ad aprirsi, ma i file non si scaricano più.`
|
|
507
|
+
: "I file restano finché non li togli tu." })] }), _jsxs(Group, { title: "Alla fine della pagina", children: [_jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: draft.ctaEnabled, onChange: (e) => change({ ctaEnabled: e.target.checked }) }), _jsxs("span", { children: [_jsx("strong", { children: "Chiedi una recensione" }), _jsx("small", { children: "Un pulsante in fondo, dopo le fotografie." })] })] }), draft.ctaEnabled && (_jsxs(_Fragment, { children: [_jsx(Field, { label: "Testo del pulsante", children: _jsx("input", { value: draft.ctaLabel, onChange: (e) => change({ ctaLabel: e.target.value }) }) }), _jsx(Field, { label: "Indirizzo", hint: "Il link alla tua pagina delle recensioni.", children: _jsx("input", { type: "url", value: draft.ctaUrl, placeholder: "https://\u2026", onChange: (e) => change({ ctaUrl: e.target.value }) }) })] })), _jsx(Field, { label: "Note d'uso", hint: "Cosa pu\u00F2 farci il cliente. Appaiono in fondo alla pagina.", children: _jsx("textarea", { rows: 3, value: draft.licenseNotes, onChange: (e) => change({ licenseNotes: e.target.value }) }) })] }), _jsxs("details", { className: "dl-unavailable", children: [_jsx("summary", { children: "Funzioni aggiuntive non attive" }), _jsxs("div", { children: [" ", _jsxs(Group, { title: "Richiedi pagamento", children: [_jsx("span", { className: "dl-payment-status", children: "Chiedi di attivare la funzione" }), _jsxs("label", { className: "dl-check dl-payment-disabled", children: [_jsx("input", { type: "checkbox", checked: false, disabled: true, "aria-describedby": "dl-payment-description" }), _jsxs("span", { children: [_jsx("strong", { children: "Sblocca gallery e download al saldo" }), _jsx("small", { id: "dl-payment-description", children: "Potrai impostare l\u2019importo da incassare per questa consegna. Il cliente pagher\u00E0 una sola volta per sbloccare la galleria e scaricare i file." })] })] }), _jsx("p", { className: "dl-note", children: "Questa opzione non \u00E8 ancora disponibile: il transfer non richiede pagamenti e segue le impostazioni di accesso qui sopra." })] }), _jsxs(Group, { title: "Selezione del cliente", children: [_jsx("span", { className: "dl-payment-status", children: "Chiedi di attivare la funzione" }), _jsxs("label", { className: "dl-check dl-payment-disabled", children: [_jsx("input", { type: "checkbox", checked: false, disabled: true, "aria-describedby": "dl-selection-description" }), _jsxs("span", { children: [_jsx("strong", { children: "Consenti al cliente di scegliere le foto" }), _jsx("small", { id: "dl-selection-description", children: "Il cliente potr\u00E0 indicare nella galleria quali foto entrano nella sua selezione." })] })] }), _jsx("p", { className: "dl-note", children: "Questa opzione non \u00E8 ancora disponibile: al momento il cliente pu\u00F2 consultare la galleria, se abilitata, ma non salvare una selezione." })] })] })] }), _jsxs("section", { className: "dl-card dl-cover", children: [_jsxs("div", { className: "dl-cover-head", children: [_jsxs("div", { children: [_jsx("span", { className: "dl-step", children: "Copertina" }), _jsxs("p", { children: ["Fino a otto sfondi per la pagina del destinatario.", " ", coverFiles.length ? coverFiles.map(file => file.name).join(", ") : heroes.length
|
|
508
|
+
? `Ne hai scelte ${heroes.length}.`
|
|
509
|
+
: "Nessuna scelta: si userà quella predefinita."] }), _jsx("p", { role: "status", children: !delivery ? "Puoi scegliere uno sfondo per questo transfer prima di inviarlo." : heroesDirty || coverFiles.length > 0
|
|
510
|
+
? "Scelta non ancora salvata: premi Salva modifiche per mostrarla al cliente."
|
|
511
|
+
: heroes.length
|
|
512
|
+
? "Copertine salvate. Una sola immagine resta fissa; più immagini compongono la sequenza."
|
|
513
|
+
: "Scegli le copertine qui: la galleria sotto nella pagina del cliente è separata." })] }), _jsxs("div", { className: "dl-cover-actions", children: [!!photos.length && (_jsx("button", { className: "ak-btn", onClick: () => setPreviewAttempt(value => value + 1), title: "Riprova a caricare le miniature senza cambiare le copertine selezionate", children: "Ricarica anteprime" })), delivery && _jsx("button", { className: "ak-btn ak-btn-primary", disabled: !dirty || saving || busy || uploading, onClick: () => void save(), children: saving ? "Salvo…" : "Salva modifiche" }), _jsx("button", { className: "ak-btn", disabled: saving || uploading, onClick: () => { if (coverRef.current)
|
|
514
|
+
coverRef.current.value = ""; coverRef.current?.click(); }, children: "Carica un'immagine" }), (!!heroes.length || !!coverFiles.length) && (_jsx("button", { className: "ak-btn ak-btn-quiet", disabled: saving, onClick: () => { setHeroes([]); setCoverFiles([]); }, children: "Usa quella predefinita" })), _jsx("input", { ref: coverRef, type: "file", accept: "image/jpeg,image/png,image/webp", multiple: true, hidden: true, onChange: selectCovers })] })] }), packages.some(pkg => (moreImages[pkg.id] ? moreImages[pkg.id].nextCursor : pkg.nextCursor) != null) && (_jsx("button", { className: "ak-btn", disabled: loadingImages, onClick: () => void loadMoreImages(), children: loadingImages ? "Caricamento…" : "Mostra altre foto" })), photos.length ? (_jsx("div", { className: "dl-cover-grid", children: photos.map(({ pkg, image }) => {
|
|
515
|
+
const chosen = heroes.some((item) => item.type === "package" && item.packageId === pkg.id && item.index === image.index);
|
|
516
|
+
return (_jsxs("button", { type: "button", className: chosen ? "is-chosen" : "", disabled: saving, "aria-pressed": chosen, onClick: () => toggleCover(pkg.id, image.index, image.previewUrl), children: [_jsx("img", { src: previewAttempt ? `${image.previewUrl}&previewRetry=${previewAttempt}` : image.previewUrl, alt: image.name, width: image.width, height: image.height, loading: "lazy" }), chosen && _jsx("em", { "aria-hidden": "true", children: "\u2713" })] }, `${pkg.id}-${image.index}`));
|
|
517
|
+
}) })) : ready ? (_jsx("p", { className: "dl-note dl-cover-empty", children: heroes.some((item) => item.type === "object")
|
|
518
|
+
? `${heroes.length} immagini caricate a mano.`
|
|
519
|
+
: "Questo transfer non ha anteprime da cui scegliere: carica un'immagine, oppure resta quella predefinita." })) : null] }), !!delivery && (_jsxs("section", { className: "dl-danger", children: [_jsxs("div", { children: [_jsx("button", { className: "ak-btn ak-btn-quiet", disabled: busy, onClick: () => void duplicate(), children: "Usa come modello" }), delivery.status === "active" && (_jsx("button", { className: "ak-btn ak-btn-quiet", disabled: busy, onClick: () => void run({ action: "archive", id: delivery.id }, "Originali tolti: recuperabili per sette giorni"), children: "Libera spazio: togli gli originali" }))] }), confirmDelete ? (_jsxs("div", { className: "dl-confirm", children: [_jsxs("p", { children: ["Elimino ", _jsx("strong", { children: delivery.title }), photos.length ? ` (${countPhotos(packages)} file, ${formatBytes(delivery.storedBytes)})` : "", "? Il link smette subito di funzionare. La rimozione dei file e degli upload residui viene completata in background. Non si torna indietro."] }), _jsx("button", { className: "ak-btn", onClick: () => setConfirmDelete(false), children: "Annulla" }), _jsx("button", { className: "ak-btn dl-danger-btn", onClick: () => void remove(), children: "S\u00EC, elimina" })] })) : (_jsx("button", { className: "ak-btn ak-btn-quiet", onClick: () => setConfirmDelete(true), children: "Elimina il transfer" }))] }))] })] })] })] })] }));
|
|
453
520
|
}
|
|
454
521
|
/* ============================================================================================
|
|
455
522
|
Impostazioni
|
|
456
523
|
========================================================================================== */
|
|
457
|
-
export function DeliverySettings({ settings, onAction, pickMedia }) {
|
|
524
|
+
export function DeliverySettings({ settings, onAction, onReload, pickMedia }) {
|
|
458
525
|
const [covers, setCovers] = useState(settings.defaultHeroes);
|
|
459
|
-
const [
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
526
|
+
const [saving, setSaving] = useState(false);
|
|
527
|
+
const [notice, setNotice] = useState("");
|
|
528
|
+
const [error, setError] = useState("");
|
|
529
|
+
const dirty = JSON.stringify(covers) !== JSON.stringify(settings.defaultHeroes);
|
|
530
|
+
const savedKey = JSON.stringify(settings.defaultHeroes);
|
|
531
|
+
useEffect(() => { setCovers(JSON.parse(savedKey)); }, [savedKey]);
|
|
532
|
+
const update = (next) => {
|
|
533
|
+
setNotice("");
|
|
534
|
+
setError("");
|
|
535
|
+
if (next.length > 8) {
|
|
536
|
+
setError("Puoi scegliere fino a otto sfondi.");
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
setCovers(next);
|
|
540
|
+
};
|
|
541
|
+
const save = async () => {
|
|
542
|
+
setSaving(true);
|
|
543
|
+
setError("");
|
|
544
|
+
setNotice("");
|
|
545
|
+
try {
|
|
546
|
+
const next = covers.map(url => url.trim()).filter(Boolean);
|
|
547
|
+
await onAction({ action: "saveSettings", defaultHeroes: next }, { reload: false });
|
|
548
|
+
await onReload();
|
|
549
|
+
setCovers(next);
|
|
550
|
+
setNotice("Sfondi predefiniti salvati.");
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
setError(errorText(err));
|
|
554
|
+
}
|
|
555
|
+
finally {
|
|
556
|
+
setSaving(false);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
return (_jsxs("div", { className: "dl-work", children: [_jsx("header", { className: "dl-work-head", children: _jsx("h2", { children: "Impostazioni Transfer" }) }), _jsxs("section", { className: "dl-card dl-cover", "aria-labelledby": "dl-default-covers", children: [_jsxs("div", { className: "dl-cover-head", children: [_jsxs("div", { children: [_jsx("h3", { id: "dl-default-covers", children: "Sfondi predefiniti" }), _jsx("p", { children: "La pagina del destinatario mostra questi sfondi quando il transfer non ha una copertina propria. Puoi sceglierne fino a otto, nell\u2019ordine di visualizzazione." })] }), _jsxs("div", { className: "dl-cover-actions", children: [pickMedia && _jsx("button", { type: "button", className: "ak-btn", disabled: saving, onClick: async () => {
|
|
560
|
+
try {
|
|
561
|
+
const chosen = await pickMedia({ multiple: true });
|
|
562
|
+
if (chosen?.length)
|
|
563
|
+
update([...new Set([...covers, ...chosen])]);
|
|
564
|
+
}
|
|
565
|
+
catch (err) {
|
|
566
|
+
setError(errorText(err));
|
|
567
|
+
}
|
|
568
|
+
}, children: "Scegli dalla libreria" }), _jsx("button", { type: "button", className: "ak-btn ak-btn-primary", disabled: !dirty || saving, onClick: () => void save(), children: saving ? "Salvo…" : "Salva sfondi" })] })] }), !pickMedia && _jsx(Field, { label: "Percorsi delle immagini", hint: "Un percorso /media/ del sito per riga.", children: _jsx("textarea", { rows: 4, disabled: saving, value: covers.join("\n"), placeholder: "/media/copertine/studio.jpg", onChange: event => update(event.target.value.split("\n")) }) }), !!covers.filter(Boolean).length && _jsx("ol", { className: "dl-default-covers", children: covers.map((url, index) => url.startsWith("/media/") && _jsxs("li", { children: [_jsx("img", { src: url, alt: `Sfondo ${index + 1}`, loading: "lazy" }), _jsx("button", { type: "button", className: "ak-btn", disabled: saving, "aria-label": `Rimuovi sfondo ${index + 1}`, onClick: () => update(covers.filter((_, i) => i !== index)), children: "Rimuovi" })] }, index)) }), error && _jsx("p", { className: "ak-error", role: "alert", children: error }), notice && _jsx("p", { role: "status", children: notice })] }), _jsx(DeliveryEmailConfiguration, {})] }));
|
|
466
569
|
}
|
|
467
570
|
/* ============================================================================================
|
|
468
571
|
Pezzi
|
|
@@ -475,6 +578,38 @@ function FileIcon() {
|
|
|
475
578
|
function FolderIcon() {
|
|
476
579
|
return (_jsxs("svg", { viewBox: "0 0 24 24", width: "22", height: "22", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M3 7a2 2 0 0 1 2-2h4l2 2.5h8a2 2 0 0 1 2 2V18a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" }), _jsx("path", { d: "M12 11.5v5M9.5 14h5" })] }));
|
|
477
580
|
}
|
|
581
|
+
function PackageContents({ pkg, confirming, job, onAction }) {
|
|
582
|
+
const [loaded, setLoaded] = useState();
|
|
583
|
+
const [loading, setLoading] = useState(false);
|
|
584
|
+
const [error, setError] = useState(false);
|
|
585
|
+
const files = loaded ?? pkg.fileList;
|
|
586
|
+
const names = files?.names ?? [];
|
|
587
|
+
const count = pkg.fileCount;
|
|
588
|
+
const extra = count === 2 ? " e un altro file" : count > 2 ? ` e altri ${count - 1} file` : "";
|
|
589
|
+
const title = names.length ? names[0] + extra : count ? `${count} file` : "Caricamento";
|
|
590
|
+
const status = pkg.state === "ready"
|
|
591
|
+
? [pkg.galleryEnabled ? "galleria" : "", pkg.webEnabled ? "versione leggera" : ""].filter(Boolean).join(" · ") || "solo originali"
|
|
592
|
+
: isBusy(job) ? job?.state === "paused" ? "caricamento in pausa" : "caricamento in corso" : "caricamento interrotto";
|
|
593
|
+
async function loadMore() {
|
|
594
|
+
if (loading || files?.nextCursor == null)
|
|
595
|
+
return;
|
|
596
|
+
setLoading(true);
|
|
597
|
+
setError(false);
|
|
598
|
+
try {
|
|
599
|
+
const next = await onAction({
|
|
600
|
+
action: "manifestPage", view: "files", id: pkg.deliveryId, packageId: pkg.id, after: files.nextCursor,
|
|
601
|
+
}, { reload: false });
|
|
602
|
+
setLoaded({ names: [...names, ...next.names], nextCursor: next.nextCursor });
|
|
603
|
+
}
|
|
604
|
+
catch {
|
|
605
|
+
setError(true);
|
|
606
|
+
}
|
|
607
|
+
finally {
|
|
608
|
+
setLoading(false);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return _jsxs("div", { className: "dl-file-main", children: [_jsx("strong", { children: confirming ? `Rimuovere ${title}?` : title }), _jsx("span", { children: confirming ? "La rimozione è definitiva." : `${formatBytes(pkg.sourceBytes)} · ${status}` }), count > 1 && names.length > 0 && _jsxs("details", { open: confirming || undefined, className: "dl-package-names", children: [_jsx("summary", { children: `Elenco dei ${count} file` }), _jsx("ul", { children: names.map((name, index) => _jsx("li", { children: name }, index)) }), error && _jsx("span", { role: "alert", children: "Impossibile caricare gli altri nomi." }), files?.nextCursor != null && _jsx("button", { className: "ak-btn", type: "button", disabled: loading, onClick: () => void loadMore(), children: loading ? "Caricamento…" : error ? "Riprova" : "Mostra altri file" })] }, confirming ? "confirm" : "view")] });
|
|
612
|
+
}
|
|
478
613
|
function Group({ title, note, children }) {
|
|
479
614
|
return (_jsxs("section", { className: "dl-group", children: [_jsx("h3", { children: title }), children, note && _jsx("p", { className: "dl-note", children: note })] }));
|
|
480
615
|
}
|
|
@@ -514,7 +649,6 @@ function Progress({ job }) {
|
|
|
514
649
|
if (!progress) {
|
|
515
650
|
return (_jsxs("div", { className: "dl-progress", children: [_jsx("div", { className: "dl-progress-top", children: _jsx("strong", { children: "Preparo il caricamento\u2026" }) }), _jsx("div", { className: "dl-progress-track", children: _jsx("i", { style: { width: "3%" } }) })] }));
|
|
516
651
|
}
|
|
517
|
-
const done = progress.totalFiles ? Math.min(1, progress.doneFiles / progress.totalFiles) : 0;
|
|
518
652
|
const phase = job.state === "paused" ? "In pausa"
|
|
519
653
|
: job.state === "cancelling" ? "Annullamento in corso"
|
|
520
654
|
: job.waitingForNetwork ? "Attendo la connessione e riprovo…"
|
|
@@ -527,7 +661,7 @@ function Progress({ job }) {
|
|
|
527
661
|
const left = progress.phase === "originals" && mbps > 0
|
|
528
662
|
? Math.max(0, (progress.sourceBytes - progress.uploadedBytes) * 8 / (mbps * 1_000_000))
|
|
529
663
|
: null;
|
|
530
|
-
return (_jsxs("div", { className: "dl-progress", children: [_jsxs("div", { className: "dl-progress-top", children: [_jsx("strong", { children: phase }), _jsxs("span", { children: [progress.doneFiles, " di ", progress.totalFiles, left !== null && left > 5 ? ` · ancora ${formatDuration(left)}` : ""] })] }), _jsx("div", { className: "dl-progress-track", children: _jsx("i", { style: { width: `${Math.max(2,
|
|
664
|
+
return (_jsxs("div", { className: "dl-progress", children: [_jsxs("div", { className: "dl-progress-top", children: [_jsx("strong", { children: phase }), _jsxs("span", { children: [progress.doneFiles, " di ", progress.totalFiles, left !== null && left > 5 ? ` · ancora ${formatDuration(left)}` : ""] })] }), _jsx("div", { className: "dl-progress-track", children: _jsx("i", { style: { width: `${Math.max(2, deliveryProgressPercent(progress))}%` } }) }), _jsxs("p", { children: [progress.file || "…", " \u00B7 ", formatBytes(progress.uploadedBytes), mbps > 0 ? ` · ${mbps.toFixed(1)} Mbps` : "", progress.note ? ` · ${progress.note}` : ""] }), _jsx("small", { children: "Puoi continuare a usare il pannello. Tieni aperta questa scheda fino alla fine del caricamento." })] }));
|
|
531
665
|
}
|
|
532
666
|
/* ============================================================================================
|
|
533
667
|
Calcoli
|
|
@@ -575,7 +709,9 @@ function heroKey(item) {
|
|
|
575
709
|
return item.type === "package" ? `p:${item.packageId}:${item.index}` : `o:${item.id}`;
|
|
576
710
|
}
|
|
577
711
|
function primaryLink(delivery) {
|
|
578
|
-
|
|
712
|
+
const links = delivery?.links.filter(item => !item.revokedAt) || [];
|
|
713
|
+
const now = Date.now();
|
|
714
|
+
return links.find(item => !item.expiresAt || Date.parse(item.expiresAt) > now) || links[0] || null;
|
|
579
715
|
}
|
|
580
716
|
function transferState(row) {
|
|
581
717
|
if (row.filesExpiresAt) {
|
|
@@ -590,8 +726,9 @@ function transferState(row) {
|
|
|
590
726
|
if (row.status === "archived")
|
|
591
727
|
return { kind: "archived", label: "Originali tolti" };
|
|
592
728
|
if (row.status === "active") {
|
|
593
|
-
return
|
|
594
|
-
|
|
729
|
+
// Older backends return the total only in the list, but include counters on each detail link.
|
|
730
|
+
return (row.downloadCount > 0 || row.links?.some(link => link.downloadCount > 0))
|
|
731
|
+
? { kind: "downloaded", label: "Download richiesto" }
|
|
595
732
|
: { kind: "ready", label: "Pronto" };
|
|
596
733
|
}
|
|
597
734
|
return { kind: "draft", label: "Senza file" };
|
|
@@ -606,22 +743,26 @@ function makeCode() {
|
|
|
606
743
|
.map((n) => alphabet[n % alphabet.length]).join("");
|
|
607
744
|
return `${pick()}-${pick()}`;
|
|
608
745
|
}
|
|
609
|
-
function messageFor(
|
|
610
|
-
const who =
|
|
746
|
+
function messageFor(delivery, link) {
|
|
747
|
+
const who = delivery.clientName.trim().split(/\s+/)[0];
|
|
748
|
+
const expiry = [link.expiresAt, delivery.expiresAt, delivery.filesExpiresAt]
|
|
749
|
+
.filter((value) => !!value)
|
|
750
|
+
.sort((a, b) => Date.parse(a) - Date.parse(b))[0];
|
|
611
751
|
return [
|
|
612
|
-
`Ciao${who ? ` ${who}` : ""},
|
|
752
|
+
`Ciao${who ? ` ${who}` : ""}, ti condivido il transfer «${delivery.title}».`,
|
|
613
753
|
link.url,
|
|
614
|
-
|
|
615
|
-
expiry ? `Puoi
|
|
754
|
+
link.pin ? `Codice di accesso: ${link.pin}` : "",
|
|
755
|
+
expiry && Date.parse(expiry) > Date.now() ? `Puoi scaricare i file fino al ${formatDate(expiry)}.` : "",
|
|
616
756
|
].filter(Boolean).join("\n");
|
|
617
757
|
}
|
|
618
758
|
function linkStory(link) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
const
|
|
624
|
-
|
|
759
|
+
const opens = link.openedCount === 0 ? "Nessuna apertura"
|
|
760
|
+
: link.openedCount === 1 ? "1 apertura" : `${link.openedCount} aperture`;
|
|
761
|
+
const requests = link.downloadCount === 0 ? "Nessuna richiesta di download"
|
|
762
|
+
: link.downloadCount === 1 ? "1 richiesta di download" : `${link.downloadCount} richieste di download`;
|
|
763
|
+
const lastOpen = link.lastOpenedAt ? ` (${formatDate(link.lastOpenedAt)})` : "";
|
|
764
|
+
const lastRequest = link.lastDownloadAt ? ` (${formatDate(link.lastDownloadAt)})` : "";
|
|
765
|
+
return `${opens}${lastOpen} · ${requests}${lastRequest}`;
|
|
625
766
|
}
|
|
626
767
|
function expiryFrom(duration) {
|
|
627
768
|
if (duration === "forever" || duration === "keep")
|
|
@@ -652,15 +793,3 @@ function formatDuration(seconds) {
|
|
|
652
793
|
const hours = Math.floor(seconds / 3600);
|
|
653
794
|
return `${hours} h ${Math.ceil((seconds % 3600) / 60)} min`;
|
|
654
795
|
}
|
|
655
|
-
function errorText(error) {
|
|
656
|
-
return error instanceof Error ? error.message : String(error);
|
|
657
|
-
}
|
|
658
|
-
function uploadFailure(error) {
|
|
659
|
-
const raw = errorText(error);
|
|
660
|
-
if ((error instanceof DOMException && error.name === "NotReadableError") ||
|
|
661
|
-
raw.includes("requested file could not be read")) {
|
|
662
|
-
return "Il browser non riesce più a leggere uno dei file scelti. " +
|
|
663
|
-
"Riseleziona la stessa cartella e premi «Riprendi».";
|
|
664
|
-
}
|
|
665
|
-
return raw;
|
|
666
|
-
}
|