Project-Image-Uploader/frontend/src/Utils/batchUpload.js
matthias.lotz bd7bdac000 refactor: Complete UI refactoring with modular components
- Refactored ManagementPortalPage, MultiUploadPage, ModerationGroupImagesPage
- Created reusable modular components with mode support:
  * ImageDescriptionManager (manage/moderate modes)
  * GroupMetadataEditor (edit/upload/moderate modes)
  * ConsentManager (edit/upload modes)
- Replaced Material-UI Buttons with HTML buttons + CSS classes
- Fixed image descriptions upload (preview ID to filename mapping)
- Reduced ModerationGroupImagesPage from 281 to 107 lines
- Updated ModerationGroupsPage and GroupsOverviewPage button styles
- All pages now use consistent Paper boxes with headings
- Inline Material-UI Alerts instead of SweetAlert2 popups (except destructive actions)
- Icons: 💾 save, ↩ discard, 🗑️ delete consistently used
2025-11-15 18:17:14 +01:00

101 lines
2.7 KiB
JavaScript

// Batch-Upload Funktion für mehrere Bilder
export const uploadImageBatch = async ({ images, metadata, imageDescriptions = {}, consents = null, onProgress }) => {
if (!images || images.length === 0) {
throw new Error('Keine Bilder zum Upload ausgewählt');
}
const formData = new FormData();
// Füge alle Bilder hinzu
images.forEach((image) => {
formData.append('images', image);
});
// Füge Metadaten hinzu
formData.append('metadata', JSON.stringify(metadata || {}));
// Füge Beschreibungen hinzu (convert object to array format with fileName)
const descriptionsArray = Object.entries(imageDescriptions).map(([fileName, description]) => ({
fileName: fileName,
description
}));
if (descriptionsArray.length > 0) {
formData.append('descriptions', JSON.stringify(descriptionsArray));
}
// Füge Einwilligungen hinzu (GDPR)
if (consents) {
formData.append('consents', JSON.stringify(consents));
}
try {
const response = await fetch('/api/upload/batch', {
method: 'POST',
body: formData
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
}
const result = await response.json();
return result;
} catch (error) {
console.error('Batch upload error:', error);
throw error;
}
};
// Einzelne Gruppe abrufen
export const fetchGroup = async (groupId) => {
try {
const response = await fetch(`/api/groups/${groupId}`);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching group:', error);
throw error;
}
};
// Alle Gruppen abrufen
export const fetchAllGroups = async () => {
try {
const response = await fetch('/api/groups');
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching groups:', error);
throw error;
}
};
// Gruppe löschen
export const deleteGroup = async (groupId) => {
try {
const response = await fetch(`/api/groups/${groupId}`, {
method: 'DELETE'
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error deleting group:', error);
throw error;
}
};