re-enabled autoseeding of attachment groups
This commit is contained in:
@@ -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 }) {
|
||||
<div className="d-flex justify-content-between align-items-center mb-3">
|
||||
<h5 className="mb-0">{t('attachment.groups_title')}</h5>
|
||||
<div className="d-flex align-items-center gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
className="bb-accent-button"
|
||||
onClick={handleSeedAttachmentDefaults}
|
||||
disabled={attachmentSeedSaving}
|
||||
>
|
||||
{attachmentSeedSaving
|
||||
? t('attachment.seed_in_progress')
|
||||
: t('attachment.seed_defaults')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline-secondary"
|
||||
@@ -2722,6 +2761,16 @@ export default function Acp({ isAdmin }) {
|
||||
{!attachmentGroupsLoading && attachmentGroups.length > 0
|
||||
&& attachmentGroups.every((group) => !group.parent_id) && (
|
||||
<div className="bb-muted mb-3">
|
||||
<Button
|
||||
type="button"
|
||||
className="bb-accent-button me-2"
|
||||
onClick={handleSeedAttachmentDefaults}
|
||||
disabled={attachmentSeedSaving}
|
||||
>
|
||||
{attachmentSeedSaving
|
||||
? t('attachment.seed_in_progress')
|
||||
: t('attachment.seed_defaults')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline-secondary"
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Http\Controllers\I18nController;
|
||||
use App\Http\Controllers\PortalController;
|
||||
use App\Http\Controllers\PostController;
|
||||
use App\Http\Controllers\PostThankController;
|
||||
use App\Http\Controllers\PreviewController;
|
||||
use App\Http\Controllers\SettingController;
|
||||
use App\Http\Controllers\StatsController;
|
||||
use App\Http\Controllers\ThreadController;
|
||||
@@ -96,3 +97,4 @@ Route::post('/posts', [PostController::class, 'store'])->middleware('auth:sanctu
|
||||
Route::post('/posts/{post}/thanks', [PostThankController::class, 'store'])->middleware('auth:sanctum');
|
||||
Route::delete('/posts/{post}/thanks', [PostThankController::class, 'destroy'])->middleware('auth:sanctum');
|
||||
Route::delete('/posts/{post}', [PostController::class, 'destroy'])->middleware('auth:sanctum');
|
||||
Route::post('/preview', [PreviewController::class, 'preview'])->middleware('auth:sanctum');
|
||||
|
||||
Reference in New Issue
Block a user