Skip to content

Commit f2f3e7e

Browse files
committed
download_urls table checks 1 link at a time
1 parent 4a7a2a7 commit f2f3e7e

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

idr_gallery/templates/idr_gallery/download_urls.html

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,46 @@ <h1>Download URLs</h1>
2424

2525
<script>
2626

27-
function checkLinks() {
27+
async function checkLinks() {
2828
let links = Array.from(document.querySelectorAll('a'));
2929
// links = links.slice(0,50)
30-
links.forEach(link => {
30+
for (let link of links) {
31+
console.log('Checking link:', link);
32+
// links.forEach(async link => {
3133
// ignore image viewer links
32-
if (!link.href || link.href.includes("img_detail")) return;
34+
if (!link.href || link.href.includes("img_detail")) {
35+
continue;
36+
};
3337
// no cors-origin check for now, just check if the link is valid
34-
fetch(link.href, { method: 'HEAD'})
38+
let ok = await fetch(link.href, { method: 'HEAD'})
3539
.then(response => {
3640
link.style.color = response.ok ? 'green' : 'orange';
3741
link.title = response.ok ? 'Link is valid' : 'Link is broken';
42+
return true;
3843
})
3944
.catch(error => {
40-
// show "pink" and re-try with server-side check, to avoid CORS issues
4145
console.error('Error checking link:', error);
42-
link.style.color = 'pink';
43-
link.title = 'Error checking link';
44-
45-
fetch(`/link_check/?url=${encodeURIComponent(link.href)}`)
46-
.then(res => res.json())
47-
.then(data => {
48-
console.log('Link check data:', data);
49-
if (data.is_valid) {
50-
link.style.color = 'green';
51-
link.title = 'Link is valid (checked with server)';
52-
} else {
53-
link.style.color = 'red';
54-
link.title = `Link is broken: ${data.error}`;
55-
}
56-
});
46+
return false;
5747
});
58-
});
48+
if (!ok) {
49+
// show "pink" and re-try with server-side check, to avoid CORS issues
50+
link.style.color = 'pink';
51+
link.title = 'Error checking link';
52+
53+
await fetch(`/link_check/?url=${encodeURIComponent(link.href)}`)
54+
.then(res => res.json())
55+
.then(data => {
56+
console.log('Link check data:', data);
57+
if (data.is_valid) {
58+
link.style.color = 'green';
59+
link.title = 'Link is valid (checked with server)';
60+
} else {
61+
link.style.color = 'red';
62+
link.title = `Link is broken: ${data.error}`;
63+
}
64+
});
65+
}
66+
};
5967
}
6068

6169
// Fetch the TSV file and display it in a table

0 commit comments

Comments
 (0)