@@ -16,6 +16,7 @@ import { getAllCardsAndModels, getAllCardsLegacy, getDatabaseTablesAndModelsWith
1616import { fetchDatabaseFields } from '../../../apps/src/metabase/helpers/metabaseAPI' ;
1717import { getSelectedDbId } from '../../../apps/src/metabase/helpers/metabaseStateAPI' ;
1818import { getModelsWithFields } from '../../../apps/src/metabase/helpers/metabaseModels' ;
19+ import { sha256 } from 'js-sha256' ;
1920
2021export interface MetadataItem {
2122 metadata_type : string ;
@@ -58,14 +59,26 @@ export async function processMetadata(metadataItems: MetadataItem[]): Promise<an
5859/**
5960 * Calculates metadata hash for caching purposes (simplified & faster)
6061 */
62+
63+ function calculateMetadataHashFallback ( content : string ) {
64+ return sha256 ( content ) ; // `sha256` is globally available
65+ }
66+
6167async function calculateMetadataHash ( metadataType : string , metadataValue : any , version : string ) : Promise < string > {
6268 // Simplified hash calculation - just hash the stringified data
6369 const content = JSON . stringify ( { metadataType, version, metadataValue } ) ;
64- const data = new TextEncoder ( ) . encode ( content ) ;
65- const hashBuffer = await crypto . subtle . digest ( 'SHA-256' , data ) ;
70+ try {
71+ const data = new TextEncoder ( ) . encode ( content ) ;
72+ const hashBuffer = await crypto . subtle . digest ( 'SHA-256' , data ) ;
6673
67- return Array . from ( new Uint8Array ( hashBuffer ) )
68- . map ( b => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
74+ return Array . from ( new Uint8Array ( hashBuffer ) )
75+ . map ( b => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
76+ } catch ( error ) {
77+ console . warn ( 'Failed to calculate metadata hash using crypto API, falling back:' , error ) ;
78+ // Fallback to a simpler hash calculation
79+ return calculateMetadataHashFallback ( content ) ;
80+ }
81+
6982}
7083
7184// Global map to track ongoing uploads by hash
0 commit comments