feat: implement bulk upload functionality for media assets
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 29s
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 29s
- Added a new API endpoint for bulk uploading media assets, allowing users to upload multiple files in a single request. - Implemented validation for file types and sizes during the upload process, ensuring compliance with allowed formats and limits. - Enhanced the MediaLibraryPage component to support bulk file selection and visibility options, improving user experience. - Updated CSS styles for the upload interface to enhance layout and accessibility. - Added tests to verify the functionality of the new bulk upload feature and its integration with existing media asset management.
This commit is contained in:
1 parent
4f64cb105b
commit
f9e6e61244
5 files changed
+444
-8
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState, useCallback } from 'react'
|
||||
import { useEffect, useState, useCallback, useRef } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
LayoutGrid,
|
||||
@@ -13,6 +13,11 @@ import {
|
||||
CircleDot,
|
||||
FilePenLine,
|
||||
Copyright,
|
||||
Image,
|
||||
Video,
|
||||
FileText,
|
||||
File,
|
||||
Upload,
|
||||
} from 'lucide-react'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import api from '../utils/api'
|
||||
@@ -195,6 +200,32 @@ function previewDisplayKind(mimeType) {
|
||||
return 'other'
|
||||
}
|
||||
|
||||
const MEDIA_KIND_LABELS = {
|
||||
image: 'Bild',
|
||||
video: 'Video',
|
||||
pdf: 'PDF',
|
||||
other: 'Sonstiges',
|
||||
}
|
||||
|
||||
function MediaTypeGlyph({ mimeType, compact }) {
|
||||
const kind = previewDisplayKind(mimeType)
|
||||
const label = MEDIA_KIND_LABELS[kind] || 'Medium'
|
||||
let Icon = File
|
||||
if (kind === 'image') Icon = Image
|
||||
else if (kind === 'video') Icon = Video
|
||||
else if (kind === 'pdf') Icon = FileText
|
||||
const sz = compact ? 12 : 14
|
||||
return (
|
||||
<span
|
||||
className={`media-library__card-type${compact ? ' media-library__card-type--compact' : ''}`}
|
||||
title={label}
|
||||
aria-label={`Medientyp: ${label}`}
|
||||
>
|
||||
<Icon size={sz} strokeWidth={2} aria-hidden />
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export default function MediaLibraryPage() {
|
||||
const { user } = useAuth()
|
||||
const isPlatformAdmin = user?.role === 'admin' || user?.role === 'superadmin'
|
||||
@@ -222,6 +253,11 @@ export default function MediaLibraryPage() {
|
||||
const [filterClubId, setFilterClubId] = useState('')
|
||||
const [filterUploaderId, setFilterUploaderId] = useState('')
|
||||
const [uploaderFilterOptions, setUploaderFilterOptions] = useState([])
|
||||
const bulkFileInputRef = useRef(null)
|
||||
const [uploadVis, setUploadVis] = useState('private')
|
||||
const [uploadClubId, setUploadClubId] = useState('')
|
||||
const [uploadBusy, setUploadBusy] = useState(false)
|
||||
const [uploadSummary, setUploadSummary] = useState('')
|
||||
|
||||
const loadClubs = useCallback(async () => {
|
||||
try {
|
||||
@@ -428,6 +464,33 @@ export default function MediaLibraryPage() {
|
||||
|
||||
const selCount = selected.size
|
||||
|
||||
const onBulkArchiveFiles = async (e) => {
|
||||
const fl = e.target.files
|
||||
if (!fl?.length) return
|
||||
const list = Array.from(fl)
|
||||
e.target.value = ''
|
||||
if (uploadVis === 'club' && !Number(uploadClubId)) {
|
||||
window.alert('Bitte einen Verein für die Sichtbarkeit „Verein“ wählen.')
|
||||
return
|
||||
}
|
||||
setUploadBusy(true)
|
||||
setUploadSummary('')
|
||||
try {
|
||||
const res = await api.bulkUploadMediaAssets(list, {
|
||||
visibility: uploadVis,
|
||||
...(uploadVis === 'club' ? { club_id: Number(uploadClubId) } : {}),
|
||||
})
|
||||
setUploadSummary(
|
||||
`Archiv-Upload: neu ${res.created_count}, bereits vorhanden ${res.duplicate_count}, fehlgeschlagen ${res.failed_count}.`,
|
||||
)
|
||||
await loadItems()
|
||||
} catch (err) {
|
||||
window.alert(err.message || String(err))
|
||||
} finally {
|
||||
setUploadBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-page media-library">
|
||||
{isPlatformAdmin ? <AdminPageNav /> : null}
|
||||
@@ -541,6 +604,61 @@ export default function MediaLibraryPage() {
|
||||
</select>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="media-library__upload-row" aria-label="Archiv hochladen">
|
||||
<input
|
||||
ref={bulkFileInputRef}
|
||||
type="file"
|
||||
className="media-library__sr-file"
|
||||
accept="image/jpeg,image/png,image/gif,video/mp4,application/pdf,.jpg,.jpeg,.png,.gif,.mp4,.pdf"
|
||||
multiple
|
||||
onChange={onBulkArchiveFiles}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={uploadBusy}
|
||||
onClick={() => bulkFileInputRef.current?.click()}
|
||||
title="Mehrere Dateien ins Archiv laden"
|
||||
>
|
||||
<Upload size={18} aria-hidden className="media-library__upload-icon" />
|
||||
Archiv-Upload
|
||||
</button>
|
||||
<select
|
||||
className="form-input"
|
||||
value={uploadVis}
|
||||
onChange={(e) => {
|
||||
setUploadVis(e.target.value)
|
||||
setUploadSummary('')
|
||||
}}
|
||||
aria-label="Sichtbarkeit für neuen Upload"
|
||||
>
|
||||
{VIS_OPTIONS.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
Upload: {o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{uploadVis === 'club' ? (
|
||||
<select
|
||||
className="form-input"
|
||||
value={uploadClubId}
|
||||
onChange={(e) => setUploadClubId(e.target.value)}
|
||||
aria-label="Verein für Upload"
|
||||
>
|
||||
<option value="">Verein wählen…</option>
|
||||
{clubs.map((c) => (
|
||||
<option key={c.id} value={String(c.id)}>
|
||||
{c.name || c.id}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : null}
|
||||
{uploadSummary ? (
|
||||
<span className="media-library__upload-summary" role="status">
|
||||
{uploadSummary}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="media-library__toolbar-meta">
|
||||
<label className="media-library__check-all">
|
||||
<input type="checkbox" checked={items.length > 0 && selCount === items.length} onChange={selectAll} />
|
||||
@@ -591,6 +709,7 @@ export default function MediaLibraryPage() {
|
||||
title="Vorschau"
|
||||
>
|
||||
<div className="media-library__card-thumb-wrap">
|
||||
<MediaTypeGlyph mimeType={it.mime_type} />
|
||||
<MediaThumb mediaId={it.id} mimeType={it.mime_type} />
|
||||
{(it.copyright_notice || '').trim() ? (
|
||||
<span
|
||||
@@ -658,6 +777,7 @@ export default function MediaLibraryPage() {
|
||||
title="Vorschau"
|
||||
>
|
||||
<div className="media-library__table-thumb">
|
||||
<MediaTypeGlyph mimeType={it.mime_type} compact />
|
||||
<MediaThumb mediaId={it.id} mimeType={it.mime_type} />
|
||||
</div>
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user