Add file upload enabled check and new i18n message (#28946)

This commit is contained in:
Gen Sato 2025-12-15 12:18:05 +09:00 committed by GitHub
parent 63624dece1
commit 7fead6a9da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 16 deletions

View File

@ -246,6 +246,11 @@ export const useFile = (fileConfig: FileUpload) => {
}, [fileStore]) }, [fileStore])
const handleLocalFileUpload = useCallback((file: File) => { const handleLocalFileUpload = useCallback((file: File) => {
// Check file upload enabled
if (!fileConfig.enabled) {
notify({ type: 'error', message: t('common.fileUploader.uploadDisabled') })
return
}
if (!isAllowedFileExtension(file.name, file.type, fileConfig.allowed_file_types || [], fileConfig.allowed_file_extensions || [])) { if (!isAllowedFileExtension(file.name, file.type, fileConfig.allowed_file_types || [], fileConfig.allowed_file_extensions || [])) {
notify({ type: 'error', message: `${t('common.fileUploader.fileExtensionNotSupport')} ${file.type}` }) notify({ type: 'error', message: `${t('common.fileUploader.fileExtensionNotSupport')} ${file.type}` })
return return
@ -298,30 +303,16 @@ export const useFile = (fileConfig: FileUpload) => {
false, false,
) )
reader.readAsDataURL(file) reader.readAsDataURL(file)
}, [checkSizeLimit, notify, t, handleAddFile, handleUpdateFile, params.token, fileConfig?.allowed_file_types, fileConfig?.allowed_file_extensions]) }, [checkSizeLimit, notify, t, handleAddFile, handleUpdateFile, params.token, fileConfig?.allowed_file_types, fileConfig?.allowed_file_extensions, fileConfig?.enabled])
const handleClipboardPasteFile = useCallback((e: ClipboardEvent<HTMLTextAreaElement>) => { const handleClipboardPasteFile = useCallback((e: ClipboardEvent<HTMLTextAreaElement>) => {
const file = e.clipboardData?.files[0] const file = e.clipboardData?.files[0]
const text = e.clipboardData?.getData('text/plain') const text = e.clipboardData?.getData('text/plain')
if (file && !text) { if (file && !text) {
e.preventDefault() e.preventDefault()
const allowedFileTypes = fileConfig.allowed_file_types || []
const fileType = getSupportFileType(file.name, file.type, allowedFileTypes?.includes(SupportUploadFileTypes.custom))
const isFileTypeAllowed = allowedFileTypes.includes(fileType)
// Check if file type is in allowed list
if (!isFileTypeAllowed || !fileConfig.enabled) {
notify({
type: 'error',
message: t('common.fileUploader.fileExtensionNotSupport'),
})
return
}
handleLocalFileUpload(file) handleLocalFileUpload(file)
} }
}, [handleLocalFileUpload, fileConfig, notify, t]) }, [handleLocalFileUpload])
const [isDragActive, setIsDragActive] = useState(false) const [isDragActive, setIsDragActive] = useState(false)
const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => { const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => {

View File

@ -743,6 +743,7 @@ const translation = {
pasteFileLinkInvalid: 'Invalid file link', pasteFileLinkInvalid: 'Invalid file link',
fileExtensionNotSupport: 'File extension not supported', fileExtensionNotSupport: 'File extension not supported',
fileExtensionBlocked: 'This file type is blocked for security reasons', fileExtensionBlocked: 'This file type is blocked for security reasons',
uploadDisabled: 'File upload is disabled',
}, },
tag: { tag: {
placeholder: 'All Tags', placeholder: 'All Tags',

View File

@ -747,6 +747,7 @@ const translation = {
uploadFromComputerReadError: 'ファイルの読み取りに失敗しました。もう一度やり直してください。', uploadFromComputerReadError: 'ファイルの読み取りに失敗しました。もう一度やり直してください。',
fileExtensionNotSupport: 'ファイル拡張子はサポートされていません', fileExtensionNotSupport: 'ファイル拡張子はサポートされていません',
pasteFileLinkInvalid: '無効なファイルリンク', pasteFileLinkInvalid: '無効なファイルリンク',
uploadDisabled: 'ファイルアップロードは無効です',
fileExtensionBlocked: 'このファイルタイプは、セキュリティ上の理由でブロックされています', fileExtensionBlocked: 'このファイルタイプは、セキュリティ上の理由でブロックされています',
}, },
license: { license: {