Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (78 loc) · 2.55 KB
/
Copy pathindex.js
File metadata and controls
86 lines (78 loc) · 2.55 KB
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
let githubToken = null;
const fetchGitHubToken = async () => {
try {
const response = await fetch('https://certapi.loyah.dev/pac');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
githubToken = await response.text();
return githubToken;
} catch (error) {
console.error('Fetch error: ', error);
githubToken = null;
return null;
}
};
const getRevokedFileListFromGitHub = async () => {
console.log("Fetching revoked certs...");
const apiUrl = 'https://api.github.com/repos/loyahdev/certificates/contents/certs/revoked';
try {
const token = await fetchGitHubToken();
if (!token) return [];
const response = await fetch(apiUrl, {
headers: {
'Authorization': `Bearer ${token}`
}
});
const data = await response.json();
return data.map(file => ({
name: file.name,
download_url: file.download_url,
}));
} catch (error) {
console.error('Error fetching revoked certs:', error);
return [];
}
};
const getSignedFileListFromGitHub = async () => {
console.log("Fetching signed certs...");
const apiUrl = 'https://api.github.com/repos/loyahdev/certificates/contents/certs/signed';
try {
const token = await fetchGitHubToken();
if (!token) return [];
const response = await fetch(apiUrl, {
headers: {
'Authorization': `Bearer ${token}`
}
});
const data = await response.json();
return data.map(file => ({
name: file.name,
download_url: file.download_url,
}));
} catch (error) {
console.error('Error fetching signed certs:', error);
return [];
}
};
const getAllCertFileListFromGitHub = async () => {
try {
const [revokedFiles, signedFiles] = await Promise.all([
getRevokedFileListFromGitHub(),
getSignedFileListFromGitHub()
]);
return [...revokedFiles, ...signedFiles];
} catch (error) {
console.error('Error fetching all cert files:', error);
return [];
}
};
const getToken = async () => {
return await fetchGitHubToken();
};
(async () => {
console.log("Revoked Certs:", await getRevokedFileListFromGitHub());
console.log("Signed Certs:", await getSignedFileListFromGitHub());
console.log("All Certs:", await getAllCertFileListFromGitHub());
//console.log("Token:", await getToken());
})();