edit errors message

This commit is contained in:
smanylov
2025-12-25 17:24:59 +07:00
parent e82d96a44c
commit 49088e5e5f
5 changed files with 57 additions and 22 deletions
-1
View File
@@ -66,7 +66,6 @@ export async function fileUpload(messageBody: initMessageBody) {
export async function cancelUpload(udloadId: string) { export async function cancelUpload(udloadId: string) {
try { try {
console.log('cancelUpload start');
const response = await fetch(`${API_BASE_URL}/api/v1/data`, { const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
+19 -19
View File
@@ -100,7 +100,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
if (!extension || !ALLOWED_EXTENSIONS.includes(extension as string)) { if (!extension || !ALLOWED_EXTENSIONS.includes(extension as string)) {
return { return {
isValid: false, isValid: false,
errorMessage: 'Неподдерживаемый формат файла.' errorMessage: t('unsupported-file-format')
}; };
} }
} }
@@ -110,7 +110,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
if (file.size > MAX_SIZE) { if (file.size > MAX_SIZE) {
return { return {
isValid: false, isValid: false,
errorMessage: 'Файл слишком большой. Максимальный размер: 1000MB' errorMessage: t('the-file-is-too-large')
}; };
} }
@@ -133,7 +133,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
img.onerror = () => { img.onerror = () => {
URL.revokeObjectURL(objectUrl); URL.revokeObjectURL(objectUrl);
reject(new Error('Не удалось загрузить фаил')); reject(new Error(t('error-uploading-file')));
}; };
img.src = objectUrl; img.src = objectUrl;
@@ -151,7 +151,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
const validation = validateFile(file); const validation = validateFile(file);
if (!validation.isValid) { if (!validation.isValid) {
setError(validation.errorMessage || 'Неизвестная ошибка валидации'); setError(validation.errorMessage || t('unknown-validation-error'));
return; return;
} }
@@ -163,7 +163,7 @@ 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 < 150 || dimensions.height < 150 || if (dimensions.width < 150 || dimensions.height < 150 ||
dimensions.width > 10000 || dimensions.height > 10000) { dimensions.width > 10000 || dimensions.height > 10000) {
setError(`Размер изображения: ${dimensions.width}x${dimensions.height}. Допустимый диапазон: 150x150 - 10000x10000 пикселей.`); setError(`${t('image-size')}: ${dimensions.width}x${dimensions.height}. ${t('acceptable-range')}: 150x150 - 10000x10000 ${t('pixels')}.`);
return; return;
} }
@@ -188,7 +188,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
}); });
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : 'Ошибка при обработке файла'); setError(t('error-processing-file'));
} }
}, []); }, []);
@@ -276,7 +276,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
const chunkResponse = await chunkUpload(formData); const chunkResponse = await chunkUpload(formData);
if (chunkResponse.message_desc !== 'Chunk uploaded successfully') { if (chunkResponse.message_desc !== 'Chunk uploaded successfully') {
throw 'Er1' throw 'Er1: response error'
} }
if (chunkIndex === totalChunks - 1) { if (chunkIndex === totalChunks - 1) {
@@ -285,7 +285,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
setUploadId(null); setUploadId(null);
setIsFileUploaded(true); setIsFileUploaded(true);
} else { } else {
throw 'Er2' throw 'Er2: not all chunks was uploaded'
} }
} }
@@ -298,12 +298,12 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
); );
} }
} catch (error) { } catch (error) {
setError('Chunk uploaded error ' + error); setError(t('error-uploading-file'));
console.error('Chunk upload error:', error); console.error('Chunk upload error:', error);
} }
} else { } else {
console.log(response); console.error(response);
setError('file uploaded error'); setError(t('error-uploading-file'));
} }
} }
@@ -391,14 +391,14 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{fileType === "image" && ( {fileType === "image" && (
<p className="description"> <p className="description">
Разрешение изображение: 100x100 - 10000x10000 {t('image-resolution')}: 100x100 - 10000x10000
</p> </p>
)} )}
<p className="description"> <p className="description">
Размер файла: до {(maxFileSize / 1024 / 1024)} МБ {t('file-size')}: {t('to')} {(maxFileSize / 1024 / 1024)} {t('mb')}
</p> </p>
<p className="description"> <p className="description">
Формат файла: {ALLOWED_EXTENSIONS.join(', ')} {t('file-format')}: {ALLOWED_EXTENSIONS.join(', ')}
</p> </p>
{error && ( {error && (
@@ -409,7 +409,7 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{selectedFile && ( {selectedFile && (
<div <div
className="selected-file" className={`selected-file ${isFileUploaded ? 'done' : ''}`}
> >
<div className="selected-file-file-info"> <div className="selected-file-file-info">
<div> <div>
@@ -424,10 +424,10 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
</span> {selectedFile.size} </span> {selectedFile.size}
</p> </p>
<p className="text-gray-700"> <p className="text-gray-700">
<span className="font-medium">Стоимость защиты:</span> 0 <span className="font-medium">{t('cost-of-protection')}:</span> 0
</p> </p>
<p className="text-gray-700"> <p className="text-gray-700">
<span className="font-medium">Текущий баланс:</span> 0 <span className="font-medium">{t('current-balance')}:</span> 0
</p> </p>
</div> </div>
<div> <div>
@@ -457,12 +457,12 @@ export default function UploadSectionFile({ fileType, allowedExtensions, maxFile
{isFileUploaded ? t('close') : t('cancel')} {isFileUploaded ? t('close') : t('cancel')}
</button> </button>
<button <button
className={`btn btn-confirm ${error ? 'disabled' : ''}`} className={`btn btn-confirm ${error || isFileUploaded ? 'disabled' : ''}`}
onClick={() => { onClick={() => {
handlerFileUpload(selectedFile); handlerFileUpload(selectedFile);
}} }}
type="button" type="button"
disabled={error ? true : false} disabled={error || isFileUploaded ? true : false}
> >
{t('upload-file')} {t('upload-file')}
</button> </button>
+6
View File
@@ -489,6 +489,12 @@
border-radius: 15px; border-radius: 15px;
background: #fff; background: #fff;
padding: 10px; padding: 10px;
border: 2px solid transparent;
transition: all 0.3s ease-in;
&.done {
border-color: #00a63e;
}
&-file-info { &-file-info {
text-align: left; text-align: left;
+16 -1
View File
@@ -129,7 +129,22 @@
"upload-for-protection": "Upload {fileType} for protection", "upload-for-protection": "Upload {fileType} for protection",
"image": "image", "image": "image",
"file-has-no-extension": "File has no extension", "file-has-no-extension": "File has no extension",
"have-unsaved-changes": "You have unsaved changes. Are you sure you want to delete this page?" "have-unsaved-changes": "You have unsaved changes. Are you sure you want to delete this page?",
"image-size": "Image size",
"acceptable-range": "Acceptable range",
"pixels": "pixels",
"error-processing-file": "Error processing file",
"error-uploading-file": "Error uploading file",
"unknown-validation-error": "Unknown validation error",
"unsupported-file-format": "Unsupported file format.",
"the-file-is-too-large": "The file is too large",
"cost-of-protection": "Cost of protection",
"current-balance": "Current balance",
"image-resolution": "Image resolution",
"file-size": "File size",
"file-format": "File format",
"mb": "MB",
"to": "to"
}, },
"Login-register-form": { "Login-register-form": {
"and": "and", "and": "and",
+16 -1
View File
@@ -129,7 +129,22 @@
"upload-for-protection": "Загрузить {fileType} для защиты", "upload-for-protection": "Загрузить {fileType} для защиты",
"image": "изображений", "image": "изображений",
"file-has-no-extension": "Файл не имеет расширения", "file-has-no-extension": "Файл не имеет расширения",
"have-unsaved-changes": "У вас есть несохраненные изменения. Вы уверены, что хотите покинуть страницу?" "have-unsaved-changes": "У вас есть несохраненные изменения. Вы уверены, что хотите покинуть страницу?",
"image-size": "Размер изображения",
"acceptable-range": "Допустимый диапазон",
"pixels": "пикселей",
"error-processing-file": "Ошибка при обработке файла",
"error-uploading-file": "Ошибка при загрузке файла",
"unknown-validation-error": "Неизвестная ошибка валидации",
"unsupported-file-format": "Неподдерживаемый формат файла.",
"the-file-is-too-large": "Файл слишком большой",
"cost-of-protection": "Стоимость защиты",
"current-balance": "Текущий баланс",
"image-resolution": "Разрешение изображение",
"file-size": "Размер файла",
"file-format": "Формат файла",
"mb": "МБ",
"to": "до"
}, },
"Login-register-form": { "Login-register-form": {
"and": "и", "and": "и",