continue: change verification upload section for corret upload last file and mark last chank

This commit is contained in:
smanylov
2026-04-13 13:44:30 +07:00
parent 8da7056cd6
commit 0182616050
4 changed files with 26 additions and 25 deletions
+7 -3
View File
@@ -116,9 +116,14 @@ export type ChunkResponse = {
fileId?: string
};
export async function chunkUpload(formData: FormData): Promise<ChunkResponse> {
export async function chunkUpload(formData: FormData, itPrivate?: boolean): Promise<ChunkResponse> {
console.log('chunkUpload');
try {
const response = await fetch(`${API_BASE_URL}/api/v1/files/chunk`, {
const url = itPrivate
? `${API_BASE_URL}/api/v1/private/files/chunk`
: `${API_BASE_URL}/api/v1/files/chunk`;
const response = await fetch(url, {
method: 'POST',
body: formData
});
@@ -254,7 +259,6 @@ export async function checkOperationPrice(action: string, filesCount: number, fi
if (response.ok) {
let parsed = await response.json();
console.log(parsed);
if (parsed.message_code === 0) {
return parsed.message_body;
@@ -109,13 +109,14 @@ export default function VerificationUploadSection({
const handleFilesSelect = useCallback(async (files: File[]): Promise<void> => {
setError(null);
const MAX_FILES_COUNT = 3;
const newFiles: SelectedFile[] = [];
const selectedFileNames = new Set(selectedFiles.map(f => f.name));
const currentFileNames = new Set<string>();
const duplicateNames: string[] = [];
if (selectedFiles.length + files.length > 4) {
if (selectedFiles.length + files.length > MAX_FILES_COUNT) {
setError('max-lenght');
return
}
@@ -242,7 +243,7 @@ export default function VerificationUploadSection({
setError(null);
};
const uploadSingleFile = async (fileInfo: SelectedFile, uploadType: 'single' | 'multi'): Promise<void> => {
const uploadSingleFile = async (fileInfo: SelectedFile, uploadType: 'single' | 'multi', isLastFIle: boolean): Promise<void> => {
const fileId = `${fileInfo.name}-${Date.now()}`;
isCancelledRef.current.set(fileId, false);
@@ -289,6 +290,7 @@ export default function VerificationUploadSection({
if (isCancelledRef.current.get(fileId)) {
return;
}
let isLastChank = (chunkIndex + 1) === totalChunks;
const start = chunkIndex * CHUNK_SIZE;
const end = Math.min(start + CHUNK_SIZE, fileInfo.file.size);
@@ -299,7 +301,11 @@ export default function VerificationUploadSection({
formData.append('chunk_number', chunkIndex.toString());
formData.append('chunk', chunk);
const chunkResponse = await chunkUpload(formData);
if (isLastFIle && isLastChank) {
formData.append('last_file', 'true');
}
const chunkResponse = await chunkUpload(formData, true);
if (chunkResponse.errorMesage !== null) {
throw chunkResponse.errorMesage;
@@ -352,20 +358,15 @@ export default function VerificationUploadSection({
const priceCheck = await checkOperationPrice('checkTokensForProtect', selectedFilesRef.current.length, fileType);
if (priceCheck.success) {
const uploadNextBatch = async () => {
const currentPending = selectedFilesRef.current.filter(f => f.status === 'pending');
const batch = currentPending.slice(0, maxParallelUploads);
const files = selectedFilesRef.current;
const totalFiles = files.length;
if (batch.length === 0) return;
for (let i = 0; i < totalFiles; i++) {
const file = files[i];
const isLastFile = i === totalFiles - 1;
await Promise.all(batch.map(file => uploadSingleFile(file, 'multi')));
if (selectedFilesRef.current.some(f => f.status === 'pending')) {
await uploadNextBatch();
}
};
await uploadNextBatch();
await uploadSingleFile(file, 'multi', isLastFile);
}
} else {
const errorMessage = `${t('there-are-not-enough-funds-to-protect-files', { count: priceCheck?.tokens_count })}`;
setError(errorMessage);
@@ -547,7 +548,7 @@ export default function VerificationUploadSection({
<div
className="selected-file-actions"
>
{
{/* {
file.status === 'pending' && (
<button
className="btn btn-confirm"
@@ -559,7 +560,7 @@ export default function VerificationUploadSection({
{t('start-upload')}
</button>
)
}
} */}
< button
className="btn btn-cancel"
@@ -16,10 +16,6 @@ export default function PersonalDataSettings() {
const { data: userData, isLoading, isError, error } = useUserProfile();
useEffect(() => {
console.log(userData)
}, [userData]);
const t = useTranslations('Global');
return (