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