@@ -181,7 +181,8 @@ <h3>Download</h3>
181181 {% if download_url %}
182182 < p >
183183 To download original image files in your browser, you can
184- < a class ="downld-link " target ="_blank " href ="{{ download_url }} "> access original data</ a > .
184+ <!-- NB: This URL is updated dynamically by JavaScript below, using download_urls.tsv -->
185+ < a id ="download_url " target ="_blank " href ="{{ download_url }} "> access original data</ a > .
185186 </ p >
186187 {% endif %}
187188
@@ -224,14 +225,17 @@ <h3>Download</h3>
224225</ div >
225226
226227< script >
228+
229+ const BASE_URL = "{{ base_url }}" ;
230+ const IDR_ID = "{{ idr_id }}" ;
231+ const MAX_IMAGES = 1000000 ;
232+ const SLOW_WARNING_THRESHOLD = 100000 ;
233+ let url = BASE_URL + "searchengine/api/v1/resources/container_images/?data_source=idr" ;
234+ let fmt = new Intl . NumberFormat ( ) ;
235+
227236 document . addEventListener ( "DOMContentLoaded" , function ( ) {
228237 // load image counts...
229238 // https://idr.openmicroscopy.org/searchengine//api/v1/resources/container_images/?data_source=idr
230- const BASE_URL = "{{ base_url }}" ;
231- const MAX_IMAGES = 1000000 ;
232- const SLOW_WARNING_THRESHOLD = 100000 ;
233- let url = BASE_URL + "searchengine/api/v1/resources/container_images/?data_source=idr" ;
234- let fmt = new Intl . NumberFormat ( ) ;
235239
236240 // for each table-download-link (csv download link OR hidden parquet link), HEAD request to get content-length...
237241 // Then add size in MB after link
@@ -255,6 +259,7 @@ <h3>Download</h3>
255259 } ) ;
256260 } ) ;
257261
262+ // Load image counts for each container from searchengine and add to page
258263 fetch ( url )
259264 . then ( response => response . json ( ) )
260265 . then ( data => {
@@ -312,6 +317,35 @@ <h3>Download</h3>
312317 . catch ( error => {
313318 console . error ( 'Error fetching image counts:' , error ) ;
314319 } ) ;
315- } ) ;
320+
321+ // Load download URLs from TSV file in GitHub...
322+ fetch ( 'https://raw.githubusercontent.com/will-moore/idr.openmicroscopy.org/refs/heads/download_urls/_data/download_urls.tsv' )
323+ . then ( response => response . text ( ) )
324+ . then ( data => {
325+ const lines = data . split ( '\n' ) ;
326+
327+ // Use first line as header to find column names...
328+ const headers = lines [ 0 ] . split ( '\t' ) ;
329+
330+ const idrIndex = headers . indexOf ( "idrid" ) ;
331+
332+ // Find the line for this IDR ID
333+ const studyLine = lines . find ( line => line . split ( '\t' ) [ idrIndex ] === IDR_ID ) ;
334+ if ( studyLine ) {
335+ const cells = studyLine . split ( '\t' ) ;
336+ const downloadUrlIndex = headers . indexOf ( "download_url" ) ;
337+ const downloadUrl = cells [ downloadUrlIndex ] ;
338+ if ( downloadUrl ) {
339+ const downloadLink = document . getElementById ( "download_url" ) ;
340+ if ( downloadLink ) {
341+ downloadLink . href = downloadUrl ;
342+ }
343+ }
344+ } else {
345+ console . warn ( `No download URL found for ${ IDR_ID } in TSV file` ) ;
346+ }
347+ } ) ;
348+ } ) ;
349+
316350</ script >
317351{% endblock %}
0 commit comments