@@ -32,31 +32,49 @@ function updateMetaField(uuid, namespace, value) {
3232 Operation : "PUT" ,
3333 } ;
3434
35- Curate . api . fetchCurate ( url , "PUT" , metadatas ) ;
36- console . log ( `Attempted to update metadata '${ namespace } ' for UUID ${ uuid } ` ) ;
35+ Curate . api . fetchCurate ( url , "PUT" , metadatas )
36+ . then ( ( response ) => {
37+ console . log ( `updateMetaField: Successfully updated metadata for UUID: ${ uuid } ` , response ) ;
38+ } )
39+ . catch ( ( error ) => {
40+ console . error ( `updateMetaField: Failed to update metadata for UUID: ${ uuid } ` , error ) ;
41+ } ) ;
3742}
3843
3944function fetchCurateStats ( filePath , expectedChecksum , retryCount ) {
45+
46+
4047 Curate . api
4148 . fetchCurate ( "/a/tree/stats" , "POST" , {
4249 NodePaths : [ filePath ] ,
4350 } )
4451 . then ( ( data ) => {
52+
53+
4554 const node = data . Nodes . find ( ( node ) => node . Path === filePath ) ;
4655 if ( node ) {
56+
4757 // If node data is found, proceed to validate its checksum.
4858 validateChecksum ( node , expectedChecksum , filePath , retryCount ) ;
4959 } else {
5060 // Handle case where the specific node wasn't found in the API response.
51- // This might happen if path construction failed or the node doesn't exist.
52- console . error ( "Node not found in stats response:" , filePath ) ;
61+ console . error ( `❌ fetchCurateStats: Node not found in stats response for path: ${ filePath } ` ) ;
62+
5363 // Consider updating meta here to indicate a lookup failure if desired.
5464 }
5565 } )
5666 . catch ( ( error ) => {
5767 // Handle errors during the API call itself (network issues, server errors).
58- console . error ( "Error fetching node stats:" , error , filePath ) ;
59- // Consider retrying or updating meta based on the error type if desired.
68+ console . error ( `💥 fetchCurateStats: API error for ${ filePath } :` , error ) ;
69+
70+
71+ // Add retry logic for API failures
72+ if ( retryCount < 3 ) {
73+ console . log ( `🔄 fetchCurateStats: Retrying API call for ${ filePath } in 2 seconds...` ) ;
74+ setTimeout ( ( ) => {
75+ fetchCurateStats ( filePath , expectedChecksum , retryCount + 1 ) ;
76+ } , 2000 ) ;
77+ }
6078 } ) ;
6179}
6280
@@ -67,17 +85,14 @@ function validateChecksum(node, expectedChecksum, filePath, retryCount) {
6785 // The backend might return 'temporary' if its Etag calculation isn't finished.
6886 // Retry fetching stats a few times if this occurs.
6987 if ( node . Etag === "temporary" && retryCount < maxRetries ) {
70- console . log (
71- `Checksum temporary for ${ filePath } . Retrying (${
72- retryCount + 1
73- } /${ maxRetries } )...`
74- ) ;
88+
7589 setTimeout ( ( ) => {
7690 fetchCurateStats ( filePath , expectedChecksum , retryCount + 1 ) ;
7791 } , retryDelay ) ;
7892 } else if ( node . Etag === expectedChecksum ) {
7993 // Checksum matches the expected value.
80- console . log ( `Checksum validation passed for ${ filePath } .` ) ;
94+ console . log ( `✅ validateChecksum: Checksum validation PASSED for ${ filePath } !` ) ;
95+
8196 updateMetaField (
8297 node . Uuid ,
8398 "usermeta-file-integrity" , // Namespace for integrity status
@@ -86,13 +101,12 @@ function validateChecksum(node, expectedChecksum, filePath, retryCount) {
86101 } else {
87102 // Checksum mismatch, or max retries for 'temporary' reached.
88103 console . error (
89- `Checksum validation FAILED for ${ filePath } .` ,
90- "Expected:" ,
91- expectedChecksum ,
92- "Received:" ,
93- node . Etag ,
94- `(Attempt ${ retryCount + 1 } )`
104+ `❌ validateChecksum: Checksum validation FAILED for ${ filePath } !`
95105 ) ;
106+ console . error ( `❌ validateChecksum: Expected: ${ expectedChecksum } ` ) ;
107+ console . error ( `❌ validateChecksum: Received: ${ node . Etag } ` ) ;
108+ console . error ( `❌ validateChecksum: Attempt: ${ retryCount + 1 } ` ) ;
109+
96110 updateMetaField (
97111 node . Uuid ,
98112 "usermeta-file-integrity" ,
@@ -229,27 +243,32 @@ export default {
229243
230244 hooks : {
231245 onUploadComplete : async ( uploadItem ) => {
232- console . log ( 'ChecksumValidation: Processing upload completion for:' , uploadItem . _label ) ;
246+
233247
234248 try {
235249 // Generate checksum for the uploaded file
250+
236251 const finalChecksum = await generateChecksum ( uploadItem ) ;
252+
237253
238254 // Construct the file path for validation
239255 const filePath = constructFilePath ( uploadItem ) ;
240- console . log ( "Constructed final path for stats API:" , filePath ) ;
256+
241257
242258 // Introduce a small delay before fetching stats.
243259 // Delay scales slightly with file size but is capped.
244260 const delay = Math . min ( 5000 , Math . max ( 500 , uploadItem . _file . size * 0.01 ) ) ;
261+
262+
245263 setTimeout ( ( ) => {
264+
246265 // Initiate the checksum validation process using the final path.
247266 fetchCurateStats ( filePath , finalChecksum , 0 ) ;
248267 } , delay ) ;
249268
250269 } catch ( error ) {
251270 console . error (
252- "ChecksumValidation: Failed to process upload:" ,
271+ "❌ ChecksumValidation: Failed to process upload:" ,
253272 error ,
254273 "for file:" ,
255274 uploadItem . _label
0 commit comments