@antelopejs/dms-media 0.6.2 → 0.7.1
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 +17 -23
- package/dist/acl/entries.js +2 -1
- package/dist/acl/entries.js.map +1 -1
- package/dist/asset-lifecycle.js.map +1 -1
- package/dist/db/models/mediaAssets.model.d.ts +7 -5
- package/dist/db/models/mediaDeclarations.model.d.ts +7 -5
- package/dist/db/models/mediaEvents.model.d.ts +7 -5
- package/dist/db/models/mediaFavorites.model.d.ts +7 -5
- package/dist/db/models/mediaFolders.model.d.ts +7 -5
- package/dist/db/models/mediaUploads.model.d.ts +7 -5
- package/dist/declared/assets.js +2 -5
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/records.d.ts +2 -1
- package/dist/declared/records.js.map +1 -1
- package/dist/library/activity.js +2 -1
- package/dist/library/activity.js.map +1 -1
- package/dist/routes/media/manage.js +2 -2
- package/dist/routes/media/manage.js.map +1 -1
- package/dist/routes/media/storage-keys.js.map +1 -1
- package/dist/test/antelope.test.js +7 -5
- package/dist/test/antelope.test.js.map +1 -1
- package/dist/test/helpers/assets.d.ts +24 -5
- package/dist/test/helpers/assets.js +22 -7
- package/dist/test/helpers/assets.js.map +1 -1
- package/dist/test/helpers/bodies.d.ts +31 -0
- package/dist/test/helpers/bodies.js +16 -0
- package/dist/test/helpers/bodies.js.map +1 -0
- package/dist/test/helpers/folders.d.ts +50 -0
- package/dist/test/helpers/folders.js +4 -2
- package/dist/test/helpers/folders.js.map +1 -1
- package/dist/test/helpers/members.js +10 -3
- package/dist/test/helpers/members.js.map +1 -1
- package/dist/test/helpers/owner.js +6 -1
- package/dist/test/helpers/owner.js.map +1 -1
- package/dist/test/helpers/permissions-world.d.ts +132 -11
- package/dist/test/helpers/permissions-world.js +21 -2
- package/dist/test/helpers/permissions-world.js.map +1 -1
- package/dist/test/helpers/setup-token.d.ts +1 -0
- package/dist/test/helpers/setup-token.js +5 -0
- package/dist/test/helpers/setup-token.js.map +1 -0
- package/dist/test/integration/derivative-sweep-query.test.js +1 -2
- package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
- package/dist/test/integration/folder-cascade.test.js +3 -1
- package/dist/test/integration/folder-cascade.test.js.map +1 -1
- package/dist/test/integration/media-activity-overview.test.js +39 -12
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +22 -21
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +6 -5
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-declared-content.test.js +2 -1
- package/dist/test/integration/media-declared-content.test.js.map +1 -1
- package/dist/test/integration/media-delivery-editing.test.js +12 -2
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-delivery.test.js +5 -3
- package/dist/test/integration/media-delivery.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +6 -4
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +11 -16
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +73 -23
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +3 -2
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-member-access.test.js +18 -2
- package/dist/test/integration/media-member-access.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +7 -2
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-project-field.test.js +17 -2
- package/dist/test/integration/media-project-field.test.js.map +1 -1
- package/dist/test/integration/media-search-views.test.js +24 -10
- package/dist/test/integration/media-search-views.test.js.map +1 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js +2 -1
- package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
- package/dist/test/integration/media-transform.test.js +8 -9
- package/dist/test/integration/media-transform.test.js.map +1 -1
- package/dist/test/integration/media-upload-history-filters.test.d.ts +1 -0
- package/dist/test/integration/media-upload-history-filters.test.js +67 -0
- package/dist/test/integration/media-upload-history-filters.test.js.map +1 -0
- package/dist/test/integration/media-upload-policy.test.js +31 -14
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/integration/permissions-management.js +15 -4
- package/dist/test/integration/permissions-management.js.map +1 -1
- package/dist/test/unit/declared.test.js +1 -1
- package/dist/test/unit/declared.test.js.map +1 -1
- package/dist/test/unit/library/zip-names.test.js +22 -4
- package/dist/test/unit/library/zip-names.test.js.map +1 -1
- package/dist/test/unit/upload-rules.test.js +10 -0
- package/dist/test/unit/upload-rules.test.js.map +1 -1
- package/dist/transform-ops.js.map +1 -1
- package/dist/upload-policy.js +11 -11
- package/dist/upload-policy.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +4 -4
- package/dist/validation/library.schema.d.ts +10 -10
- package/dist/validation/media.schema.d.ts +8 -9
- package/dist/validation/media.schema.js +4 -6
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/build/imageEditor/useEditorSaving.ts +3 -2
- package/frontend-vue/app/build/library/libraryCore.ts +2 -1
- package/frontend-vue/app/components/FirstRun.vue +2 -1
- package/frontend-vue/app/components/dialogs/DestinationDialog.vue +3 -3
- package/frontend-vue/app/components/field/FieldAltPopover.vue +2 -1
- package/frontend-vue/app/composables/useAssetFieldUploads.ts +9 -1
- package/frontend-vue/app/composables/useAssetLink.ts +33 -13
- package/frontend-vue/app/composables/useFileDetails.ts +6 -5
- package/frontend-vue/app/composables/useUploadFailureText.ts +24 -5
- package/frontend-vue/app/composables/useUploadQueue.ts +178 -44
- package/frontend-vue/app/composables/useUploadToasts.ts +81 -19
- package/frontend-vue/package.json +3 -3
- package/frontend-vue/tests/api-error-presentation.test.ts +183 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +1 -1
- package/package.json +12 -11
- package/skills/dms-media/SKILL.md +2 -2
- package/src/acl/entries.ts +5 -2
- package/src/asset-lifecycle.ts +2 -1
- package/src/declared/assets.ts +6 -6
- package/src/declared/records.ts +5 -1
- package/src/library/activity.ts +3 -1
- package/src/routes/media/manage.ts +2 -2
- package/src/routes/media/storage-keys.ts +1 -0
- package/src/test/antelope.test.ts +7 -5
- package/src/test/helpers/assets.ts +28 -15
- package/src/test/helpers/bodies.ts +22 -0
- package/src/test/helpers/folders.ts +6 -3
- package/src/test/helpers/members.ts +11 -3
- package/src/test/helpers/owner.ts +6 -1
- package/src/test/helpers/permissions-world.ts +23 -19
- package/src/test/helpers/setup-token.ts +6 -0
- package/src/test/integration/derivative-sweep-query.test.ts +4 -3
- package/src/test/integration/folder-cascade.test.ts +3 -1
- package/src/test/integration/media-activity-overview.test.ts +52 -37
- package/src/test/integration/media-api.test.ts +25 -27
- package/src/test/integration/media-bindings.test.ts +10 -16
- package/src/test/integration/media-declared-content.test.ts +2 -1
- package/src/test/integration/media-delivery-editing.test.ts +13 -2
- package/src/test/integration/media-delivery.test.ts +8 -3
- package/src/test/integration/media-explorer-writes.test.ts +6 -4
- package/src/test/integration/media-guards.test.ts +18 -13
- package/src/test/integration/media-library.test.ts +101 -47
- package/src/test/integration/media-linked-subfolders.test.ts +3 -2
- package/src/test/integration/media-member-access.test.ts +22 -24
- package/src/test/integration/media-permissions.test.ts +11 -5
- package/src/test/integration/media-project-field.test.ts +21 -9
- package/src/test/integration/media-search-views.test.ts +35 -31
- package/src/test/integration/media-storage-origin-unreachable.test.ts +2 -1
- package/src/test/integration/media-transform.test.ts +8 -9
- package/src/test/integration/media-upload-history-filters.test.ts +77 -0
- package/src/test/integration/media-upload-policy.test.ts +39 -20
- package/src/test/integration/permissions-management.ts +16 -4
- package/src/test/unit/declared.test.ts +4 -1
- package/src/test/unit/library/zip-names.test.ts +26 -7
- package/src/test/unit/upload-rules.test.ts +11 -0
- package/src/transform-ops.ts +1 -0
- package/src/upload-policy.ts +11 -11
- package/src/validation/media.schema.ts +8 -8
|
@@ -49,6 +49,7 @@ export interface UploadItem {
|
|
|
49
49
|
loaded: number
|
|
50
50
|
failure?: UploadFailure
|
|
51
51
|
message?: string
|
|
52
|
+
requestError?: unknown
|
|
52
53
|
details?: UploadRefusalDetails
|
|
53
54
|
resourceKey?: string
|
|
54
55
|
previewUrl?: string
|
|
@@ -97,7 +98,12 @@ interface ServerRefusal {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
const CONCURRENCY = 2
|
|
100
|
-
const FINAL_STATUSES = new Set<UploadStatus>([
|
|
101
|
+
const FINAL_STATUSES = new Set<UploadStatus>([
|
|
102
|
+
'done',
|
|
103
|
+
'failed',
|
|
104
|
+
'rejected',
|
|
105
|
+
'cancelled',
|
|
106
|
+
])
|
|
101
107
|
const CANCELLABLE_STATUSES = new Set<UploadStatus>(['waiting', 'uploading'])
|
|
102
108
|
const FAILED_STATUSES = new Set<UploadStatus>(['failed', 'rejected'])
|
|
103
109
|
const HTTP_SUCCESS_LIMIT = 300
|
|
@@ -105,12 +111,21 @@ const HTTP_CLIENT_ERROR_MIN = 400
|
|
|
105
111
|
const HTTP_SERVER_ERROR_MIN = 500
|
|
106
112
|
const HTTP_PAYLOAD_TOO_LARGE = 413
|
|
107
113
|
/** Failures the same file would meet again: no retry is offered. */
|
|
108
|
-
const FINAL_FAILURES = new Set<UploadFailure>([
|
|
114
|
+
const FINAL_FAILURES = new Set<UploadFailure>([
|
|
115
|
+
'storage_limit',
|
|
116
|
+
'storage_blocked',
|
|
117
|
+
'storage_unreachable',
|
|
118
|
+
])
|
|
109
119
|
const MAX_REPORTED_FAILURES = 50
|
|
110
120
|
const VISIBLE_DUPLICATE_NAMES = 6
|
|
111
121
|
const MAX_REASON_LENGTH = 500
|
|
112
122
|
/** Headers a browser sets itself and refuses from a script. */
|
|
113
|
-
const FORBIDDEN_REQUEST_HEADERS = new Set([
|
|
123
|
+
const FORBIDDEN_REQUEST_HEADERS = new Set([
|
|
124
|
+
'content-length',
|
|
125
|
+
'host',
|
|
126
|
+
'connection',
|
|
127
|
+
'accept-encoding',
|
|
128
|
+
])
|
|
114
129
|
const REFUSALS_BY_STATUS: Record<number, UploadFailure> = {
|
|
115
130
|
400: 'invalid',
|
|
116
131
|
403: 'no_access',
|
|
@@ -119,7 +134,12 @@ const REFUSALS_BY_STATUS: Record<number, UploadFailure> = {
|
|
|
119
134
|
415: 'type_not_allowed',
|
|
120
135
|
422: 'invalid_image',
|
|
121
136
|
}
|
|
122
|
-
const SERVER_REASONS = new Set<UploadFailure>([
|
|
137
|
+
const SERVER_REASONS = new Set<UploadFailure>([
|
|
138
|
+
'type_not_allowed',
|
|
139
|
+
'field_type',
|
|
140
|
+
'quota',
|
|
141
|
+
'invalid_image',
|
|
142
|
+
])
|
|
123
143
|
|
|
124
144
|
const items = ref<UploadItem[]>([])
|
|
125
145
|
const isPaused = ref(false)
|
|
@@ -159,7 +179,8 @@ function isCancelled(id: string): boolean {
|
|
|
159
179
|
}
|
|
160
180
|
|
|
161
181
|
function api(): UploadApi {
|
|
162
|
-
if (!uploadApi)
|
|
182
|
+
if (!uploadApi)
|
|
183
|
+
throw new Error('useUploadQueue() must run in a component setup first')
|
|
163
184
|
return uploadApi
|
|
164
185
|
}
|
|
165
186
|
|
|
@@ -178,27 +199,43 @@ class UploadError extends Error {
|
|
|
178
199
|
}
|
|
179
200
|
|
|
180
201
|
/** A network error tells a dropped link from a storage this site may not reach (CORS, wrong address). */
|
|
181
|
-
async function networkFailure(
|
|
202
|
+
async function networkFailure(
|
|
203
|
+
url: string,
|
|
204
|
+
hasSentBytes: boolean,
|
|
205
|
+
): Promise<UploadError> {
|
|
182
206
|
const { failure, address } = await diagnoseStorageFailure(url, hasSentBytes)
|
|
183
207
|
if (failure === 'connection') return new UploadError('connection')
|
|
184
208
|
return new UploadError(failure, address, { address })
|
|
185
209
|
}
|
|
186
210
|
|
|
187
|
-
function putFile(
|
|
211
|
+
function putFile(
|
|
212
|
+
id: string,
|
|
213
|
+
url: string,
|
|
214
|
+
headers: Record<string, string>,
|
|
215
|
+
file: File,
|
|
216
|
+
): Promise<void> {
|
|
188
217
|
return new Promise<void>((resolve, reject) => {
|
|
189
218
|
const request = new XMLHttpRequest()
|
|
190
219
|
let sentBytes = 0
|
|
191
220
|
requests.set(id, request)
|
|
192
221
|
request.open('PUT', url)
|
|
193
222
|
for (const [name, value] of Object.entries(headers)) {
|
|
194
|
-
if (!FORBIDDEN_REQUEST_HEADERS.has(name.toLowerCase()))
|
|
223
|
+
if (!FORBIDDEN_REQUEST_HEADERS.has(name.toLowerCase()))
|
|
224
|
+
request.setRequestHeader(name, value)
|
|
195
225
|
}
|
|
196
226
|
request.upload.onprogress = (event) => {
|
|
197
227
|
sentBytes = event.loaded
|
|
198
228
|
patch(id, { loaded: event.loaded })
|
|
199
229
|
}
|
|
200
230
|
request.onload = () =>
|
|
201
|
-
request.status < HTTP_SUCCESS_LIMIT
|
|
231
|
+
request.status < HTTP_SUCCESS_LIMIT
|
|
232
|
+
? resolve()
|
|
233
|
+
: reject(
|
|
234
|
+
new UploadError(
|
|
235
|
+
storageFailure(request.status),
|
|
236
|
+
String(request.status),
|
|
237
|
+
),
|
|
238
|
+
)
|
|
202
239
|
request.onerror = () => void networkFailure(url, sentBytes > 0).then(reject)
|
|
203
240
|
request.onabort = () => reject(new UploadError('connection', 'aborted'))
|
|
204
241
|
request.send(file)
|
|
@@ -228,14 +265,20 @@ function describeFailure(error: unknown): FailureOutcome {
|
|
|
228
265
|
const reason = refusal.reason as UploadFailure | undefined
|
|
229
266
|
return {
|
|
230
267
|
status: 'rejected',
|
|
231
|
-
failure:
|
|
268
|
+
failure:
|
|
269
|
+
reason && SERVER_REASONS.has(reason)
|
|
270
|
+
? reason
|
|
271
|
+
: (REFUSALS_BY_STATUS[status] ?? 'invalid'),
|
|
232
272
|
message: refusal.message,
|
|
233
273
|
details: { accepted: refusal.accepted, remaining: refusal.remaining },
|
|
234
274
|
}
|
|
235
275
|
}
|
|
236
276
|
|
|
237
277
|
function discardStaged(item: UploadItem): void {
|
|
238
|
-
if (item.resourceKey)
|
|
278
|
+
if (item.resourceKey)
|
|
279
|
+
void api()
|
|
280
|
+
.abort(item.folderId, item.resourceKey)
|
|
281
|
+
.catch(() => undefined)
|
|
239
282
|
}
|
|
240
283
|
|
|
241
284
|
async function run(item: UploadItem): Promise<void> {
|
|
@@ -263,14 +306,22 @@ async function run(item: UploadItem): Promise<void> {
|
|
|
263
306
|
const current = findItem(item.id)
|
|
264
307
|
if (!current || current.status === 'cancelled') return
|
|
265
308
|
if (current.status === 'uploading') discardStaged(current)
|
|
266
|
-
patch(item.id, {
|
|
309
|
+
patch(item.id, {
|
|
310
|
+
...describeFailure(error),
|
|
311
|
+
requestError: error instanceof UploadError ? undefined : error,
|
|
312
|
+
resourceKey: undefined,
|
|
313
|
+
})
|
|
267
314
|
}
|
|
268
315
|
}
|
|
269
316
|
|
|
270
317
|
function pump(): void {
|
|
271
318
|
if (isPaused.value) return
|
|
272
|
-
const active = items.value.filter(
|
|
273
|
-
|
|
319
|
+
const active = items.value.filter(
|
|
320
|
+
(item) => item.status === 'uploading' || item.status === 'checking',
|
|
321
|
+
).length
|
|
322
|
+
const waiting = items.value.filter(
|
|
323
|
+
(item) => item.status === 'waiting' && !heldBatches.has(item.batchId),
|
|
324
|
+
)
|
|
274
325
|
for (const item of waiting.slice(0, Math.max(CONCURRENCY - active, 0))) {
|
|
275
326
|
void run(item).finally(() => {
|
|
276
327
|
reportSettledBatches()
|
|
@@ -280,10 +331,11 @@ function pump(): void {
|
|
|
280
331
|
}
|
|
281
332
|
|
|
282
333
|
function failureReason(item: UploadItem): string {
|
|
283
|
-
return (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
334
|
+
return (
|
|
335
|
+
item.message && item.message !== item.failure
|
|
336
|
+
? `${item.failure}: ${item.message}`
|
|
337
|
+
: (item.failure ?? 'server')
|
|
338
|
+
).slice(0, MAX_REASON_LENGTH)
|
|
287
339
|
}
|
|
288
340
|
|
|
289
341
|
function buildReport(batchId: string, batch: UploadItem[]): UploadBatchReport {
|
|
@@ -303,7 +355,10 @@ function buildReport(batchId: string, batch: UploadItem[]): UploadBatchReport {
|
|
|
303
355
|
}
|
|
304
356
|
}
|
|
305
357
|
|
|
306
|
-
function outcomeOf(
|
|
358
|
+
function outcomeOf(
|
|
359
|
+
report: UploadBatchReport,
|
|
360
|
+
batch: UploadItem[],
|
|
361
|
+
): UploadBatchOutcome {
|
|
307
362
|
return {
|
|
308
363
|
batchId: report.batchId,
|
|
309
364
|
folderId: report.folderId,
|
|
@@ -317,7 +372,8 @@ function outcomeOf(report: UploadBatchReport, batch: UploadItem[]): UploadBatchO
|
|
|
317
372
|
|
|
318
373
|
function batchesById(): Map<string, UploadItem[]> {
|
|
319
374
|
const batches = new Map<string, UploadItem[]>()
|
|
320
|
-
for (const item of items.value)
|
|
375
|
+
for (const item of items.value)
|
|
376
|
+
batches.set(item.batchId, [...(batches.get(item.batchId) ?? []), item])
|
|
321
377
|
return batches
|
|
322
378
|
}
|
|
323
379
|
|
|
@@ -327,7 +383,10 @@ function reportSettledBatches(): void {
|
|
|
327
383
|
reportedBatches.add(batchId)
|
|
328
384
|
const report = buildReport(batchId, batch)
|
|
329
385
|
batchListeners.forEach((listener) => listener(outcomeOf(report, batch)))
|
|
330
|
-
if (report.uploaded + report.failed > 0)
|
|
386
|
+
if (report.uploaded + report.failed > 0)
|
|
387
|
+
void api()
|
|
388
|
+
.reportBatch(report)
|
|
389
|
+
.catch(() => undefined)
|
|
331
390
|
}
|
|
332
391
|
}
|
|
333
392
|
|
|
@@ -337,7 +396,13 @@ function reportInterruptedBatches(): void {
|
|
|
337
396
|
if (reportedBatches.has(batchId) || batch.every(isFinal)) continue
|
|
338
397
|
reportedBatches.add(batchId)
|
|
339
398
|
const settled = batch.map((item) =>
|
|
340
|
-
isFinal(item)
|
|
399
|
+
isFinal(item)
|
|
400
|
+
? item
|
|
401
|
+
: {
|
|
402
|
+
...item,
|
|
403
|
+
status: 'failed' as const,
|
|
404
|
+
failure: 'interrupted' as const,
|
|
405
|
+
},
|
|
341
406
|
)
|
|
342
407
|
void api()
|
|
343
408
|
.reportBatch(buildReport(batchId, settled), { keepalive: true })
|
|
@@ -366,23 +431,41 @@ function isTypeRefused(file: File): boolean {
|
|
|
366
431
|
return Boolean(allowed && !matchesUploadType(uploadMimetype(file), allowed))
|
|
367
432
|
}
|
|
368
433
|
|
|
369
|
-
function refusesFieldType(
|
|
370
|
-
|
|
434
|
+
function refusesFieldType(
|
|
435
|
+
file: File,
|
|
436
|
+
accepts: readonly string[] | null | undefined,
|
|
437
|
+
): boolean {
|
|
438
|
+
return (
|
|
439
|
+
Boolean(accepts?.length) &&
|
|
440
|
+
!matchesUploadType(uploadMimetype(file), accepts ?? [])
|
|
441
|
+
)
|
|
371
442
|
}
|
|
372
443
|
|
|
373
444
|
/** Splits the files a field taking `accepts` (any file when empty) refuses from those it takes. */
|
|
374
|
-
function splitByFieldType(
|
|
445
|
+
function splitByFieldType(
|
|
446
|
+
selected: readonly File[],
|
|
447
|
+
accepts?: readonly string[] | null,
|
|
448
|
+
): FileSplit {
|
|
375
449
|
const refused = selected.filter((file) => refusesFieldType(file, accepts))
|
|
376
450
|
return { kept: selected.filter((file) => !refused.includes(file)), refused }
|
|
377
451
|
}
|
|
378
452
|
|
|
379
453
|
/** Refusals known before sending: the server would answer the same. */
|
|
380
|
-
function initialRefusal(
|
|
454
|
+
function initialRefusal(
|
|
455
|
+
file: File,
|
|
456
|
+
destination: UploadDestination,
|
|
457
|
+
): Pick<UploadItem, 'status' | 'failure' | 'details'> {
|
|
381
458
|
if (file.size === 0) return { status: 'rejected', failure: 'empty' }
|
|
382
|
-
if (file.size > uploadLimits.value.maxUploadBytes)
|
|
383
|
-
|
|
459
|
+
if (file.size > uploadLimits.value.maxUploadBytes)
|
|
460
|
+
return { status: 'rejected', failure: 'too_large' }
|
|
461
|
+
if (isTypeRefused(file))
|
|
462
|
+
return { status: 'rejected', failure: 'type_not_allowed' }
|
|
384
463
|
if (refusesFieldType(file, destination.accepts))
|
|
385
|
-
return {
|
|
464
|
+
return {
|
|
465
|
+
status: 'rejected',
|
|
466
|
+
failure: 'field_type',
|
|
467
|
+
details: { accepted: destination.accepts ?? [] },
|
|
468
|
+
}
|
|
386
469
|
return { status: 'waiting' }
|
|
387
470
|
}
|
|
388
471
|
|
|
@@ -390,7 +473,11 @@ function revokePreview(item: UploadItem): void {
|
|
|
390
473
|
if (item.previewUrl) URL.revokeObjectURL(item.previewUrl)
|
|
391
474
|
}
|
|
392
475
|
|
|
393
|
-
function createItem(
|
|
476
|
+
function createItem(
|
|
477
|
+
file: File,
|
|
478
|
+
destination: UploadDestination,
|
|
479
|
+
batchId: string,
|
|
480
|
+
): UploadItem {
|
|
394
481
|
const id = nextId()
|
|
395
482
|
files.set(id, file)
|
|
396
483
|
return {
|
|
@@ -402,7 +489,9 @@ function createItem(file: File, destination: UploadDestination, batchId: string)
|
|
|
402
489
|
folderName: destination.folderName,
|
|
403
490
|
batchId,
|
|
404
491
|
loaded: 0,
|
|
405
|
-
previewUrl: file.type.startsWith('image/')
|
|
492
|
+
previewUrl: file.type.startsWith('image/')
|
|
493
|
+
? URL.createObjectURL(file)
|
|
494
|
+
: undefined,
|
|
406
495
|
...initialRefusal(file, destination),
|
|
407
496
|
}
|
|
408
497
|
}
|
|
@@ -418,16 +507,35 @@ function createKeepBothPrompt(): KeepBothPrompt {
|
|
|
418
507
|
return (folderName, names) => {
|
|
419
508
|
const hidden = names.length - VISIBLE_DUPLICATE_NAMES
|
|
420
509
|
return confirm({
|
|
421
|
-
title: t(
|
|
422
|
-
|
|
510
|
+
title: t(
|
|
511
|
+
'dms_media.dialogs.duplicates.title',
|
|
512
|
+
{ count: names.length },
|
|
513
|
+
names.length,
|
|
514
|
+
),
|
|
515
|
+
description: t('dms_media.dialogs.duplicates.description', {
|
|
516
|
+
name: folderName,
|
|
517
|
+
}),
|
|
423
518
|
color: 'warning',
|
|
424
519
|
icon: 'i-ph-copy',
|
|
425
520
|
confirmIcon: 'i-ph-copy',
|
|
426
521
|
confirmLabel: t('dms_media.dialogs.duplicates.keep_both'),
|
|
427
522
|
cancelLabel: t('dms_media.actions.cancel'),
|
|
428
523
|
impact: [
|
|
429
|
-
...names
|
|
430
|
-
|
|
524
|
+
...names
|
|
525
|
+
.slice(0, VISIBLE_DUPLICATE_NAMES)
|
|
526
|
+
.map((name) => ({ icon: 'i-ph-file', label: name })),
|
|
527
|
+
...(hidden > 0
|
|
528
|
+
? [
|
|
529
|
+
{
|
|
530
|
+
icon: 'i-ph-dots-three',
|
|
531
|
+
label: t(
|
|
532
|
+
'dms_media.dialogs.duplicates.more',
|
|
533
|
+
{ count: hidden },
|
|
534
|
+
hidden,
|
|
535
|
+
),
|
|
536
|
+
},
|
|
537
|
+
]
|
|
538
|
+
: []),
|
|
431
539
|
],
|
|
432
540
|
})
|
|
433
541
|
}
|
|
@@ -436,19 +544,23 @@ function createKeepBothPrompt(): KeepBothPrompt {
|
|
|
436
544
|
function rejectBatch(waiting: UploadItem[], error: unknown): void {
|
|
437
545
|
const outcome = describeFailure(error)
|
|
438
546
|
if (outcome.status !== 'rejected') return
|
|
439
|
-
waiting.forEach((item) => patch(item.id, outcome))
|
|
547
|
+
waiting.forEach((item) => patch(item.id, { ...outcome, requestError: error }))
|
|
440
548
|
}
|
|
441
549
|
|
|
442
550
|
/** "Keep both" renames the copies `name (2).ext`; "Cancel" leaves them out. */
|
|
443
551
|
async function resolveDuplicates(batchId: string): Promise<void> {
|
|
444
|
-
const waiting = items.value.filter(
|
|
552
|
+
const waiting = items.value.filter(
|
|
553
|
+
(item) => item.batchId === batchId && item.status === 'waiting',
|
|
554
|
+
)
|
|
445
555
|
if (!waiting.length) return
|
|
446
556
|
try {
|
|
447
557
|
const { names } = await api().freeNames(
|
|
448
558
|
waiting[0]!.folderId,
|
|
449
559
|
waiting.map((item) => item.name),
|
|
450
560
|
)
|
|
451
|
-
const duplicates = waiting.flatMap((item, index) =>
|
|
561
|
+
const duplicates = waiting.flatMap((item, index) =>
|
|
562
|
+
names[index] ? [{ item, free: names[index]! }] : [],
|
|
563
|
+
)
|
|
452
564
|
if (!duplicates.length) return
|
|
453
565
|
const keepBoth = await askKeepBoth(
|
|
454
566
|
waiting[0]!.folderName,
|
|
@@ -456,7 +568,12 @@ async function resolveDuplicates(batchId: string): Promise<void> {
|
|
|
456
568
|
)
|
|
457
569
|
for (const { item, free } of duplicates) {
|
|
458
570
|
if (findItem(item.id)?.status !== 'waiting') continue
|
|
459
|
-
patch(
|
|
571
|
+
patch(
|
|
572
|
+
item.id,
|
|
573
|
+
keepBoth
|
|
574
|
+
? { name: free }
|
|
575
|
+
: { status: 'cancelled', failure: 'duplicate' },
|
|
576
|
+
)
|
|
460
577
|
}
|
|
461
578
|
} catch (error) {
|
|
462
579
|
rejectBatch(waiting, error)
|
|
@@ -466,7 +583,9 @@ async function resolveDuplicates(batchId: string): Promise<void> {
|
|
|
466
583
|
function enqueue(selected: File[], destination: UploadDestination): string {
|
|
467
584
|
guardUnload()
|
|
468
585
|
const batchId = newBatchId()
|
|
469
|
-
items.value.push(
|
|
586
|
+
items.value.push(
|
|
587
|
+
...selected.map((file) => createItem(file, destination, batchId)),
|
|
588
|
+
)
|
|
470
589
|
heldBatches.add(batchId)
|
|
471
590
|
void resolveDuplicates(batchId).finally(() => {
|
|
472
591
|
heldBatches.delete(batchId)
|
|
@@ -480,12 +599,20 @@ function retry(id: string): void {
|
|
|
480
599
|
const item = findItem(id)
|
|
481
600
|
if (!item || item.status !== 'failed' || !files.has(id)) return
|
|
482
601
|
reportedBatches.delete(item.batchId)
|
|
483
|
-
patch(id, {
|
|
602
|
+
patch(id, {
|
|
603
|
+
status: 'waiting',
|
|
604
|
+
failure: undefined,
|
|
605
|
+
message: undefined,
|
|
606
|
+
details: undefined,
|
|
607
|
+
requestError: undefined,
|
|
608
|
+
})
|
|
484
609
|
pump()
|
|
485
610
|
}
|
|
486
611
|
|
|
487
612
|
function retryFailed(): void {
|
|
488
|
-
items.value
|
|
613
|
+
items.value
|
|
614
|
+
.filter((item) => item.status === 'failed')
|
|
615
|
+
.forEach((item) => retry(item.id))
|
|
489
616
|
}
|
|
490
617
|
|
|
491
618
|
/** Only before the server starts checking: past that point the file is already being added. */
|
|
@@ -501,7 +628,9 @@ function cancel(id: string): void {
|
|
|
501
628
|
}
|
|
502
629
|
|
|
503
630
|
function cancelRemaining(): void {
|
|
504
|
-
items.value
|
|
631
|
+
items.value
|
|
632
|
+
.filter((item) => CANCELLABLE_STATUSES.has(item.status))
|
|
633
|
+
.forEach((item) => cancel(item.id))
|
|
505
634
|
}
|
|
506
635
|
|
|
507
636
|
function setPaused(paused: boolean): void {
|
|
@@ -540,7 +669,12 @@ function onBatchSettled(listener: BatchListener): () => void {
|
|
|
540
669
|
return () => batchListeners.delete(listener)
|
|
541
670
|
}
|
|
542
671
|
|
|
543
|
-
const activeCount = computed(
|
|
672
|
+
const activeCount = computed(
|
|
673
|
+
() =>
|
|
674
|
+
items.value.filter(
|
|
675
|
+
(item) => !isFinal(item) && !heldBatches.has(item.batchId),
|
|
676
|
+
).length,
|
|
677
|
+
)
|
|
544
678
|
|
|
545
679
|
/**
|
|
546
680
|
* The upload queue every media screen shares: files go to storage two at a
|
|
@@ -6,6 +6,7 @@ type Translate = ReturnType<typeof useI18n>['t']
|
|
|
6
6
|
|
|
7
7
|
interface Announcer {
|
|
8
8
|
toast: ToastApi
|
|
9
|
+
presentError: ReturnType<typeof useApiErrorPresenter>['presentError']
|
|
9
10
|
t: Translate
|
|
10
11
|
failureText: (item: UploadFailureSource) => string
|
|
11
12
|
failedItems: (batchId: string) => readonly UploadItem[]
|
|
@@ -32,11 +33,19 @@ function toastId(batchId: string): string {
|
|
|
32
33
|
|
|
33
34
|
function uploadsLink(announcer: Announcer, labelKey: string) {
|
|
34
35
|
if (!announcer.showUploadsLink) return undefined
|
|
35
|
-
return [
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
label: announcer.t(labelKey),
|
|
39
|
+
onClick: () => void navigateDms(MEDIA_ROUTES.uploads),
|
|
40
|
+
},
|
|
41
|
+
]
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
/** The reason most of the failed files share, or "various reasons" on a tie. */
|
|
39
|
-
function sharedReason(
|
|
45
|
+
function sharedReason(
|
|
46
|
+
announcer: Announcer,
|
|
47
|
+
failed: readonly UploadItem[],
|
|
48
|
+
): string {
|
|
40
49
|
const counts = new Map<string, number>()
|
|
41
50
|
for (const item of failed) {
|
|
42
51
|
const reason = announcer.failureText(item)
|
|
@@ -44,22 +53,36 @@ function sharedReason(announcer: Announcer, failed: readonly UploadItem[]): stri
|
|
|
44
53
|
}
|
|
45
54
|
const ranked = [...counts].sort((left, right) => right[1] - left[1])
|
|
46
55
|
const [top, runnerUp] = ranked
|
|
47
|
-
if (!top || (runnerUp && runnerUp[1] === top[1]))
|
|
56
|
+
if (!top || (runnerUp && runnerUp[1] === top[1]))
|
|
57
|
+
return announcer.t('dms_media.toasts.upload_failed_mixed')
|
|
48
58
|
return top[0]
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
function failureToast(announcer: Announcer, outcome: UploadBatchOutcome) {
|
|
52
62
|
const { t } = announcer
|
|
53
|
-
const failed = announcer
|
|
63
|
+
const failed = announcer
|
|
64
|
+
.failedItems(outcome.batchId)
|
|
65
|
+
.filter((item) => item.requestError === undefined)
|
|
54
66
|
const [only] = failed
|
|
55
67
|
const added = outcome.uploaded
|
|
56
|
-
? t(
|
|
68
|
+
? t(
|
|
69
|
+
'dms_media.toasts.upload_added',
|
|
70
|
+
{ count: outcome.uploaded, name: outcome.folderName },
|
|
71
|
+
outcome.uploaded,
|
|
72
|
+
)
|
|
57
73
|
: ''
|
|
58
74
|
const title =
|
|
59
75
|
failed.length === 1 && only
|
|
60
76
|
? t('dms_media.toasts.upload_failed_one', { name: only.name })
|
|
61
|
-
: t(
|
|
62
|
-
|
|
77
|
+
: t(
|
|
78
|
+
'dms_media.toasts.upload_failed',
|
|
79
|
+
{ count: failed.length, name: outcome.folderName },
|
|
80
|
+
failed.length,
|
|
81
|
+
)
|
|
82
|
+
const reason =
|
|
83
|
+
failed.length === 1 && only
|
|
84
|
+
? announcer.failureText(only)
|
|
85
|
+
: sharedReason(announcer, failed)
|
|
63
86
|
return { title, description: [reason, added].filter(Boolean).join(' · ') }
|
|
64
87
|
}
|
|
65
88
|
|
|
@@ -69,28 +92,49 @@ function settle(outcome: UploadBatchOutcome): void {
|
|
|
69
92
|
announcers.delete(outcome.batchId)
|
|
70
93
|
const { toast, t } = announcer
|
|
71
94
|
toast.remove(toastId(outcome.batchId))
|
|
72
|
-
|
|
95
|
+
const failed = announcer.failedItems(outcome.batchId)
|
|
96
|
+
for (const item of failed) {
|
|
97
|
+
if (item.requestError === undefined) continue
|
|
98
|
+
announcer.presentError(item.requestError, {
|
|
99
|
+
fallbackKey: 'dms_media.toasts.upload_failed_one',
|
|
100
|
+
params: { name: item.name },
|
|
101
|
+
actions: announcer.showUploadsLink
|
|
102
|
+
? [
|
|
103
|
+
{
|
|
104
|
+
labelKey: 'dms_media.upload_strip.see_details',
|
|
105
|
+
onSelect: () => navigateDms(MEDIA_ROUTES.uploads),
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
: undefined,
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
if (failed.some((item) => item.requestError === undefined))
|
|
73
112
|
return void toast.add({
|
|
74
113
|
...failureToast(announcer, outcome),
|
|
75
114
|
icon: 'i-ph-cloud-slash',
|
|
76
|
-
color: '
|
|
115
|
+
color: 'warning',
|
|
77
116
|
actions: uploadsLink(announcer, 'dms_media.upload_strip.see_details'),
|
|
78
117
|
})
|
|
79
|
-
if (!outcome.uploaded) return
|
|
118
|
+
if (outcome.failed || !outcome.uploaded) return
|
|
80
119
|
toast.add({
|
|
81
|
-
title: t(
|
|
120
|
+
title: t(
|
|
121
|
+
'dms_media.toasts.upload_added',
|
|
122
|
+
{ count: outcome.uploaded, name: outcome.folderName },
|
|
123
|
+
outcome.uploaded,
|
|
124
|
+
),
|
|
82
125
|
icon: 'i-ph-check-circle',
|
|
83
126
|
color: 'success',
|
|
84
127
|
})
|
|
85
128
|
}
|
|
86
129
|
|
|
87
130
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* was left.
|
|
131
|
+
* Shows batch progress, then request failures through the API presenter and
|
|
132
|
+
* local validation or success notices once every file settles, even after
|
|
133
|
+
* the page that started the batch was left.
|
|
91
134
|
*/
|
|
92
135
|
export function useUploadToasts() {
|
|
93
136
|
const toast = useToast()
|
|
137
|
+
const { presentError } = useApiErrorPresenter()
|
|
94
138
|
const { t } = useI18n()
|
|
95
139
|
const uploads = useUploadQueue()
|
|
96
140
|
const failureText = useUploadFailureText()
|
|
@@ -99,18 +143,31 @@ export function useUploadToasts() {
|
|
|
99
143
|
uploads.onBatchSettled(settle)
|
|
100
144
|
}
|
|
101
145
|
|
|
102
|
-
function announce(
|
|
146
|
+
function announce(
|
|
147
|
+
batchId: string,
|
|
148
|
+
count: number,
|
|
149
|
+
folderName: string,
|
|
150
|
+
options: UploadToastOptions = {},
|
|
151
|
+
): void {
|
|
103
152
|
const announcer: Announcer = {
|
|
104
153
|
toast,
|
|
154
|
+
presentError,
|
|
105
155
|
t,
|
|
106
156
|
failureText,
|
|
107
|
-
failedItems: (id) =>
|
|
157
|
+
failedItems: (id) =>
|
|
158
|
+
uploads.items.value.filter(
|
|
159
|
+
(item) => item.batchId === id && FAILED_STATUSES.has(item.status),
|
|
160
|
+
),
|
|
108
161
|
showUploadsLink: options.showUploadsLink ?? true,
|
|
109
162
|
}
|
|
110
163
|
announcers.set(batchId, announcer)
|
|
111
164
|
toast.add({
|
|
112
165
|
id: toastId(batchId),
|
|
113
|
-
title: t(
|
|
166
|
+
title: t(
|
|
167
|
+
'dms_media.toasts.uploading',
|
|
168
|
+
{ count, name: folderName },
|
|
169
|
+
count,
|
|
170
|
+
),
|
|
114
171
|
icon: 'i-ph-cloud-arrow-up',
|
|
115
172
|
color: 'neutral',
|
|
116
173
|
actions: uploadsLink(announcer, 'dms_media.upload_strip.see_progress'),
|
|
@@ -118,7 +175,10 @@ export function useUploadToasts() {
|
|
|
118
175
|
}
|
|
119
176
|
|
|
120
177
|
/** Names the files a field refused for their type, and says what it takes. */
|
|
121
|
-
function announceRefusedTypes(
|
|
178
|
+
function announceRefusedTypes(
|
|
179
|
+
refused: readonly File[],
|
|
180
|
+
accept: readonly string[],
|
|
181
|
+
): void {
|
|
122
182
|
if (refused.length === 0) return
|
|
123
183
|
const types = fieldTypesLabel(accept, t)
|
|
124
184
|
toast.add({
|
|
@@ -127,7 +187,9 @@ export function useUploadToasts() {
|
|
|
127
187
|
{ names: refused.map((file) => file.name).join(NAMES_SEPARATOR) },
|
|
128
188
|
refused.length,
|
|
129
189
|
),
|
|
130
|
-
description: types
|
|
190
|
+
description: types
|
|
191
|
+
? t('dms_media.field_widget.upload.accepts', { types })
|
|
192
|
+
: undefined,
|
|
131
193
|
color: 'warning',
|
|
132
194
|
icon: 'i-ph-file-x',
|
|
133
195
|
})
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
"main": "./dms.frontend.ts",
|
|
7
7
|
"packageManager": "pnpm@10.6.5",
|
|
8
8
|
"engines": {
|
|
9
|
-
"@antelopejs/dms-frontend": ">=0.
|
|
9
|
+
"@antelopejs/dms-frontend": ">=0.10.0 <0.11.0"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "pnpm --dir ../playground frontend:dev",
|
|
13
13
|
"build": "pnpm --dir ../playground exec ajs dms build",
|
|
14
14
|
"typecheck": "pnpm --dir \"${DMS_FRONTEND_WORKSPACE:?Set DMS_FRONTEND_WORKSPACE to the generated Inertia workspace}\" typecheck",
|
|
15
15
|
"format": "prettier --write .",
|
|
16
|
-
"lint": "eslint .",
|
|
16
|
+
"lint": "eslint . && node ../node_modules/@antelopejs/dms/frontend-vue/scripts/check-api-error-presentation.mjs app",
|
|
17
17
|
"lint:fix": "eslint . --fix",
|
|
18
18
|
"test": "vitest run"
|
|
19
19
|
},
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"zod": "^3.24.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@antelopejs/tooling-configs": "^0.2.
|
|
29
|
+
"@antelopejs/tooling-configs": "^0.2.18",
|
|
30
30
|
"@nuxt/ui": "4.10.0",
|
|
31
31
|
"@typescript-eslint/parser": "^8.0.0",
|
|
32
32
|
"@vitejs/plugin-vue": "^6.0.10",
|