@crombolo/api-management 0.45.0 → 0.46.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/package.json +4 -4
- package/src/handlers/media.ts +45 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/api-management",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Umbraco-compatible Management API handlers for crombolo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@crombolo/content": "0.
|
|
33
|
-
"@crombolo/contracts": "0.
|
|
34
|
-
"@crombolo/core": "0.
|
|
32
|
+
"@crombolo/content": "0.46.1",
|
|
33
|
+
"@crombolo/contracts": "0.46.1",
|
|
34
|
+
"@crombolo/core": "0.46.1"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/handlers/media.ts
CHANGED
|
@@ -120,6 +120,8 @@ export function registerMediaHandlers(
|
|
|
120
120
|
const mediaStart = (ctx: RequestContext) => ctx.principal?.startNodes.media ?? ROOT_ACCESS
|
|
121
121
|
|
|
122
122
|
/** The signed-in user, as the operations know them: their rules apply (story 165). */
|
|
123
|
+
const DELETING_LATER =
|
|
124
|
+
'This holds a lot of items, so it is being deleted in the background. It will be gone in a few moments.'
|
|
123
125
|
const actorOf = (ctx: RequestContext) =>
|
|
124
126
|
userActor(ctx.principal as NonNullable<typeof ctx.principal>, ctx.client ?? {})
|
|
125
127
|
const missing = (result: Refusal, title: string) =>
|
|
@@ -130,6 +132,15 @@ export function registerMediaHandlers(
|
|
|
130
132
|
if (message) ctx.notifications.push({ message, category: 'Media', type: 'Success' })
|
|
131
133
|
return new Response(null, { status: 200 })
|
|
132
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* A large branch's write was queued (story 246): the editor is told it is under
|
|
137
|
+
* way, and `Crombolo-Job` names the job its progress is read from.
|
|
138
|
+
*/
|
|
139
|
+
const queuedOr = (ctx: RequestContext, result: { queued?: string }, message: string) => {
|
|
140
|
+
if (!result.queued) return done(ctx)
|
|
141
|
+
ctx.notifications.push({ message, category: 'Media', type: 'Info' })
|
|
142
|
+
return new Response(null, { status: 200, headers: { 'crombolo-job': result.queued } })
|
|
143
|
+
}
|
|
133
144
|
|
|
134
145
|
router.handle('GetItemMediaTypeAllowed', async (ctx) => {
|
|
135
146
|
const page = paging(ctx)
|
|
@@ -219,12 +230,20 @@ export function registerMediaHandlers(
|
|
|
219
230
|
|
|
220
231
|
router.handle('DeleteMediaById', async (ctx) => {
|
|
221
232
|
const result = await operations.delete(actorOf(ctx), ctx.params.id as string)
|
|
222
|
-
return result.ok
|
|
233
|
+
return result.ok
|
|
234
|
+
? queuedOr(ctx, result, DELETING_LATER)
|
|
235
|
+
: missing(result, 'Could not delete the media item')
|
|
223
236
|
})
|
|
224
237
|
|
|
225
238
|
router.handle('PutMediaByIdMoveToRecycleBin', async (ctx) => {
|
|
226
239
|
const result = await operations.trash(actorOf(ctx), ctx.params.id as string)
|
|
227
|
-
return result.ok
|
|
240
|
+
return result.ok
|
|
241
|
+
? queuedOr(
|
|
242
|
+
ctx,
|
|
243
|
+
result,
|
|
244
|
+
'This holds a lot of items, so it is being moved to the recycle bin in the background. It will be there in a few moments.',
|
|
245
|
+
)
|
|
246
|
+
: missing(result, 'Could not move the media item')
|
|
228
247
|
})
|
|
229
248
|
|
|
230
249
|
router.handle('PutMediaByIdMove', async (ctx) => {
|
|
@@ -233,7 +252,13 @@ export function registerMediaHandlers(
|
|
|
233
252
|
ctx.params.id as string,
|
|
234
253
|
refId((await readBody(ctx)).target),
|
|
235
254
|
)
|
|
236
|
-
return result.ok
|
|
255
|
+
return result.ok
|
|
256
|
+
? queuedOr(
|
|
257
|
+
ctx,
|
|
258
|
+
result,
|
|
259
|
+
'This holds a lot of items, so it is being moved in the background. It will be in its new place in a few moments.',
|
|
260
|
+
)
|
|
261
|
+
: failed('Could not move the media item', result)
|
|
237
262
|
})
|
|
238
263
|
|
|
239
264
|
router.handle('PutMediaSort', async (ctx) => {
|
|
@@ -446,7 +471,13 @@ export function registerMediaHandlers(
|
|
|
446
471
|
ctx.params.id as string,
|
|
447
472
|
target ?? undefined,
|
|
448
473
|
)
|
|
449
|
-
return result.ok
|
|
474
|
+
return result.ok
|
|
475
|
+
? queuedOr(
|
|
476
|
+
ctx,
|
|
477
|
+
result,
|
|
478
|
+
'This holds a lot of items, so it is being restored in the background. It will be back in a few moments.',
|
|
479
|
+
)
|
|
480
|
+
: failed('Could not restore', result)
|
|
450
481
|
})
|
|
451
482
|
router.handle('DeleteRecycleBinMediaById', async (ctx) => {
|
|
452
483
|
const key = ctx.params.id as string
|
|
@@ -457,11 +488,19 @@ export function registerMediaHandlers(
|
|
|
457
488
|
problemDetails({ title: 'The media item is not in the recycle bin', status: 400 }),
|
|
458
489
|
)
|
|
459
490
|
const result = await operations.delete(actorOf(ctx), key, { fromBin: true })
|
|
460
|
-
return result.ok
|
|
491
|
+
return result.ok
|
|
492
|
+
? queuedOr(ctx, result, DELETING_LATER)
|
|
493
|
+
: missing(result, 'Could not delete the media item')
|
|
461
494
|
})
|
|
462
495
|
router.handle('DeleteRecycleBinMedia', async (ctx) => {
|
|
463
496
|
const result = await operations.emptyBin(actorOf(ctx))
|
|
464
|
-
return result.ok
|
|
497
|
+
return result.ok
|
|
498
|
+
? queuedOr(
|
|
499
|
+
ctx,
|
|
500
|
+
result,
|
|
501
|
+
'The recycle bin holds a lot of items, so it is being emptied in the background. This can take a few minutes.',
|
|
502
|
+
)
|
|
503
|
+
: failed('Could not empty the recycle bin', result)
|
|
465
504
|
})
|
|
466
505
|
|
|
467
506
|
// References arrive with relations (story 046); nothing is known to refer yet.
|