@@ -113,29 +113,43 @@ download_wasm_files() {
113113 rm " /tmp/openmina-$OPENMINA_WASM_VERSION -webnode-wasm.tar.gz"
114114}
115115
116+ get_short_sha1 () {
117+ local file=" $1 "
118+ if [ -z " $file " ]; then
119+ echo " Usage: get_short_sha1 filename" >&2
120+ return 1
121+ fi
122+ if [ ! -f " $file " ]; then
123+ echo " Error: File not found: $file " >&2
124+ return 1
125+ fi
126+ openssl sha1 " $file " | awk ' { print substr($2,1,8) }'
127+ }
128+
116129inject_caching_logic () {
117130 local js_file=" $1 "
118131 local index_html=" $2 "
119132 if [ -f " $js_file " ]; then
120133 echo " Injecting caching logic into $js_file "
121134
122- # Generate a unique hash
123- local hash=$( openssl rand -hex 8)
135+ # Generate checksum hashes
136+ local js_file_hash=$( get_short_sha1 " $TARGET_DIR /openmina_node_web.js" )
137+ local wasm_file_hash=$( get_short_sha1 " $TARGET_DIR /openmina_node_web_bg.wasm" )
124138
125- # replace openmina_node_web_bg.wasm with openmina_node_web_bg.$hash .wasm
126- sed -i " s/openmina_node_web_bg.wasm/openmina_node_web_bg.$hash .wasm/g" " $js_file "
139+ # replace openmina_node_web_bg.wasm with openmina_node_web_bg.$wasm_file_hash .wasm
140+ sed -i " s/openmina_node_web_bg.wasm/openmina_node_web_bg.$wasm_file_hash .wasm/g" " $js_file "
127141
128142 # add cache headers to fetch calls
129143 sed -i ' s/module_or_path = fetch(module_or_path);/module_or_path = fetch(module_or_path, { cache: "force-cache", headers: { "Cache-Control": "max-age=31536000, immutable" } });/' " $js_file "
130144
131- # rename openmina_node_web_bg.wasm to openmina_node_web_bg.$hash .wasm
132- mv " $TARGET_DIR /openmina_node_web_bg.wasm" " $TARGET_DIR /openmina_node_web_bg.$hash .wasm"
145+ # rename openmina_node_web_bg.wasm to openmina_node_web_bg.$wasm_file_hash .wasm
146+ mv " $TARGET_DIR /openmina_node_web_bg.wasm" " $TARGET_DIR /openmina_node_web_bg.$wasm_file_hash .wasm"
133147
134- # rename openmina_node_web.js to openmina_node_web.$hash .js
135- mv " $TARGET_DIR /openmina_node_web.js" " $TARGET_DIR /openmina_node_web.$hash .js"
148+ # rename openmina_node_web.js to openmina_node_web.$js_file_hash .js
149+ mv " $TARGET_DIR /openmina_node_web.js" " $TARGET_DIR /openmina_node_web.$js_file_hash .js"
136150
137- # replace openmina_node_web.js with openmina_node_web.$hash .js in index.html
138- sed -i " s/openmina_node_web.js/openmina_node_web.$hash .js/g" " $index_html "
151+ # replace openmina_node_web.js with openmina_node_web.$js_file_hash .js in index.html
152+ sed -i " s/openmina_node_web.js/openmina_node_web.$js_file_hash .js/g" " $index_html "
139153
140154 if [[ $? -ne 0 ]]; then
141155 echo " Failed to inject caching logic into $js_file "
0 commit comments