-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
104 lines (88 loc) · 4.57 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html lang="fi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Finto-data statustaulu</title>
</head>
<style>
ul { list-style-type: none; }
</style>
<body>
<h1>Sanastojen statukset</h1>
<p><b>Selite:</b> Kaikki kunossa 🟢 | Kehitysversio ja julkaisuversio epäsynkassa 🟡 | Skosify on törmännyt ongelmaan 🔴</p>
<ul id="status-container"></ul>
<script>
const BASE_URL = 'https://raw.githubusercontent.com/NatLibFi/Finto-data/master/vocabularies/';
const API_URL = "https://api.github.com/repos/NatLibFi/Finto-data/commits";
async function getCommitDate(pathToFile) {
try {
const commitUrl = new URL("https://api.github.com/repos/NatLibFi/Finto-data/commits");
commitUrl.searchParams.set('page', '1');
commitUrl.searchParams.set('per_page', '1');
commitUrl.searchParams.set('path', pathToFile);
const response = await fetch(commitUrl.toString());
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
const lastCommitDate = data[0]?.commit?.committer?.date;
console.log(pathToFile + " : " + lastCommitDate);
return lastCommitDate || null;
} catch (error) {
console.error('Error fetching commit date:', error);
return null;
}
}
async function getLogFileContent(url) {
const response = await fetch(url);
return await response.text();
}
async function checkStatus(resource) {
const name = resource.name
const path = BASE_URL + '/' + name + '/';
const dev = 'vocabularies/' + name + '/' + resource.dev;
const skos = 'vocabularies/' + name + '/' + resource.skos;
const log = path + resource.log;
const [devDate, publishDate, logContent] = await Promise.all([
getCommitDate(dev),
getCommitDate(skos),
getLogFileContent(log)
]);
const daysDifference = (new Date(devDate).getTime() - new Date(publishDate).getTime()) / (1000 * 3600 * 24);
const hasError = logContent.toLowerCase().includes('CRITICAL: ');
const statusElement = document.createElement('li');
statusElement.className = 'status';
if (hasError) {
statusElement.classList.add('red');
statusElement.textContent += '\u{1f534} ';
} else if (daysDifference > 1) {
statusElement.classList.add('yellow');
statusElement.textContent += '\u{1f7e1} ';
} else {
statusElement.classList.add('green');
statusElement.textContent += '\u{1f7e2} ';
}
const span = document.createElement('span');
span.textContent = name.charAt(0).toUpperCase() + name.slice(1);
statusElement.appendChild(span);
return statusElement;
}
async function generateStatusContainer() {
const container = document.getElementById('status-container');
const resources = { 'finaf': { "name": "finaf", "dev": "skosify.log", "skos": "finaf-skos/finaf-skos142.ttl", "log": "skosify.log" },
'koko': { "name": "koko", "dev": "koko.ttl", "skos": "koko-skos.ttl", "log": "skosify.log" },
'metatietosanasto': { "name": "metatietosanasto", "dev": "metatietosanasto.rdf", "skos": "metatietosanasto-skos.ttl", "log": "skosify.log" },
'slm': { "name": "slm", "dev": "slm.ttl", "skos": "slm-skos.ttl", "log": "skosify.log" },
'yso-aika': { "name": "yso-aika", "dev": "yso-aika.rdf", "skos": "yso-aika-skos.ttl", "log": "skosify.log" },
'yso-paikat': { "name": "yso-paikat", "dev": "yso-paikat-vb-dump.rdf", "skos": "yso-paikat-skos.ttl", "log": "skosify.log" },
'yso': { "name": "yso", "dev": "ysoKehitys.rdf", "skos": "yso-skos.ttl", "log": "skosify.log" } };
for (const resource of Object.keys(resources)) {
const statusElement = await checkStatus(resources[resource]);
container.appendChild(statusElement);
}
}
generateStatusContainer();
</script>
</body>
</html>