diff --git a/resources/js/pages/Acp.jsx b/resources/js/pages/Acp.jsx index e0f8080..35c633b 100644 --- a/resources/js/pages/Acp.jsx +++ b/resources/js/pages/Acp.jsx @@ -1140,34 +1140,63 @@ export default function Acp({ isAdmin }) { setAttachmentGroupsError('') setAttachmentExtensionsError('') try { + const groupsByName = new Map(attachmentGroups.map((group) => [group.name, group])) + const extensionsByGroup = new Map() + attachmentExtensions.forEach((ext) => { + const groupId = ext.attachment_group_id ? String(ext.attachment_group_id) : 'none' + if (!extensionsByGroup.has(groupId)) { + extensionsByGroup.set(groupId, new Set()) + } + extensionsByGroup + .get(groupId) + .add(String(ext.extension || '').toLowerCase()) + }) const createdGroups = [] const createdExtensions = [] for (const group of attachmentDefaultSeed) { - const parent = await createAttachmentGroup({ - name: group.name, - max_size_kb: group.max_size_kb, - is_active: true, - }) + let parent = groupsByName.get(group.name) + if (!parent) { + parent = await createAttachmentGroup({ + name: group.name, + max_size_kb: group.max_size_kb, + is_active: true, + }) + groupsByName.set(group.name, parent) + createdGroups.push(parent) + } createdGroups.push(parent) for (const child of group.children || []) { - const createdChild = await createAttachmentGroup({ - name: child.name, - parent_id: parent.id, - max_size_kb: child.max_size_kb, - is_active: true, - }) - createdGroups.push(createdChild) + let createdChild = groupsByName.get(child.name) + if (!createdChild) { + createdChild = await createAttachmentGroup({ + name: child.name, + parent_id: parent.id, + max_size_kb: child.max_size_kb, + is_active: true, + }) + groupsByName.set(child.name, createdChild) + createdGroups.push(createdChild) + } + + const groupKey = String(createdChild.id) + const existingSet = extensionsByGroup.get(groupKey) || new Set() for (const ext of child.extensions || []) { + const key = String(ext.ext || '').toLowerCase() + if (existingSet.has(key)) { + continue + } const createdExt = await createAttachmentExtension({ extension: ext.ext, attachment_group_id: createdChild.id, allowed_mimes: ext.mimes, }) createdExtensions.push(createdExt) + existingSet.add(key) } + extensionsByGroup.set(groupKey, existingSet) } } @@ -2677,6 +2706,16 @@ export default function Acp({ isAdmin }) {