From 42f420253199d772dfef7da0890dc59b18989531 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:39:28 -0400 Subject: [PATCH] update --- src/splitter.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/splitter.html b/src/splitter.html index 3111f65..2019e28 100644 --- a/src/splitter.html +++ b/src/splitter.html @@ -111,7 +111,12 @@ const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); // Calculate the total number of chunks - const totalChunks = Math.ceil((text.length + `Hash: ${hashHex}\nMessage 1/1\n\n`.length) / maxChunkSize); + const initialPrefix = `Hash: ${hashHex}\nMessage 1/1\n\n`; + const remainingLength = text.length - (maxChunkSize - initialPrefix.length); + const additionalChunks = Math.ceil(remainingLength / (maxChunkSize - 20)); + const totalChunks = 1 + additionalChunks; + + // Prepare the first chunk with hash and sequence const firstChunkPrefix = `Hash: ${hashHex}\nMessage 1/${totalChunks}\n\n`; const firstChunkContentSize = maxChunkSize - firstChunkPrefix.length; const firstChunk = firstChunkPrefix + text.substring(0, firstChunkContentSize); @@ -122,7 +127,7 @@ // Split the remaining text into chunks for (let i = firstChunkContentSize; i < text.length; i += (maxChunkSize - 20)) { let chunk = text.substring(i, i + (maxChunkSize - 20)); - let chunkNumber = Math.floor(i / (maxChunkSize - 20)) + 2; // Start from the second chunk + let chunkNumber = Math.floor((i - firstChunkContentSize) / (maxChunkSize - 20)) + 2; // Start from the second chunk let prefix = `Message ${chunkNumber}/${totalChunks}\n\n`; chunk = `${prefix}${chunk}`;