From 0182616050c7f5480b60fffb85b5241665bb167c Mon Sep 17 00:00:00 2001 From: smanylov Date: Mon, 13 Apr 2026 13:44:30 +0700 Subject: [PATCH] continue: change verification upload section for corret upload last file and mark last chank --- package.json | 2 +- src/app/actions/fileUpload.ts | 10 ++++-- .../component/verification-upload-section.tsx | 35 ++++++++++--------- .../ui/settings/personal-data-settings.tsx | 4 --- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 40d7cbf..8c87cf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "no-copy-frontend", - "version": "0.85.0", + "version": "0.86.0", "private": true, "scripts": { "dev": "next dev -p 2999", diff --git a/src/app/actions/fileUpload.ts b/src/app/actions/fileUpload.ts index e5b25d9..cedd28e 100644 --- a/src/app/actions/fileUpload.ts +++ b/src/app/actions/fileUpload.ts @@ -116,9 +116,14 @@ export type ChunkResponse = { fileId?: string }; -export async function chunkUpload(formData: FormData): Promise { +export async function chunkUpload(formData: FormData, itPrivate?: boolean): Promise { + 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; diff --git a/src/app/ui/settings/component/verification-upload-section.tsx b/src/app/ui/settings/component/verification-upload-section.tsx index fe5b8d0..f60132b 100644 --- a/src/app/ui/settings/component/verification-upload-section.tsx +++ b/src/app/ui/settings/component/verification-upload-section.tsx @@ -109,13 +109,14 @@ export default function VerificationUploadSection({ const handleFilesSelect = useCallback(async (files: File[]): Promise => { setError(null); + const MAX_FILES_COUNT = 3; const newFiles: SelectedFile[] = []; const selectedFileNames = new Set(selectedFiles.map(f => f.name)); const currentFileNames = new Set(); 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 => { + const uploadSingleFile = async (fileInfo: SelectedFile, uploadType: 'single' | 'multi', isLastFIle: boolean): Promise => { 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({
- { + {/* { file.status === 'pending' && (