|
| 1 | +{% extends "idr_gallery/base.html" %} |
| 2 | + |
| 3 | +{% block content %} |
| 4 | + |
| 5 | + |
| 6 | +<style> |
| 7 | + body { |
| 8 | + background-color: #f6f6f9; |
| 9 | + } |
| 10 | + |
| 11 | + table { |
| 12 | + width: 100%; |
| 13 | + border-collapse: collapse; |
| 14 | + font-size: 12px; |
| 15 | + } |
| 16 | + |
| 17 | +</style> |
| 18 | + |
| 19 | +<h1>Download URLs</h1> |
| 20 | + |
| 21 | +<div id="table-container"> |
| 22 | + <p>Loading download URLs...</p> |
| 23 | +</div> |
| 24 | + |
| 25 | +<script> |
| 26 | + |
| 27 | + async function checkLinks() { |
| 28 | + let links = Array.from(document.querySelectorAll('a')); |
| 29 | + // links = links.slice(0,50) |
| 30 | + for (let link of links) { |
| 31 | + // links.forEach(async link => { |
| 32 | + // ignore image viewer links |
| 33 | + if (!link.href || link.href.includes("img_detail")) { |
| 34 | + continue; |
| 35 | + }; |
| 36 | + // no cors-origin check for now, just check if the link is valid |
| 37 | + let ok = await fetch(link.href, { method: 'HEAD'}) |
| 38 | + .then(response => { |
| 39 | + link.style.color = response.ok ? 'green' : 'orange'; |
| 40 | + link.title = response.ok ? 'Link is valid' : 'Link is broken'; |
| 41 | + return true; |
| 42 | + }) |
| 43 | + .catch(error => { |
| 44 | + console.error('Error checking link:', error); |
| 45 | + return false; |
| 46 | + }); |
| 47 | + if (!ok) { |
| 48 | + // show "pink" and re-try with server-side check, to avoid CORS issues |
| 49 | + link.style.color = 'pink'; |
| 50 | + link.title = 'Error checking link'; |
| 51 | + |
| 52 | + await fetch(`/link_check/?url=${encodeURIComponent(link.href)}`) |
| 53 | + .then(res => res.json()) |
| 54 | + .then(data => { |
| 55 | + if (data.is_valid) { |
| 56 | + link.style.color = 'green'; |
| 57 | + link.title = 'Link is valid (checked with server)'; |
| 58 | + } else { |
| 59 | + link.style.color = 'red'; |
| 60 | + link.title = `Link is broken: ${data.error}`; |
| 61 | + } |
| 62 | + }); |
| 63 | + } |
| 64 | + }; |
| 65 | + } |
| 66 | + |
| 67 | + // Fetch the TSV file and display it in a table |
| 68 | + fetch('https://raw.githubusercontent.com/IDR/idr.openmicroscopy.org/refs/heads/master/_data/download_urls.tsv') |
| 69 | + .then(response => response.text()) |
| 70 | + .then(data => { |
| 71 | + const lines = data.split('\n'); |
| 72 | + const table = document.createElement('table'); |
| 73 | + table.style.width = '100%'; |
| 74 | + table.style.borderCollapse = 'collapse'; |
| 75 | + |
| 76 | + // Create table header |
| 77 | + const header = table.createTHead(); |
| 78 | + const headerRow = header.insertRow(); |
| 79 | + const headers = lines[0].split('\t'); |
| 80 | + headers.forEach(headerText => { |
| 81 | + const th = document.createElement('th'); |
| 82 | + th.textContent = headerText; |
| 83 | + th.style.border = '1px solid #ddd'; |
| 84 | + th.style.padding = '2px'; |
| 85 | + th.style.backgroundColor = '#f2f2f2'; |
| 86 | + headerRow.appendChild(th); |
| 87 | + }); |
| 88 | + |
| 89 | + let clientPathIndex = headers.indexOf('client_path'); |
| 90 | + let downloadUrlIndex = headers.indexOf('download_url'); |
| 91 | + let idrIdIndex = headers.indexOf('idrid'); |
| 92 | + let imageIdIndex = headers.indexOf('image_id'); |
| 93 | + let dataLocationIndex = headers.indexOf('data_location'); |
| 94 | + |
| 95 | + // Create table body - update client_path to URL, based on the download_url column... |
| 96 | + const tbody = table.createTBody(); |
| 97 | + lines.slice(1).forEach(line => { |
| 98 | + if (line.trim() === '') return; // Skip empty lines |
| 99 | + const row = tbody.insertRow(); |
| 100 | + const cells = line.split('\t'); |
| 101 | + |
| 102 | + let idrId = cells[idrIdIndex]; |
| 103 | + let clientPath = cells[clientPathIndex]; |
| 104 | + let downloadUrl = cells[downloadUrlIndex]; |
| 105 | + let dataLocation = cells[dataLocationIndex]; |
| 106 | + let clientPathUrl; |
| 107 | + if (dataLocation == "Github") { |
| 108 | + let branch = "main"; |
| 109 | + // e.g. data/idr-metadata/idr0106-kubota-lunglightsheet/experimentA/companions/Mosaic_Image.companion.ome |
| 110 | + // links to https://github.com/IDR/idr0106-kubota-lunglightsheet/blob/main/experimentA/companions/Mosaic_Image.companion.ome |
| 111 | + // uod/idr/metadata/idr0052-walther-condensinmap/experimentA/companions/160719_NCAPD2gfpc272c78_MitoSys2/conc/cell0005_R0001.companion.ome |
| 112 | + // links to https://github.com/IDR/idr0052-walther-condensinmap/blob/master/experimentA/companions/160719_NCAPD2gfpc272c78_MitoSys2/conc/cell0005_R0001.companion.ome |
| 113 | + // uod/idr/metadata/idr0079-hartmann-lateralline/companions/experimentA/056F63395C/056F63395C.companion.ome |
| 114 | + // https://github.com/IDR/idr0079-hartmann-lateralline/blob/master/companions/experimentA/056F63395C/056F63395C.companion.ome |
| 115 | + let relativePath = clientPath.split("metadata/idr")[1]; |
| 116 | + let githubRepo = "idr" + relativePath.split("/")[0]; |
| 117 | + // some repos use "master" branch, so check for those... |
| 118 | + if ("idr0079,idr0052,idr0065,idr0075,idr0100".includes(githubRepo.split("-")[0])) { |
| 119 | + branch = "master"; |
| 120 | + } |
| 121 | + relativePath = relativePath.split("/").slice(1).join("/"); |
| 122 | + clientPathUrl = `https://github.com/IDR/${githubRepo}/blob/${branch}/${relativePath}`; |
| 123 | + |
| 124 | + } else if (downloadUrl.includes(idrId) && clientPath.includes(idrId)) { |
| 125 | + // e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0001-graml-sysgro |
| 126 | + let urlBase = downloadUrl.split(idrId)[0]; |
| 127 | + let urlPath = clientPath.split(idrId)[1]; |
| 128 | + clientPathUrl = urlBase + idrId + urlPath; |
| 129 | + } |
| 130 | + if (clientPathUrl) { |
| 131 | + // client_path needs patching for /idr0045-reichmann-zygotespindle/ |
| 132 | + clientPathUrl = clientPathUrl.replace("/idr0045-reichmann/", "/idr0045-reichmann-zygotespindle/"); |
| 133 | + } |
| 134 | + |
| 135 | + cells.forEach((cellText, colIndex) => { |
| 136 | + const td = document.createElement('td'); |
| 137 | + td.style.border = '1px solid #ddd'; |
| 138 | + td.style.padding = '2px'; |
| 139 | + // handle links or 'client_path' column... |
| 140 | + if (cellText.startsWith('http') || (headers[colIndex] === 'client_path' && clientPathUrl)) { |
| 141 | + const link = document.createElement('a'); |
| 142 | + // escape the URL to avoid issues with special characters in the client_path |
| 143 | + link.href = encodeURI(cellText.startsWith('http') ? cellText : clientPathUrl).replace("#", "%23"); |
| 144 | + // fix idr0045 as above |
| 145 | + cellText = cellText.replace("/idr0045-reichmann/", "/idr0045-reichmann-zygotespindle/"); |
| 146 | + link.textContent = cellText; |
| 147 | + link.target = '_blank'; |
| 148 | + td.textContent = ''; |
| 149 | + td.appendChild(link); |
| 150 | + } else if (colIndex == imageIdIndex) { |
| 151 | + // Add link to image viewer at /webclient/img_detail/1884807/ |
| 152 | + const link = document.createElement('a'); |
| 153 | + link.href = encodeURI(`/webclient/img_detail/${cellText}/?check_links=true`).replace("#", "%23"); |
| 154 | + link.textContent = cellText; |
| 155 | + link.target = '_blank'; |
| 156 | + td.textContent = ''; |
| 157 | + td.appendChild(link); |
| 158 | + } else { |
| 159 | + td.textContent = cellText; |
| 160 | + } |
| 161 | + row.appendChild(td); |
| 162 | + }); |
| 163 | + }); |
| 164 | + const tableContainer = document.getElementById('table-container'); |
| 165 | + tableContainer.innerHTML = ''; |
| 166 | + tableContainer.appendChild(table); |
| 167 | + |
| 168 | + checkLinks(); |
| 169 | + }) |
| 170 | + .catch(error => { |
| 171 | + console.error('Error fetching TSV file:', error); |
| 172 | + const tableContainer = document.getElementById('table-container'); |
| 173 | + tableContainer.innerHTML = '<p>Error loading download URLs.</p>'; |
| 174 | + }); |
| 175 | + |
| 176 | +</script> |
| 177 | + |
| 178 | +{% endblock %} |
0 commit comments