관리자 업로드 제한 설정 추가

This commit is contained in:
2026-07-01 17:58:30 +09:00
parent 129b68b939
commit e5d3eac2fd
17 changed files with 308 additions and 20 deletions

View File

@@ -4,13 +4,17 @@ import { createError, readMultipartFormData } from 'h3'
import {
buildDefaultUploadSizeLimits,
formatUploadSizeLimit,
getUploadFilesTotalSize,
getMaxUploadBytesForKind,
getUploadKind,
getUploadKindLabel
getUploadKindLabel,
normalizeUploadMaxFileCount,
normalizeUploadMaxTotalSize
} from '../../../../lib/upload-size-limit.js'
import { requireAdminSession } from '../../../utils/admin-auth'
import { getRuntimeEnvNumber } from '../../../utils/runtime-env.js'
import { upsertMediaMetadataCategory } from '../../../utils/media-library'
import { getSiteSettings } from '../../../repositories/content-repository'
const allowedUploadTypes = new Map([
['image/jpeg', '.jpg'],
@@ -135,6 +139,9 @@ export default defineEventHandler(async (event) => {
audio: getRuntimeEnvNumber('MAX_AUDIO_FILE_SIZE', 'maxAudioFileSize', 52428800),
document: getRuntimeEnvNumber('MAX_DOCUMENT_FILE_SIZE', 'maxDocumentFileSize', 52428800)
})
const settings = await getSiteSettings()
const uploadMaxFileCount = normalizeUploadMaxFileCount(settings.uploadMaxFileCount)
const uploadMaxTotalSize = normalizeUploadMaxTotalSize(settings.uploadMaxTotalSize)
const formData = await readMultipartFormData(event)
const files = (formData || []).filter((part) => part.name === 'files' && part.filename)
@@ -145,6 +152,22 @@ export default defineEventHandler(async (event) => {
})
}
if (files.length > uploadMaxFileCount) {
throw createError({
statusCode: 413,
message: `한 번에 업로드할 수 있는 파일은 최대 ${uploadMaxFileCount}개입니다.`
})
}
const uploadTotalSize = getUploadFilesTotalSize(files)
if (uploadTotalSize > uploadMaxTotalSize) {
throw createError({
statusCode: 413,
message: `한 번에 업로드 가능한 전체 용량을 초과했습니다. (최대 ${formatUploadSizeLimit(uploadMaxTotalSize)})`
})
}
const now = new Date()
const year = String(now.getFullYear())
const month = String(now.getMonth() + 1).padStart(2, '0')