feat: implement media asset reactivation and enhance lifecycle management
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Successful in 31s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Successful in 31s
- Added a new action to the media asset lifecycle for reactivating assets from the trash, allowing users to restore previously deleted media. - Updated the backend API to handle reactivation requests and ensure proper state transitions for media assets. - Enhanced frontend error handling to prompt users for reactivation when attempting to upload media that matches an existing asset in the trash. - Incremented version to 0.8.45, reflecting the latest changes in media lifecycle management and user experience improvements.
This commit is contained in:
1 parent
e2964a077d
commit
da368222e0
8 files changed
+198
-44
No files matched your search
@@ -694,7 +694,44 @@ function ExerciseFormPage() {
|
||||
setMediaTitle('')
|
||||
await refreshMedia()
|
||||
} catch (err) {
|
||||
alert('Upload: ' + err.message)
|
||||
if (err.code === 'MEDIA_ASSET_IN_TRASH' && err.payload?.media_asset_id != null) {
|
||||
const aid = err.payload.media_asset_id
|
||||
const nameHint =
|
||||
(mediaFile && mediaFile.name) ||
|
||||
err.payload.original_filename ||
|
||||
'diese Datei'
|
||||
if (
|
||||
confirm(
|
||||
`Die hochgeladene Datei ist inhaltsgleich mit einem Archiv-Medium im Papierkorb (${nameHint}). ` +
|
||||
'Soll dieses Medium wieder aktiviert und an die Übung gehängt werden? (Es wird kein zweites Exemplar auf der Platte angelegt.)',
|
||||
)
|
||||
) {
|
||||
try {
|
||||
await api.postMediaAssetLifecycle(aid, 'reactivate')
|
||||
await api.attachExerciseMediaFromAsset(exerciseId, {
|
||||
media_asset_id: aid,
|
||||
title: mediaTitle || undefined,
|
||||
description: '',
|
||||
context: mediaContext,
|
||||
is_primary: false,
|
||||
})
|
||||
setMediaFile(null)
|
||||
setMediaTitle('')
|
||||
await refreshMedia()
|
||||
} catch (e2) {
|
||||
alert(e2.message || String(e2))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if (err.code === 'MEDIA_ASSET_UNAVAILABLE') {
|
||||
alert(
|
||||
(err.message || 'Archiv-Konflikt') +
|
||||
' Bitte wenden Sie sich an einen Administrator oder wählen Sie eine andere Datei.',
|
||||
)
|
||||
return
|
||||
}
|
||||
alert('Upload: ' + (err.message || String(err)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -473,12 +473,29 @@ export async function uploadExerciseMedia(exerciseId, formData) {
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({ detail: 'Unknown error' }))
|
||||
const d = err.detail
|
||||
if (
|
||||
response.status === 409 &&
|
||||
d &&
|
||||
typeof d === 'object' &&
|
||||
!Array.isArray(d) &&
|
||||
typeof d.code === 'string'
|
||||
) {
|
||||
const e = new Error(
|
||||
typeof d.message === 'string' ? d.message : 'Upload konnte nicht verarbeitet werden',
|
||||
)
|
||||
e.code = d.code
|
||||
e.status = 409
|
||||
e.payload = d
|
||||
throw e
|
||||
}
|
||||
const msg =
|
||||
typeof d === 'string'
|
||||
? d
|
||||
: d != null
|
||||
? JSON.stringify(d)
|
||||
: `HTTP ${response.status}`
|
||||
: d != null && typeof d === 'object' && typeof d.message === 'string'
|
||||
? d.message
|
||||
: d != null
|
||||
? JSON.stringify(d)
|
||||
: `HTTP ${response.status}`
|
||||
throw new Error(msg)
|
||||
}
|
||||
return response.json()
|
||||
@@ -502,7 +519,7 @@ export async function reorderExerciseMedia(exerciseId, mediaIds) {
|
||||
})
|
||||
}
|
||||
|
||||
/** Papierkorb / Recovery — `action`: trash_soft | trash_hidden | recover | purge */
|
||||
/** Papierkorb / Recovery — `action`: trash_soft | trash_hidden | recover | purge | reactivate */
|
||||
export async function postMediaAssetLifecycle(assetId, action) {
|
||||
return request(`/api/media-assets/${assetId}/lifecycle`, {
|
||||
method: 'POST',
|
||||
|
||||
Reference in new issue
Block a user