@cardinali-studio/adminkit 2.2.39 → 2.2.42
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/README.md +73 -0
- package/dist/app/App.js +5 -4
- package/dist/app/app.css +93 -0
- package/dist/app/delivery.d.ts +2 -0
- package/dist/app/delivery.js +10 -3
- package/dist/app/lib/delivery-pricing.d.ts +12 -0
- package/dist/app/lib/delivery-pricing.js +9 -0
- package/dist/app/next.css +11 -0
- package/dist/app/routes/Deliveries.js +14 -14
- package/dist/app/routes/DeliveryCostEstimate.d.ts +5 -0
- package/dist/app/routes/DeliveryCostEstimate.js +17 -0
- package/dist/app/routes/DeliveryDashboard.d.ts +4 -0
- package/dist/app/routes/DeliveryDashboard.js +52 -0
- package/dist/app/routes/Overview.js +2 -2
- package/dist/app/site.d.ts +3 -0
- package/dist/functions/_shared/b2.js +67 -5
- package/dist/functions/_shared/delivery-manifest.js +2 -1
- package/dist/functions/_shared/delivery-purge.js +100 -66
- package/dist/functions/_shared/delivery-storage-dashboard.js +100 -0
- package/dist/functions/api/deliveries.js +14 -3
- package/dist/functions/api/delivery/multipart.js +4 -1
- package/dist/functions/delivery-public/index.js +2 -12
- package/dist/functions/delivery-public/migrations/0010_delivery_storage_cleanup.sql +19 -0
- package/dist/functions/delivery-public/migrations/0011_delivery_storage_dashboard.sql +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -204,6 +204,40 @@ Persistent checkpoints record `store-header-v1`. Checkpoints from earlier releas
|
|
|
204
204
|
|
|
205
205
|
The regression includes 208 synthetic members with the collision at member 53, streaming and indexed readers, ZIP64 offsets, and byte-identical resume against fixtures from 2.2.37.
|
|
206
206
|
|
|
207
|
+
## Permanent delivery storage cleanup
|
|
208
|
+
|
|
209
|
+
Delivery cleanup permanently deletes **all versions and delete markers** in the
|
|
210
|
+
removed package's exact storage prefix, and aborts unfinished multipart uploads.
|
|
211
|
+
Successful deletion requires a subsequent empty listing; a failed or partial sweep
|
|
212
|
+
keeps the database work for retry. No bucket-wide cleanup or lifecycle is installed.
|
|
213
|
+
|
|
214
|
+
Apply `dist/functions/delivery-public/migrations/0010_delivery_storage_cleanup.sql`
|
|
215
|
+
to the consumer's delivery D1 **before** deploying this code. The new
|
|
216
|
+
`delivery_storage_cleanup` table has no foreign keys: its scoped tombstones survive
|
|
217
|
+
removal of a delivery, so a PUT or multipart completion already in flight cannot
|
|
218
|
+
become permanently untracked. The housekeeping caller must continue invoking
|
|
219
|
+
`purgeDue` independently of visits to the admin or public pages. Scopes are checked
|
|
220
|
+
again after 15 minutes in the first hour, then daily, subject to the caller's request
|
|
221
|
+
budget and backlog. Tombstones are deliberately retained indefinitely. `last_error`
|
|
222
|
+
records failed sweeps; `last_checked_at` records successful empty verification.
|
|
223
|
+
|
|
224
|
+
Expired deliveries cannot request new upload signatures or start/finalize new
|
|
225
|
+
packages. An uploading package retains its one-hour metadata grace period;
|
|
226
|
+
its durable scope also catches requests finishing after that grace period.
|
|
227
|
+
A late write can occupy space temporarily until the next successful sweep.
|
|
228
|
+
|
|
229
|
+
The opt-in live regression `scripts/verify-delivery-storage.mjs` uses a new random
|
|
230
|
+
prefix and an in-memory D1 database. It creates versions, a delete marker, an
|
|
231
|
+
unfinished multipart upload, and a PUT authorized before deletion. It checks zero
|
|
232
|
+
remaining versions/bytes/uploads after both deletion and expiration, and compares
|
|
233
|
+
all pre-existing version IDs before and after. Every mutation outside the new
|
|
234
|
+
prefix is refused. Configuration and secret-file paths are arguments; credentials
|
|
235
|
+
are never printed. This test does not deploy a Worker or change lifecycle rules.
|
|
236
|
+
|
|
237
|
+
Do not deploy this cleanup against a populated production bucket when existing
|
|
238
|
+
objects must be preserved: pending/expired deliveries would become eligible for
|
|
239
|
+
permanent deletion. The migration alone is additive and does not enqueue old data.
|
|
240
|
+
|
|
207
241
|
## Development
|
|
208
242
|
|
|
209
243
|
```sh
|
|
@@ -219,3 +253,42 @@ Generated files live in `dist/` and are the only application files included in t
|
|
|
219
253
|
## License
|
|
220
254
|
|
|
221
255
|
[0BSD](./LICENSE). Use it, copy it, change it, ship it. Attribution is appreciated but not required.
|
|
256
|
+
|
|
257
|
+
## Delivery dashboard
|
|
258
|
+
|
|
259
|
+
The delivery overview reads download **requests**, not completed downloads. Active
|
|
260
|
+
transfers have ready packages, unexpired files and at least one valid link.
|
|
261
|
+
|
|
262
|
+
Before enabling `DELIVERY_STORAGE_DASHBOARD=true`, apply
|
|
263
|
+
`dist/functions/delivery-public/migrations/0011_delivery_storage_dashboard.sql` to
|
|
264
|
+
the consumer's delivery D1 database. In the consumer's existing scheduled handler,
|
|
265
|
+
call `verifyDeliveryStorage(env, {maxCalls: 4})` from
|
|
266
|
+
`@cardinali-studio/adminkit/functions/_shared/delivery-storage-dashboard.js` after
|
|
267
|
+
housekeeping. Run the handler every 15 minutes: completed inventories refresh
|
|
268
|
+
hourly; larger inventories resume across invocations. Admin polling also resumes
|
|
269
|
+
due work, and “Verifica ora” forces a fresh check.
|
|
270
|
+
|
|
271
|
+
The read-only scan sums all B2 object versions and uploaded multipart parts,
|
|
272
|
+
including hidden versions and unassigned keys. It stores only complete totals,
|
|
273
|
+
retaining the previous snapshot on failure, and shows the last completion time.
|
|
274
|
+
Concurrent B2 writes can change storage during the scan; this is a measured
|
|
275
|
+
inventory, not the provider's billing statement. Dashboard checks never delete
|
|
276
|
+
objects. The existing preservation policy remains independent of this feature.
|
|
277
|
+
|
|
278
|
+
### Transfer dashboard and creation (2.2.42)
|
|
279
|
+
|
|
280
|
+
Both the full admin and `mountDeliveryAdmin` expose a Dashboard button above
|
|
281
|
+
New transfer. New transfers start with gallery and low-resolution conversion off,
|
|
282
|
+
JPG conversion selected, and a 60-day expiry. Existing packages keep their options.
|
|
283
|
+
Delivery options precede file selection; unavailable features are collapsed.
|
|
284
|
+
|
|
285
|
+
A site may supply `deliveryPricing` in `SiteAdminConfig`, or `pricing` in
|
|
286
|
+
`DeliveryAdminOptions`: `storageUsdPerTb30Days`, `freeStorageGb`,
|
|
287
|
+
`downloadUsdPerGb`, `freeDownloadMultiplier`, and ISO date `verifiedAt`.
|
|
288
|
+
The dashboard projects the last measured storage across the current calendar month;
|
|
289
|
+
it does not reconstruct past usage, subtract a shared free allowance, or infer
|
|
290
|
+
actual download bytes. Missing inventory is shown as unavailable, never zero.
|
|
291
|
+
The information dialog explains those limits. Rates are supplied by the consumer,
|
|
292
|
+
not inferred from storage credentials or provider names.
|
|
293
|
+
The dedicated delivery entry now initializes its own module configuration;
|
|
294
|
+
consumers must remove the old internal `setSiteConfig` workaround.
|
package/dist/app/App.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { DeliveryDashboard } from "./routes/DeliveryDashboard.js";
|
|
2
3
|
/* Il guscio del pannello: tre colonne fisse.
|
|
3
4
|
*
|
|
4
5
|
* 1. dove sono la navigazione principale — non cambia mai
|
|
@@ -91,7 +92,7 @@ function CurrentAdminApp({ adminInterface, setAdminInterface, }) {
|
|
|
91
92
|
const requests = useRequests();
|
|
92
93
|
const publish = usePublish();
|
|
93
94
|
const deliverySettingsOpen = section === "deliveries" && route[1] === "settings";
|
|
94
|
-
const activeDeliveryId = section === "deliveries" && !deliverySettingsOpen ? route[1] : undefined;
|
|
95
|
+
const activeDeliveryId = section === "deliveries" && !deliverySettingsOpen && route[1] !== "new" ? route[1] : undefined;
|
|
95
96
|
/* Come Richieste, Consegne carica subito l'elenco: il badge "in scadenza" deve
|
|
96
97
|
esistere prima di entrare nella sezione. Il dettaglio resta pigro. */
|
|
97
98
|
const deliveries = useDeliveries(activeDeliveryId);
|
|
@@ -293,10 +294,10 @@ function CurrentAdminApp({ adminInterface, setAdminInterface, }) {
|
|
|
293
294
|
else
|
|
294
295
|
next.add(id);
|
|
295
296
|
return next;
|
|
296
|
-
}) }) })] })), section === "deliveries" && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "col-head col-head-actions", children: [_jsx("span", { className: "col-title", children: "Transfer" }), _jsx(NewDeliveryButton, { onCreate: () => {
|
|
297
|
+
}) }) })] })), section === "deliveries" && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "col-head col-head-actions dl-col-head", children: [_jsx("span", { className: "col-title", children: "Transfer" }), _jsxs("button", { type: "button", className: "ak-btn dl-dashboard-button" + (!activeDeliveryId && !deliverySettingsOpen && route[1] !== "new" ? " is-on" : ""), "aria-current": !activeDeliveryId && !deliverySettingsOpen && route[1] !== "new" ? "page" : undefined, onClick: () => { setQuickSelectedId(undefined); go("/deliveries"); }, children: [_jsx(Icon.grid, {}), _jsx("span", { children: "Dashboard" })] }), _jsx(NewDeliveryButton, { onCreate: () => {
|
|
297
298
|
setQuickSelectedId(undefined);
|
|
298
299
|
setQuickKey((value) => value + 1);
|
|
299
|
-
go("/deliveries");
|
|
300
|
+
go("/deliveries/new");
|
|
300
301
|
} })] }), _jsx("div", { className: "col-body", children: deliveries.error ? _jsx("p", { className: "ak-error", children: deliveries.error })
|
|
301
302
|
: !deliveries.rows ? _jsx("p", { className: "ak-hint", children: "Carico\u2026" })
|
|
302
303
|
: deliveries.rows.length === 0 ? _jsx("p", { className: "ak-hint", children: "Nessun transfer, per ora." })
|
|
@@ -340,7 +341,7 @@ function CurrentAdminApp({ adminInterface, setAdminInterface, }) {
|
|
|
340
341
|
: _jsx(MediaGrid, { lib: media })), view === "trash" && _jsx(Trash, {}), section === "requests" && (requests.error ? _jsx("p", { className: "ak-error", children: requests.error })
|
|
341
342
|
: openReq ? (_jsx(RequestDetail, { row: openReq, onMark: (h) => void requests.mark([openReq.id], h), onRemove: () => { void requests.remove([openReq.id]); go("/requests"); } }))
|
|
342
343
|
: _jsx("p", { className: "pane-empty ak-hint", children: requests.rows?.length ? "Scegli una richiesta dall'elenco." : "" })), section === "deliveries" && (deliveries.error ? _jsx("p", { className: "ak-error", children: deliveries.error })
|
|
343
|
-
: deliverySettingsOpen ? (_jsx(DeliverySettings, { settings: deliveries.settings, onAction: deliveries.action, pickMedia: pickMedia })) : activeDeliveryId && !deliveries.detail ? (_jsx("p", { className: "pane-empty ak-hint", children: "Carico\u2026" })) : (
|
|
344
|
+
: deliverySettingsOpen ? (_jsx(DeliverySettings, { settings: deliveries.settings, onAction: deliveries.action, pickMedia: pickMedia })) : activeDeliveryId && !deliveries.detail ? (_jsx("p", { className: "pane-empty ak-hint", children: "Carico\u2026" })) : !activeDeliveryId && route[1] !== "new" ? (_jsx(DeliveryDashboard, { onCreate: () => { setQuickSelectedId(undefined); setQuickKey(v => v + 1); go("/deliveries/new"); }, onOpen: id => go(`/deliveries/${id}`) })) : (
|
|
344
345
|
/* Un transfer nuovo e uno già spedito sono la stessa schermata: cambia solo se
|
|
345
346
|
arriva già con dei dati. La `key` la rimonta quando si passa da un transfer
|
|
346
347
|
all'altro, e quando «Nuovo transfer» chiede di ricominciare da capo. */
|
package/dist/app/app.css
CHANGED
|
@@ -2360,3 +2360,96 @@ body:has(.uk) .pane-body { padding-bottom: 190px; }
|
|
|
2360
2360
|
}
|
|
2361
2361
|
:root[data-admin-interface="next"] .rail-foot > .ak-release-control.ak-release-control{width:auto;height:auto;overflow:visible}
|
|
2362
2362
|
:root[data-admin-interface="next"] .rail-foot > .ak-release-control.ak-release-control > .ak-release-trigger{width:auto;min-width:104px;display:inline-flex;gap:9px;padding:0 14px;color:var(--ak-rail-ink-on);font:600 12px/1 var(--ak-font);overflow:visible}
|
|
2363
|
+
|
|
2364
|
+
/* Consegne: panoramica e inventario B2, con dati di verifica separati dai contatori. */
|
|
2365
|
+
.dd-dashboard { max-width: 1440px; width: 100%; min-width: 0; margin: 0 auto; display: grid; gap: 22px; padding: 8px 0 28px; }
|
|
2366
|
+
.dd-dashboard>* { min-width: 0; }
|
|
2367
|
+
.dd-heading>div,.dd-storage-head>div { min-width: 0; }
|
|
2368
|
+
.dd-heading h2,.dd-metric>span { overflow-wrap: anywhere; }
|
|
2369
|
+
.dd-heading,.dd-storage-head { display: flex; gap: 20px; align-items: center; justify-content: space-between; }
|
|
2370
|
+
.dd-heading h2 { margin: 5px 0 8px; font-size: 28px; font-weight: 600; letter-spacing: -.7px; }
|
|
2371
|
+
.dd-heading p,.dd-storage-head p { margin: 0; color: var(--ak-ink-quiet); font-size: 12px; line-height: 1.6; }
|
|
2372
|
+
.dd-heading .dd-eyebrow { text-transform: uppercase; letter-spacing: 1.5px; font-size: 10px; font-weight: 600; }
|
|
2373
|
+
.dd-metrics,.dd-storage-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
|
|
2374
|
+
.dd-metrics>.dd-metric,.dd-storage,.dd-transfers { background: var(--ak-panel); border: 1px solid var(--ak-line); border-radius: var(--ak-radius); }
|
|
2375
|
+
.dd-metric { padding: 19px; min-width: 0; }
|
|
2376
|
+
.dd-metric>span { display: block; color: var(--ak-ink-quiet); font-size: 11px; }
|
|
2377
|
+
.dd-metric>strong { display: block; font-size: clamp(23px,2.1vw,34px); line-height: 1.2; font-weight: 550; letter-spacing: -.7px; margin: 13px 0 10px; font-variant-numeric: tabular-nums; }
|
|
2378
|
+
.dd-metric>p { margin: 0; font-size: 10px; line-height: 1.6; color: var(--ak-ink-quiet); }
|
|
2379
|
+
.dd-storage-head { padding: 20px; border-bottom: 1px solid var(--ak-line); }
|
|
2380
|
+
.dd-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
|
|
2381
|
+
.dd-title-row h3 { font-size: 14px; font-weight: 600; margin: 0; }
|
|
2382
|
+
.dd-title-row>span { font-size: 11px; color: var(--ak-ink-quiet); }
|
|
2383
|
+
.dd-status { padding: 4px 9px; border-radius: 30px; background: color-mix(in srgb,#2b825d 10%,var(--ak-panel)); color: #28744f !important; }
|
|
2384
|
+
.dd-status.is-running { color: var(--ak-ink) !important; background: var(--ak-bg); }
|
|
2385
|
+
.dd-status.is-error { background: color-mix(in srgb,#bd6d2a 12%,var(--ak-panel)); color: #aa612a !important; }
|
|
2386
|
+
.dd-storage-head p { margin-top: 8px; font-size: 11px; }
|
|
2387
|
+
.dd-storage-grid { gap: 0; }
|
|
2388
|
+
.dd-storage-grid>.dd-metric+ .dd-metric { border-left: 1px solid var(--ak-line); }
|
|
2389
|
+
.dd-storage-grid .dd-metric>strong { font-size: 25px; }
|
|
2390
|
+
.dd-footnote { font-size: 10px; color: var(--ak-ink-quiet); margin: 0; line-height: 1.7; }
|
|
2391
|
+
.dd-storage>.dd-footnote { border-top: 1px solid var(--ak-line); padding: 12px 20px; }
|
|
2392
|
+
.dd-transfers { padding: 20px; }
|
|
2393
|
+
.dd-transfers>.dd-title-row { justify-content: space-between; margin-bottom: 8px; }
|
|
2394
|
+
.dd-table-wrap { overflow-x: auto; margin-top: 18px; }
|
|
2395
|
+
.dd-table-wrap table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
|
|
2396
|
+
.dd-table-wrap th { font-size: 10px; font-weight: 500; color: var(--ak-ink-quiet); padding: 0 12px 12px; white-space: nowrap; }
|
|
2397
|
+
.dd-table-wrap td { padding: 13px 12px; border-top: 1px solid var(--ak-line); font-variant-numeric: tabular-nums; }
|
|
2398
|
+
.dd-table-wrap th:first-child,.dd-table-wrap td:first-child { padding-left: 0; }
|
|
2399
|
+
.dd-transfer-link { border: 0; padding: 0; background: transparent; cursor: pointer; color: var(--ak-ink); text-align: left; font: inherit; }
|
|
2400
|
+
.dd-transfer-link strong { display: block; font-size: 12px; font-weight: 550; }
|
|
2401
|
+
.dd-transfer-link span { display: block; font-size: 10px; margin-top: 4px; color: var(--ak-ink-quiet); }
|
|
2402
|
+
.dd-transfer-link:hover strong { text-decoration: underline; }
|
|
2403
|
+
.dd-request { display: inline-block; white-space: nowrap; font-size: 10px; color: #28744f; }
|
|
2404
|
+
.dd-request.is-pending { color: var(--ak-ink-quiet); }
|
|
2405
|
+
:root[data-theme="dark"] .dd-status:not(.is-running):not(.is-error),:root[data-theme="dark"] .dd-request:not(.is-pending) { color: #80c7a0 !important; }
|
|
2406
|
+
:root[data-theme="dark"] .dd-status.is-error { color: #eeb177 !important; }
|
|
2407
|
+
.dd-notice,.dd-error { margin: 0; padding: 12px 20px; font-size: 12px; line-height: 1.6; color: var(--ak-ink-quiet); }
|
|
2408
|
+
.dd-empty { padding: 25px 0; color: var(--ak-ink-quiet); font-size: 12px; }
|
|
2409
|
+
@media(max-width:1100px) { .dd-metrics,.dd-storage-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } .dd-storage-grid>.dd-metric:nth-child(3) { border-left: 0; } .dd-storage-grid>.dd-metric:nth-child(n+3) { border-top: 1px solid var(--ak-line); } }
|
|
2410
|
+
@media(max-width:600px) { .dd-heading,.dd-storage-head { align-items: flex-start; flex-direction: column; gap: 12px; } .dd-heading h2 { font-size: 25px; } .dd-dashboard { gap: 16px; } .dd-metric { padding: 14px; } .dd-table-wrap table { min-width: 600px; } }
|
|
2411
|
+
@media(max-width:700px) { .app:has(.dd-dashboard)>.col { display: none; } .app:has(.dd-dashboard)>.pane { grid-column: 2 / -1; } }
|
|
2412
|
+
|
|
2413
|
+
/* Transfer navigation and optional client-facing cost projection. */
|
|
2414
|
+
.dl-dashboard-button.is-on { color: var(--ak-accent); border-color: var(--ak-accent); background: var(--ak-panel); }
|
|
2415
|
+
.dd-cost { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px; background: var(--ak-panel); border: 1px solid var(--ak-line); border-radius: var(--ak-radius); }
|
|
2416
|
+
.dd-cost h3 { margin: 0; font-size: 14px; }
|
|
2417
|
+
.dd-cost p { margin: 8px 0 0; color: var(--ak-ink-quiet); font-size: 12px; line-height: 1.6; }
|
|
2418
|
+
.dd-cost .dd-cost-caveat { font-size: 11px; max-width: 70ch; }
|
|
2419
|
+
.dd-cost-info { display: inline-grid; place-items: center; flex: none; padding: 0; width: 28px; height: 28px; min-height: 28px; border-radius: 50%; font: 600 13px Georgia, serif; }
|
|
2420
|
+
.dd-cost-amount { display: grid; gap: 8px; flex: none; text-align: right; }
|
|
2421
|
+
.dd-cost-amount strong { font-size: clamp(24px, 2.5vw, 34px); font-weight: 500; letter-spacing: -.035em; }
|
|
2422
|
+
.dd-cost-amount span { color: var(--ak-ink-quiet); font-size: 11px; }
|
|
2423
|
+
.dd-cost-dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; color: var(--ak-ink); background: var(--ak-panel); border: 1px solid var(--ak-line); border-radius: var(--ak-radius); box-shadow: var(--ak-shadow); }
|
|
2424
|
+
.dd-cost-dialog::backdrop { background: rgb(0 0 0 / .48); }
|
|
2425
|
+
.dd-cost-dialog-inner { padding: 24px; }
|
|
2426
|
+
.dd-cost-dialog header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
|
|
2427
|
+
.dd-cost-dialog h2 { margin: 6px 0 0; font-size: 24px; letter-spacing: -.025em; }
|
|
2428
|
+
.dd-cost-dialog dl { margin: 24px 0 0; display: grid; gap: 20px; }
|
|
2429
|
+
.dd-cost-dialog dt { font-weight: 600; font-size: 13px; }
|
|
2430
|
+
.dd-cost-dialog dd { margin: 6px 0 0; color: var(--ak-ink-quiet); font-size: 13px; line-height: 1.65; }
|
|
2431
|
+
.dd-cost-dialog .dd-footnote { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--ak-line); }
|
|
2432
|
+
@media(max-width:700px) { .dd-cost { align-items: flex-start; flex-direction: column; gap: 16px; } .dd-cost-amount { text-align: left; } }
|
|
2433
|
+
|
|
2434
|
+
.dl-col-head { flex-direction: column; align-items: stretch; gap: 12px; }
|
|
2435
|
+
.dl-dashboard-button { display: flex; align-items: center; justify-content: flex-start; gap: 10px; }
|
|
2436
|
+
|
|
2437
|
+
/* Transfer: file e dettagli nel flusso principale, impostazioni compatte a fianco. */
|
|
2438
|
+
.dl-section-head { padding: 20px 20px 0; }
|
|
2439
|
+
.dl-section-head h3 { margin: 0; font: 600 15px/1.4 var(--ak-font); }
|
|
2440
|
+
.dl-section-head p { margin: 6px 0 0; color: var(--ak-ink-quiet); font-size: 12px; line-height: 1.5; }
|
|
2441
|
+
.dl-about > .dl-section-head { grid-column: 1/-1; padding: 0 0 4px; }
|
|
2442
|
+
.dl-about { padding: 20px; gap: 18px; }
|
|
2443
|
+
.dl-upload-card .dl-pick { padding: 18px 20px; }
|
|
2444
|
+
.dl-upload-card .dl-drop { margin: 0 20px 20px; padding: 22px 16px; }
|
|
2445
|
+
.dl-group { padding: 20px; gap: 14px; }
|
|
2446
|
+
.dl-group h3 { font-size: 14px; }
|
|
2447
|
+
.dl-radio,.dl-check { grid-template-columns: 20px minmax(0,1fr); gap: 10px; }
|
|
2448
|
+
.dl-radio input,.dl-check input { width: 18px; height: 18px; margin-top: 1px; }
|
|
2449
|
+
.dl-radio strong,.dl-check strong { font-size: 13px; }
|
|
2450
|
+
.dl-radio small,.dl-check small,.dl-note { font-size: 12px; line-height: 1.5; }
|
|
2451
|
+
.dl-unavailable { color: var(--ak-ink-quiet); font-size: 12px; }
|
|
2452
|
+
.dl-unavailable summary { padding: 14px 4px; cursor: pointer; }
|
|
2453
|
+
.dl-unavailable > div { display: grid; gap: 12px; }
|
|
2454
|
+
.dl-unavailable summary:focus-visible,.dl-pick-tile:focus-visible { outline: 2px solid var(--ak-accent); outline-offset: 3px; }
|
|
2455
|
+
.dd-cost-info { line-height: 1; box-sizing: border-box; aspect-ratio: 1; min-width: 28px; max-width: 28px; }
|
package/dist/app/delivery.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DeliveryPricing } from "./lib/delivery-pricing.js";
|
|
1
2
|
import "../theme.css";
|
|
2
3
|
import "./app.css";
|
|
3
4
|
import "./next.css";
|
|
@@ -6,6 +7,7 @@ export interface DeliveryAdminOptions {
|
|
|
6
7
|
storagePrefix: string;
|
|
7
8
|
root?: HTMLElement | null;
|
|
8
9
|
websiteUrl?: string;
|
|
10
|
+
pricing?: DeliveryPricing;
|
|
9
11
|
}
|
|
10
12
|
/** Delivery-only entry: no editorial, GitHub, booking or R2 hooks are mounted. */
|
|
11
13
|
export declare function mountDeliveryAdmin(options: DeliveryAdminOptions): void;
|
package/dist/app/delivery.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { setSiteConfig } from "./site.js";
|
|
3
|
+
import { Icon } from "./ui/icons.js";
|
|
4
|
+
import { useAdminInterface } from "./lib/admin-interface.js";
|
|
5
|
+
import { DeliveryDashboard } from "./routes/DeliveryDashboard.js";
|
|
2
6
|
import { StrictMode, useEffect, useState } from "react";
|
|
3
7
|
import { createRoot } from "react-dom/client";
|
|
4
8
|
import { setStoragePrefix } from "../index.js";
|
|
@@ -14,6 +18,7 @@ import "./next.css";
|
|
|
14
18
|
/** Delivery-only entry: no editorial, GitHub, booking or R2 hooks are mounted. */
|
|
15
19
|
export function mountDeliveryAdmin(options) {
|
|
16
20
|
setStoragePrefix(options.storagePrefix);
|
|
21
|
+
setSiteConfig({ name: options.name, publicBase: options.websiteUrl || "", pagesProject: "", support: { name: "", email: "" }, pages: {}, home: {}, positionWeight: (_, index) => index, modules: { delivery: true }, deliveryPricing: options.pricing });
|
|
17
22
|
applyTheme(initialTheme());
|
|
18
23
|
const root = options.root ?? document.getElementById("root");
|
|
19
24
|
if (!root)
|
|
@@ -21,8 +26,9 @@ export function mountDeliveryAdmin(options) {
|
|
|
21
26
|
createRoot(root).render(_jsx(StrictMode, { children: _jsx(DeliveryAdmin, { ...options }) }));
|
|
22
27
|
}
|
|
23
28
|
function DeliveryAdmin({ name, websiteUrl }) {
|
|
29
|
+
const { adminInterface } = useAdminInterface();
|
|
24
30
|
const [route, go] = useHashRoute();
|
|
25
|
-
const id = route[0] === "deliveries" ? route[1] : undefined;
|
|
31
|
+
const id = route[0] === "deliveries" && route[1] !== "new" ? route[1] : undefined;
|
|
26
32
|
const api = useDeliveries(id);
|
|
27
33
|
const { theme, toggle } = useTheme();
|
|
28
34
|
const completions = useUploadCompletions();
|
|
@@ -39,8 +45,9 @@ function DeliveryAdmin({ name, websiteUrl }) {
|
|
|
39
45
|
const open = (value) => { setSelectedId(undefined); go(`/deliveries/${value}`); };
|
|
40
46
|
// Never render the previous transfer while the requested detail is loading.
|
|
41
47
|
const detail = id && api.detail?.id === id ? api.detail : null;
|
|
42
|
-
return _jsxs("div", { className: "app", children: [_jsxs("nav", { className: "rail", "aria-label": "Navigazione", children: [_jsxs("div", { className: "rail-brand", children: [_jsx("span", { className: "rail-brand-name", children: name }), _jsx("span", { className: "rail-brand-role", children: "Consegne" })] }), _jsx("button", { className: "rail-item is-on", onClick: () => go("/deliveries"), children: "Transfer" }), _jsxs("div", { className: "rail-foot", children: [websiteUrl && _jsx("a", { className: "rail-item", href: websiteUrl, target: "_blank", rel: "noreferrer", children: "Sito dello studio" }), _jsx("button", { className: "rail-item", onClick: toggle, children: theme === "dark" ? "Tema chiaro" : "Tema scuro" })] })] }), _jsxs("aside", { className: "col", "aria-label": "Elenco transfer", children: [_jsxs("div", { className: "col-head col-head-actions", children: [_jsx("span", { className: "col-title", children: "Transfer" }), _jsx(NewDeliveryButton, { onCreate: () => { setSelectedId(undefined); setDraftKey(v => v + 1); go("/deliveries"); } })] }), _jsx("div", { className: "col-body", children: !api.rows ? _jsx("p", { className: "ak-hint", children: "Carico\u2026" }) : api.rows.length === 0 ? _jsx("p", { className: "ak-hint", children: "Nessun transfer, per ora." })
|
|
48
|
+
return _jsxs("div", { className: "app", "data-admin-interface": adminInterface, children: [_jsxs("nav", { className: "rail", "aria-label": "Navigazione", children: [_jsxs("div", { className: "rail-brand", children: [_jsx("span", { className: "rail-brand-name", children: name }), _jsx("span", { className: "rail-brand-role", children: "Consegne" })] }), _jsx("button", { className: "rail-item is-on", onClick: () => go("/deliveries"), children: "Transfer" }), _jsxs("div", { className: "rail-foot", children: [websiteUrl && _jsx("a", { className: "rail-item", href: websiteUrl, target: "_blank", rel: "noreferrer", children: "Sito dello studio" }), _jsx("button", { className: "rail-item", onClick: toggle, children: theme === "dark" ? "Tema chiaro" : "Tema scuro" })] })] }), _jsxs("aside", { className: "col", "aria-label": "Elenco transfer", children: [_jsxs("div", { className: "col-head col-head-actions dl-col-head", children: [_jsx("span", { className: "col-title", children: "Transfer" }), _jsxs("button", { type: "button", className: "ak-btn dl-dashboard-button" + (!id && route[1] !== "new" ? " is-on" : ""), "aria-current": !id && route[1] !== "new" ? "page" : undefined, onClick: () => { setSelectedId(undefined); go("/deliveries"); }, children: [_jsx(Icon.grid, {}), _jsx("span", { children: "Dashboard" })] }), _jsx(NewDeliveryButton, { onCreate: () => { setSelectedId(undefined); setDraftKey(v => v + 1); go("/deliveries/new"); } })] }), _jsx("div", { className: "col-body", children: !api.rows ? _jsx("p", { className: "ak-hint", children: "Carico\u2026" }) : api.rows.length === 0 ? _jsx("p", { className: "ak-hint", children: "Nessun transfer, per ora." })
|
|
43
49
|
: _jsx(DeliveriesList, { rows: api.rows, current: id || selectedId, onOpen: open }) }), _jsx("div", { className: "dl-col-foot", children: api.rows && _jsx(DeliveriesTotal, { rows: api.rows }) })] }), _jsx("main", { className: "pane", children: _jsx("div", { className: "pane-body", children: api.error ? _jsxs("div", { role: "alert", children: [_jsx("p", { className: "ak-error", children: api.error }), _jsx("button", { className: "ak-btn", onClick: () => void api.refresh(), children: "Riprova" })] })
|
|
44
50
|
: id && !detail ? _jsx("p", { className: "ak-hint", children: "Carico\u2026" })
|
|
45
|
-
:
|
|
51
|
+
: !id && route[1] !== "new" ? _jsx(DeliveryDashboard, { onCreate: () => { setSelectedId(undefined); setDraftKey(v => v + 1); go("/deliveries/new"); }, onOpen: open })
|
|
52
|
+
: _jsx(DeliveryWorkspace, { delivery: detail, busy: api.busy, onAction: api.action, onRefresh: api.refresh, onReload: api.load, onRead: api.read, onDeleted: () => go("/deliveries"), onOpen: open, onSelected: setSelectedId }, id || `new-${draftKey}`) }) }), _jsx(UploadDock, {})] });
|
|
46
53
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** A transparent projection, never a reconstructed provider invoice. */
|
|
2
|
+
export interface DeliveryPricing {
|
|
3
|
+
storageUsdPerTb30Days: number;
|
|
4
|
+
freeStorageGb: number;
|
|
5
|
+
downloadUsdPerGb: number;
|
|
6
|
+
freeDownloadMultiplier: number;
|
|
7
|
+
verifiedAt: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function projectStorageCost(totalBytes: number | null | undefined, now: Date, pricing: DeliveryPricing): {
|
|
10
|
+
days: number;
|
|
11
|
+
usd: number;
|
|
12
|
+
} | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function projectStorageCost(totalBytes, now, pricing) {
|
|
2
|
+
if (totalBytes == null || !Number.isFinite(totalBytes) || totalBytes < 0 || !Number.isFinite(now.getTime()) || !Number.isFinite(pricing.storageUsdPerTb30Days) || pricing.storageUsdPerTb30Days < 0)
|
|
3
|
+
return null;
|
|
4
|
+
const parts = new Intl.DateTimeFormat('en', { timeZone: 'Europe/Rome', year: 'numeric', month: 'numeric' }).formatToParts(now);
|
|
5
|
+
const year = Number(parts.find(p => p.type === 'year').value);
|
|
6
|
+
const month = Number(parts.find(p => p.type === 'month').value);
|
|
7
|
+
const days = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
8
|
+
return { days, usd: totalBytes / 1e12 * pricing.storageUsdPerTb30Days * days / 30 };
|
|
9
|
+
}
|
package/dist/app/next.css
CHANGED
|
@@ -825,3 +825,14 @@
|
|
|
825
825
|
:root[data-admin-interface="next"] .pane-body,
|
|
826
826
|
:root[data-admin-interface="next"] .pane-body.is-wide { border-radius: 22px; padding: 24px 20px 56px; }
|
|
827
827
|
}
|
|
828
|
+
|
|
829
|
+
:root[data-admin-interface="next"] .col-head .dl-dashboard-button { justify-content: flex-start; gap: 10px; color: var(--ak-ink); background: transparent; border: 1px solid var(--ak-line); }
|
|
830
|
+
:root[data-admin-interface="next"] .col-head .dl-dashboard-button:hover { background: var(--ak-hover); }
|
|
831
|
+
:root[data-admin-interface="next"] .col-head .dl-dashboard-button.is-on { color: var(--ak-accent); border-color: var(--ak-accent); background: var(--ak-panel); }
|
|
832
|
+
.dl-dashboard-button:focus-visible,.dd-cost-info:focus-visible { outline: 2px solid var(--ak-accent); outline-offset: 3px; }
|
|
833
|
+
|
|
834
|
+
:root[data-admin-interface="next"] .dd-cost .dd-cost-info { display: inline-grid; place-items: center; width: 28px; height: 28px; min-height: 28px; padding: 0; border: 1px solid var(--ak-line); border-radius: 50%; font: 600 13px Georgia, serif; }
|
|
835
|
+
:root[data-admin-interface="next"] .dl-group { padding: 20px; }
|
|
836
|
+
:root[data-admin-interface="next"] .dl-about { padding: 22px; }
|
|
837
|
+
:root[data-admin-interface="next"] .dl-get { padding: 8px 0 20px; }
|
|
838
|
+
:root[data-admin-interface="next"] .dd-cost .dd-cost-info { min-width: 28px; max-width: 28px; line-height: 1; aspect-ratio: 1; }
|
|
@@ -258,7 +258,7 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
258
258
|
setNotice(null);
|
|
259
259
|
try {
|
|
260
260
|
const updated = (await onAction({
|
|
261
|
-
action: "update", id: delivery.id, title: draft.title.trim() || delivery.title,
|
|
261
|
+
action: "update", id: delivery.id, version: delivery.version, title: draft.title.trim() || delivery.title,
|
|
262
262
|
clientName: draft.clientName, description: draft.description,
|
|
263
263
|
licenseNotes: draft.licenseNotes, ctaEnabled: draft.ctaEnabled,
|
|
264
264
|
ctaLabel: draft.ctaLabel, ctaUrl: draft.ctaUrl, syncPackageLabel: true,
|
|
@@ -268,7 +268,7 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
268
268
|
? delivery.filesExpiresAt : expiryFrom(draft.duration),
|
|
269
269
|
}, { reload: false })).delivery;
|
|
270
270
|
if (!sameHeroes(heroes, heroesClean)) {
|
|
271
|
-
await onAction({ action: "commitHeroes", id: delivery.id, heroes }, { reload: false });
|
|
271
|
+
await onAction({ action: "commitHeroes", id: delivery.id, version: updated.version, heroes }, { reload: false });
|
|
272
272
|
}
|
|
273
273
|
if (link) {
|
|
274
274
|
if ((link.pin || "") !== draft.pin) {
|
|
@@ -385,7 +385,9 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
385
385
|
const state = delivery ? transferState(delivery) : null;
|
|
386
386
|
const expiry = draft.duration === "keep"
|
|
387
387
|
? delivery?.filesExpiresAt || null : expiryFrom(draft.duration);
|
|
388
|
-
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: "Guarda come lo vede il cliente" })), link && (_jsx("button", { className: "ak-btn ak-btn-primary", disabled: !dirty || saving || busy, onClick: () => void save(), children: saving ? "Salvo…" : "Salva" }))] })] }), (failure || notice) && (_jsxs("p", { 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", children: [_jsxs("div", { className: "dl-main", children: [_jsxs(
|
|
388
|
+
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: "Guarda come lo vede il cliente" })), link && (_jsx("button", { className: "ak-btn ak-btn-primary", disabled: !dirty || saving || busy, onClick: () => void save(), children: saving ? "Salvo…" : "Salva" }))] })] }), (failure || notice) && (_jsxs("p", { 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", children: [_jsxs("div", { className: "dl-main", children: [_jsxs(Group, { title: "Opzioni di consegna", note: packages.length
|
|
389
|
+
? "Le opzioni dei file caricati sono bloccate. Per cambiarle, rimuovi e ricarica i file."
|
|
390
|
+
: "Scegli prima di aggiungere i file. Gli originali sono sempre inclusi.", 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 }) }), _jsxs("span", { children: [_jsx("strong", { children: "Aggiungi conversione in bassa risoluzione" }), _jsx("small", { children: "Aggiunge un download 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%", "."] })] }))] }), _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 transfer. Il caricamento inizia appena scegli i file." })] }), _jsxs("div", { className: "dl-pick", children: [_jsxs("button", { className: "dl-pick-tile", disabled: uploading, onClick: () => choose(filesRef.current), children: [_jsx(FileIcon, {}), "Aggiungi file"] }), _jsxs("button", { className: "dl-pick-tile", disabled: uploading, onClick: () => choose(folderRef.current), children: [_jsx(FolderIcon, {}), "Aggiungi una cartella"] }), _jsx("input", { ref: folderRef, type: "file", multiple: true, hidden: true, onChange: picked }), _jsx("input", { ref: filesRef, type: "file", multiple: true, hidden: true, onChange: picked })] }), _jsx(DropArea, { disabled: uploading, resuming: !!resumeRef.current, onFiles: (files) => {
|
|
389
391
|
const resume = resumeRef.current;
|
|
390
392
|
resumeRef.current = null;
|
|
391
393
|
void beginUpload(files, resume);
|
|
@@ -397,7 +399,7 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
397
399
|
.filter(Boolean).join(" · ") || "solo originali"
|
|
398
400
|
: job?.id === pkg.id && isBusy(job)
|
|
399
401
|
? (job.state === "paused" ? "caricamento in pausa" : "caricamento in corso")
|
|
400
|
-
: "caricamento interrotto" })] }), _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; 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("section", { className: "dl-card dl-about", children: [_jsx(Field, { label: "Nome del transfer", hint: "
|
|
402
|
+
: "caricamento interrotto" })] }), _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; 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("section", { className: "dl-card dl-about", children: [_jsxs("div", { className: "dl-section-head", children: [_jsx("h3", { children: "Dettagli del transfer" }), _jsx("p", { children: "Queste informazioni saranno visibili al destinatario." })] }), _jsx(Field, { label: "Nome del transfer", hint: "Usato anche per il nome del file ZIP.", children: _jsx("input", { value: draft.title, placeholder: "Es. Team building \u2014 Milano", onChange: (e) => change({ title: e.target.value }) }) }), _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 }) }) }), _jsx(Field, { label: "Messaggio", wide: true, hint: "Un messaggio di accompagnamento. Facoltativo.", children: _jsx("textarea", { rows: 3, value: draft.description, onChange: (e) => change({ description: e.target.value }) }) })] }), link ? (_jsxs("section", { className: "dl-card dl-link", 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: [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 () => {
|
|
401
403
|
setSaving(true);
|
|
402
404
|
try {
|
|
403
405
|
await run({ action: "shortenLink", id: delivery.id, linkId: link.id }, "Link accorciato. Anche il vecchio indirizzo resta valido.");
|
|
@@ -407,13 +409,11 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
407
409
|
}
|
|
408
410
|
}, children: "Accorcia link" })), _jsx("button", { className: "ak-btn ak-btn-primary", onClick: () => void copy(link.url, "link"), children: copied === "link" ? "Copiato" : "Copia il link" }), _jsx("button", { className: "ak-btn", onClick: () => void copy(messageFor(draft, link, expiry), "messaggio"), children: copied === "messaggio" ? "Copiato" : "Copia il messaggio" }), _jsx("a", { className: "ak-btn", target: "_blank", rel: "noreferrer", href: `https://wa.me/?text=${encodeURIComponent(messageFor(draft, link, expiry))}`, children: "Apri in WhatsApp" })] }), _jsx("p", { className: "dl-link-stats", children: linkStory(link) }), draft.pin && (_jsxs("p", { className: "dl-link-stats", children: ["Codice di accesso ", _jsx("strong", { children: draft.pin }), " \u2014 \u00E8 gi\u00E0 dentro il messaggio."] }))] })) : (_jsxs("section", { className: "dl-card dl-get", children: [_jsx("button", { className: "ak-btn ak-btn-primary dl-get-btn", disabled: !delivery || saving || busy, onClick: () => void save(), children: saving ? "Preparo…" : "Ottieni il link" }), _jsx("p", { children: delivery
|
|
409
411
|
? "Il link vale già mentre l'upload continua: chi lo apre vede che i file stanno arrivando."
|
|
410
|
-
: "Aggiungi i file: il caricamento parte subito e il resto si compila mentre va." })] }))] }), _jsxs("div", { className: "dl-side", children: [_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: "
|
|
411
|
-
? "Si decide prima di caricare: per cambiarle bisognerebbe ricaricare i file."
|
|
412
|
-
: undefined, 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: "Vede le foto sulla pagina" }), _jsx("small", { children: "Anteprime e ingrandimento, senza scaricare niente. Da telefono \u00E8 la differenza fra un link e un Transfer." })] })] }), _jsxs("label", { className: "dl-check", children: [_jsx("input", { type: "checkbox", checked: draft.light, disabled: !!packages.length, onChange: (e) => change({ light: e.target.checked }) }), _jsxs("span", { children: [_jsx("strong", { children: "Pu\u00F2 scaricare una versione leggera" }), _jsx("small", { children: "Un secondo download, adatto a social e web. Gli originali ci sono sempre." })] })] }), draft.light && (_jsxs("label", { className: "dl-field", children: [_jsx("span", { children: "Formato della versione leggera" }), _jsxs("select", { className: "dl-select", "aria-label": "Formato della versione leggera", 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%", "."] })] }))] }), 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: "Per quanto resta scaricabile", children: [_jsxs("select", { className: "dl-select", value: draft.duration, onChange: (e) => change({ duration: e.target.value }), children: [delivery && _jsx("option", { value: "keep", children: delivery.filesExpiresAt
|
|
412
|
+
: "Aggiungi i file: il caricamento parte subito e il resto si compila mentre va." })] }))] }), _jsxs("div", { className: "dl-side", children: [_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
|
|
413
413
|
? `Fino al ${formatDate(delivery.filesExpiresAt)}`
|
|
414
|
-
: "Per sempre" }), _jsx("option", { value: "7", children: "7 giorni" }), _jsx("option", { value: "30", children: "30 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
|
|
414
|
+
: "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
|
|
415
415
|
? `Dopo il ${formatDate(expiry)} il link continua ad aprirsi, ma i file non si scaricano più.`
|
|
416
|
-
: "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 }) }) })] })] })] }), !!delivery && (_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: ["Le foto grandi in cima alla pagina del cliente, fino a otto.", " ", heroes.length
|
|
416
|
+
: "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." })] })] })] })] })] }), !!delivery && (_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: ["Le foto grandi in cima alla pagina del cliente, fino a otto.", " ", heroes.length
|
|
417
417
|
? `Ne hai scelte ${heroes.length}.`
|
|
418
418
|
: "Nessuna scelta: si userà quella predefinita."] }), _jsx("p", { role: "status", children: heroesDirty
|
|
419
419
|
? "Scelta non ancora salvata: premi Salva modifiche per mostrarla al cliente."
|
|
@@ -425,7 +425,7 @@ export function DeliveryWorkspace({ delivery: fromServer, busy, onAction, onRefr
|
|
|
425
425
|
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}`));
|
|
426
426
|
}) })) : (_jsx("p", { className: "dl-note dl-cover-empty", children: heroes.some((item) => item.type === "object")
|
|
427
427
|
? `${heroes.length} immagini caricate a mano.`
|
|
428
|
-
: "Questo transfer non ha anteprime da cui scegliere: carica un'immagine, oppure resta quella predefinita." }))] })), !!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
|
|
428
|
+
: "Questo transfer non ha anteprime da cui scegliere: carica un'immagine, oppure resta quella predefinita." }))] })), !!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" }))] }))] }));
|
|
429
429
|
}
|
|
430
430
|
/* ============================================================================================
|
|
431
431
|
Impostazioni
|
|
@@ -515,7 +515,7 @@ function draftOf(delivery, keep) {
|
|
|
515
515
|
return {
|
|
516
516
|
title: "", clientName: "", description: "", licenseNotes: "",
|
|
517
517
|
ctaEnabled: false, ctaLabel: "Lascia una recensione", ctaUrl: "",
|
|
518
|
-
duration: "
|
|
518
|
+
duration: "60", pin: "", gallery: false, light: false, webFormat: "jpg",
|
|
519
519
|
downloadOriginalsLabel: "", downloadWebLabel: "",
|
|
520
520
|
};
|
|
521
521
|
}
|
|
@@ -534,9 +534,9 @@ function draftOf(delivery, keep) {
|
|
|
534
534
|
pin: link?.pin || "",
|
|
535
535
|
/* Gallery e versione leggera non sono campi del transfer ma del caricamento: per un
|
|
536
536
|
transfer che ha già i file, la verità è quella dei file. */
|
|
537
|
-
gallery: delivery.packages[0]?.galleryEnabled ?? keep?.gallery ??
|
|
538
|
-
light: delivery.packages[0]?.webEnabled ?? keep?.light ??
|
|
539
|
-
webFormat: delivery.packages.length ? (delivery.packages[0].webFormat || "webp") : keep?.webFormat || "
|
|
537
|
+
gallery: delivery.packages[0]?.galleryEnabled ?? keep?.gallery ?? false,
|
|
538
|
+
light: delivery.packages[0]?.webEnabled ?? keep?.light ?? false,
|
|
539
|
+
webFormat: delivery.packages.length ? (delivery.packages[0].webFormat || "webp") : keep?.webFormat || "jpg",
|
|
540
540
|
};
|
|
541
541
|
}
|
|
542
542
|
function same(a, b) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
3
|
+
import { projectStorageCost } from '../lib/delivery-pricing.js';
|
|
4
|
+
const usd = (value) => new Intl.NumberFormat('it-IT', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value) + ' USD';
|
|
5
|
+
export function DeliveryCostEstimate({ totalBytes, pricing }) {
|
|
6
|
+
const [open, setOpen] = useState(false);
|
|
7
|
+
const modal = useRef(null);
|
|
8
|
+
const id = useId();
|
|
9
|
+
const now = new Date();
|
|
10
|
+
const projection = projectStorageCost(totalBytes, now, pricing);
|
|
11
|
+
const month = new Intl.DateTimeFormat('it-IT', { month: 'long', year: 'numeric', timeZone: 'Europe/Rome' }).format(now);
|
|
12
|
+
useEffect(() => { if (open)
|
|
13
|
+
modal.current?.showModal(); }, [open]);
|
|
14
|
+
const close = () => { modal.current?.close(); setOpen(false); };
|
|
15
|
+
return _jsxs("section", { className: "dd-cost", "aria-label": "Stima del costo mensile", children: [_jsxs("div", { children: [_jsxs("div", { className: "dd-title-row", children: [_jsxs("h3", { children: ["Costo stimato \u00B7 ", month] }), _jsx("button", { type: "button", className: "ak-btn dd-cost-info", "aria-label": "Come vengono calcolati i costi", "aria-haspopup": "dialog", onClick: () => setOpen(true), children: _jsx("span", { "aria-hidden": "true", children: "i" }) })] }), _jsx("p", { children: "Proiezione del solo spazio, se l\u2019occupazione attuale resta stabile per tutto il mese." }), _jsx("p", { className: "dd-cost-caveat", children: "Stima orientativa: il costo dipende dal consumo effettivo. Download extra, imposte e quota gratuita non sono conteggiati." })] }), _jsxs("div", { className: "dd-cost-amount", children: [_jsx("strong", { children: projection ? projection.usd > 0 && projection.usd < .01 ? "< 0,01 USD" : `≈ ${usd(projection.usd)}` : '—' }), _jsx("span", { children: projection ? `${projection.days} giorni · prima della quota gratuita` : 'Disponibile dopo la verifica dello spazio' })] }), open && _jsx("dialog", { className: "dd-cost-dialog", ref: modal, "aria-labelledby": id, onCancel: close, onClose: () => setOpen(false), onClick: event => { if (event.target === event.currentTarget)
|
|
16
|
+
close(); }, children: _jsxs("div", { className: "dd-cost-dialog-inner", children: [_jsxs("header", { children: [_jsxs("div", { children: [_jsx("p", { className: "dd-eyebrow", children: "Spazio e download" }), _jsx("h2", { id: id, children: "Come si calcolano i costi" })] }), _jsx("button", { className: "ak-btn", type: "button", onClick: close, autoFocus: true, "aria-label": "Chiudi dettagli sui costi", children: "Chiudi" })] }), _jsxs("dl", { children: [_jsxs("div", { children: [_jsx("dt", { children: "Lo spazio sul server" }), _jsxs("dd", { children: [usd(pricing.storageUsdPerTb30Days), " per TB ogni 30 giorni, in proporzione ai byte e alle ore di conservazione. Nessuna dimensione o durata minima. Anteprime, copie precedenti e caricamenti incompleti occupano spazio."] })] }), _jsxs("div", { children: [_jsx("dt", { children: "La quota gratuita" }), _jsxs("dd", { children: ["I primi ", pricing.freeStorageGb, " GB sono gratuiti e condivisi con gli altri spazi dello stesso account. Non conoscendo la quota residua, la proiezione non la sottrae: il costo reale pu\u00F2 essere inferiore."] })] }), _jsxs("div", { children: [_jsx("dt", { children: "I download" }), _jsxs("dd", { children: ["Sono inclusi fino a ", pricing.freeDownloadMultiplier, " volte lo spazio medio conservato nel mese. Oltre questa soglia, ", usd(pricing.downloadUsdPerGb), " per GB scaricato. Ogni nuovo download conta; conservare i file per pochi giorni riduce lo spazio medio e la quota inclusa. I percorsi di distribuzione convenzionati possono non avere costi di download."] })] }), _jsxs("div", { children: [_jsx("dt", { children: "Cosa comprende questa stima" }), _jsxs("dd", { children: ["Lo spazio rilevato all\u2019ultima verifica, mantenuto per tutti i giorni di ", month, ". Non ricostruisce lo spazio gi\u00E0 usato e poi liberato. Le richieste di download non misurano i byte realmente ricevuti: gli eventuali download extra sono esclusi."] })] }), _jsxs("div", { children: [_jsx("dt", { children: "Altri costi" }), _jsx("dd", { children: "Upload e operazioni ordinarie sono inclusi. Eventuali notifiche automatiche speciali hanno un costo separato: 0,004 USD ogni 10.000 operazioni, con le prime 2.500 al giorno gratuite. Questo pannello non le utilizza. Imposte e conversione valutaria sono escluse." })] })] }), _jsxs("p", { className: "dd-footnote", children: ["1 TB = 1.000 GB. Tariffe verificate il ", new Intl.DateTimeFormat('it-IT', { dateStyle: 'long', timeZone: 'Europe/Rome' }).format(new Date(pricing.verifiedAt + 'T12:00:00Z')), ". La cifra \u00E8 orientativa e dipende dal consumo effettivo; fa fede il conteggio finale del servizio."] })] }) })] });
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { site } from "../site.js";
|
|
3
|
+
import { DeliveryCostEstimate } from "./DeliveryCostEstimate.js";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
const bytes = (value) => {
|
|
6
|
+
if (value == null)
|
|
7
|
+
return "—";
|
|
8
|
+
if (!value)
|
|
9
|
+
return "0 B";
|
|
10
|
+
const power = Math.min(4, Math.floor(Math.log(value) / Math.log(1000)));
|
|
11
|
+
return `${new Intl.NumberFormat("it-IT", { maximumFractionDigits: power ? 2 : 0 }).format(value / 1000 ** power)} ${["B", "KB", "MB", "GB", "TB"][power]}`;
|
|
12
|
+
};
|
|
13
|
+
const date = (value) => new Intl.DateTimeFormat("it-IT", { dateStyle: "short", timeStyle: "short" }).format(new Date(value));
|
|
14
|
+
export function DeliveryDashboard({ onCreate, onOpen }) {
|
|
15
|
+
const [data, setData] = useState(null);
|
|
16
|
+
const [error, setError] = useState(null);
|
|
17
|
+
const [checking, setChecking] = useState(false);
|
|
18
|
+
const mounted = useRef(false);
|
|
19
|
+
const load = useCallback(async (verify = false) => {
|
|
20
|
+
if (verify)
|
|
21
|
+
setChecking(true);
|
|
22
|
+
try {
|
|
23
|
+
const response = await fetch(verify ? "/admin/api/deliveries" : "/admin/api/deliveries?dashboard=1", {
|
|
24
|
+
credentials: "same-origin", ...(verify ? { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "verifyStorage" }) } : {}),
|
|
25
|
+
});
|
|
26
|
+
const body = await response.json();
|
|
27
|
+
if (!response.ok || !body.ok)
|
|
28
|
+
throw new Error(body.error || "La dashboard non è disponibile. Riprova.");
|
|
29
|
+
if (mounted.current) {
|
|
30
|
+
setData(body.dashboard);
|
|
31
|
+
setError(null);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (mounted.current)
|
|
36
|
+
setError(err instanceof Error ? err.message : "Verifica non disponibile");
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (mounted.current && verify)
|
|
40
|
+
setChecking(false);
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
useEffect(() => { mounted.current = true; void load(); return () => { mounted.current = false; }; }, [load]);
|
|
44
|
+
const running = checking || data?.storage.status === "running";
|
|
45
|
+
useEffect(() => { const timer = setTimeout(() => void load(), running || (data?.storage.enabled && !data.storage.checkedAt) ? 3000 : 60_000); return () => clearTimeout(timer); }, [data, running, load]);
|
|
46
|
+
const storage = data?.storage, snapshot = storage?.snapshot;
|
|
47
|
+
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." })] }), _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 ? "Rilevato sul server · " + date(storage.checkedAt) : "In attesa della prima verifica dello spazio" }), _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 }), _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.` : "L’inventario legge i file e i caricamenti presenti sul server, senza scaricare i file." })] }), _jsx("button", { className: "ak-btn", disabled: running || !storage?.enabled, onClick: () => void load(true), children: running ? "Verifica in corso…" : "Verifica ora" })] }), !storage?.enabled && data && _jsx("p", { className: "dd-notice", children: "La verifica dello spazio sar\u00E0 disponibile dopo l\u2019abilitazione di questa funzione sul server." }), storage?.error && _jsxs("p", { className: "dd-notice", role: "status", children: ["Non \u00E8 stato possibile verificare lo spazio. ", snapshot ? "Rimane visibile l’ultimo inventario completo." : "Nessun inventario completo disponibile."] }), _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` : "Parti già caricate sul server" }), _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. La verifica non elimina alcun file." })] }), _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." }) :
|
|
48
|
+
_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)) })] }) })] })] });
|
|
49
|
+
}
|
|
50
|
+
function Metric({ label, value, note }) {
|
|
51
|
+
return _jsxs("div", { className: "dd-metric", children: [_jsx("span", { children: label }), _jsx("strong", { children: value ?? "—" }), _jsx("p", { children: note })] });
|
|
52
|
+
}
|