fix upload file bugs
This commit is contained in:
@@ -74,6 +74,11 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
||||
return { isValid: true };
|
||||
};
|
||||
|
||||
function setErrorHandler(message: string | null): void {
|
||||
setError(message);
|
||||
setUploadProgress(0);
|
||||
}
|
||||
|
||||
const getImageDimensions = (file: File): Promise<{ width: number; height: number }> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
@@ -120,11 +125,11 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
||||
dimensions = await getImageDimensions(file) as { width: number, height: number };
|
||||
if (dimensions.width < 100 || dimensions.height < 100 ||
|
||||
dimensions.width > 10000 || dimensions.height > 10000) {
|
||||
setError(`${t('image-size')}: ${dimensions.width}x${dimensions.height}. ${t('acceptable-range')}: 100x100 - 10000x10000 ${t('pixels')}.`);
|
||||
setErrorHandler(`${t('image-size')}: ${dimensions.width}x${dimensions.height}. ${t('acceptable-range')}: 100x100 - 10000x10000 ${t('pixels')}.`);
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
setError(t('error-reading-image'));
|
||||
setErrorHandler(t('error-reading-image'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -255,10 +260,9 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
||||
} catch (error) {
|
||||
if (!isCancelledRef.current) {
|
||||
if (error === 'duplicate-file') {
|
||||
setError(t('error-duplicate-file'));
|
||||
setErrorHandler(t('error-duplicate-file'));
|
||||
} else {
|
||||
setError(t('error-uploading-file'));
|
||||
console.error('Upload error:', error);
|
||||
setErrorHandler(t('error-uploading-file'));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -347,6 +351,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
||||
className="btn btn-primary"
|
||||
onClick={handleButtonClick}
|
||||
type="button"
|
||||
disabled={uploadProgress && uploadProgress !== 100 ? true : false}
|
||||
>
|
||||
{t('select-files-to-protect')}
|
||||
</button>
|
||||
@@ -394,7 +399,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
|
||||
src={selectedFile.preview}
|
||||
alt="Предпросмотр загруженного изображения"
|
||||
className="uploaded-image"
|
||||
onError={() => setError('Не удалось загрузить превью изображения')}
|
||||
onError={() => setErrorHandler('Не удалось загрузить превью изображения')}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -371,6 +371,11 @@
|
||||
background: v.$p-color;
|
||||
margin-bottom: 10px;
|
||||
margin-top: 20px;
|
||||
|
||||
&:disabled {
|
||||
background: linear-gradient(135deg, v.$p-color-disabled, v.$s-color-disabled);
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -297,6 +297,7 @@ export default function SectionSearchFile({ fileType, allowedExtensions, maxFile
|
||||
className="btn btn-primary"
|
||||
onClick={handleButtonClick}
|
||||
type="button"
|
||||
disabled={uploadProgress && uploadProgress !== 100 ? true : false}
|
||||
>
|
||||
Выбрать файл
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user