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
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "no-copy-frontend", "name": "no-copy-frontend",
"version": "0.85.0", "version": "0.86.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 2999", "dev": "next dev -p 2999",
+7 -3
View File
@@ -116,9 +116,14 @@ export type ChunkResponse = {
fileId?: string fileId?: string
}; };
export async function chunkUpload(formData: FormData): Promise<ChunkResponse> { export async function chunkUpload(formData: FormData, itPrivate?: boolean): Promise<ChunkResponse> {
console.log('chunkUpload');
try { 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', method: 'POST',
body: formData body: formData
}); });
@@ -254,7 +259,6 @@ export async function checkOperationPrice(action: string, filesCount: number, fi
if (response.ok) { if (response.ok) {
let parsed = await response.json(); let parsed = await response.json();
console.log(parsed);
if (parsed.message_code === 0) { if (parsed.message_code === 0) {
return parsed.message_body; return parsed.message_body;
@@ -109,13 +109,14 @@ export default function VerificationUploadSection({
const handleFilesSelect = useCallback(async (files: File[]): Promise<void> => { const handleFilesSelect = useCallback(async (files: File[]): Promise<void> => {
setError(null); setError(null);
const MAX_FILES_COUNT = 3;
const newFiles: SelectedFile[] = []; const newFiles: SelectedFile[] = [];
const selectedFileNames = new Set(selectedFiles.map(f => f.name)); const selectedFileNames = new Set(selectedFiles.map(f => f.name));
const currentFileNames = new Set<string>(); const currentFileNames = new Set<string>();
const duplicateNames: string[] = []; const duplicateNames: string[] = [];
if (selectedFiles.length + files.length > 4) { if (selectedFiles.length + files.length > MAX_FILES_COUNT) {
setError('max-lenght'); setError('max-lenght');
return return
} }
@@ -242,7 +243,7 @@ export default function VerificationUploadSection({
setError(null); 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()}`; const fileId = `${fileInfo.name}-${Date.now()}`;
isCancelledRef.current.set(fileId, false); isCancelledRef.current.set(fileId, false);
@@ -289,6 +290,7 @@ export default function VerificationUploadSection({
if (isCancelledRef.current.get(fileId)) { if (isCancelledRef.current.get(fileId)) {
return; return;
} }
let isLastChank = (chunkIndex + 1) === totalChunks;
const start = chunkIndex * CHUNK_SIZE; const start = chunkIndex * CHUNK_SIZE;
const end = Math.min(start + CHUNK_SIZE, fileInfo.file.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_number', chunkIndex.toString());
formData.append('chunk', chunk); 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) { if (chunkResponse.errorMesage !== null) {
throw chunkResponse.errorMesage; throw chunkResponse.errorMesage;
@@ -352,20 +358,15 @@ export default function VerificationUploadSection({
const priceCheck = await checkOperationPrice('checkTokensForProtect', selectedFilesRef.current.length, fileType); const priceCheck = await checkOperationPrice('checkTokensForProtect', selectedFilesRef.current.length, fileType);
if (priceCheck.success) { if (priceCheck.success) {
const uploadNextBatch = async () => { const files = selectedFilesRef.current;
const currentPending = selectedFilesRef.current.filter(f => f.status === 'pending'); const totalFiles = files.length;
const batch = currentPending.slice(0, maxParallelUploads);
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'))); await uploadSingleFile(file, 'multi', isLastFile);
}
if (selectedFilesRef.current.some(f => f.status === 'pending')) {
await uploadNextBatch();
}
};
await uploadNextBatch();
} else { } else {
const errorMessage = `${t('there-are-not-enough-funds-to-protect-files', { count: priceCheck?.tokens_count })}`; const errorMessage = `${t('there-are-not-enough-funds-to-protect-files', { count: priceCheck?.tokens_count })}`;
setError(errorMessage); setError(errorMessage);
@@ -547,7 +548,7 @@ export default function VerificationUploadSection({
<div <div
className="selected-file-actions" className="selected-file-actions"
> >
{ {/* {
file.status === 'pending' && ( file.status === 'pending' && (
<button <button
className="btn btn-confirm" className="btn btn-confirm"
@@ -559,7 +560,7 @@ export default function VerificationUploadSection({
{t('start-upload')} {t('start-upload')}
</button> </button>
) )
} } */}
< button < button
className="btn btn-cancel" className="btn btn-cancel"
@@ -16,10 +16,6 @@ export default function PersonalDataSettings() {
const { data: userData, isLoading, isError, error } = useUserProfile(); const { data: userData, isLoading, isError, error } = useUserProfile();
useEffect(() => {
console.log(userData)
}, [userData]);
const t = useTranslations('Global'); const t = useTranslations('Global');
return ( return (