feat(checksum): add checksum support to download components and update workflow

- Enhanced ButtonCard component to accept and display SHA-256 checksums.
- Updated PlatformDownload and release-data to include checksum information for each release.
- Modified DownloadScript to apply twilight mode to new checksum buttons.
- Adjusted download page to retrieve and display checksums dynamically.
This commit is contained in:
taroj1205 2025-05-09 12:13:27 +12:00
parent 59974742e9
commit 3816206f6b
No known key found for this signature in database
GPG key ID: 0FCB6CFFE0981AB7
7 changed files with 234 additions and 76 deletions

View file

@ -0,0 +1,31 @@
/**
* Fetches the latest release notes from GitHub and parses the SHA-256 checksums.
* Returns a mapping from filename to checksum.
*/
export async function getChecksums() {
const token = import.meta.env.GITHUB_TOKEN;
if (!token) throw new Error('GITHUB_TOKEN is not set in environment variables');
const res = await fetch('https://api.github.com/repos/zen-browser/desktop/releases/latest', {
headers: {
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${token}`,
'X-GitHub-Api-Version': '2022-11-28',
'User-Agent': 'zen-browser-checksum-fetcher',
},
});
if (!res.ok) throw new Error('Failed to fetch GitHub release: ' + res.statusText);
const data = await res.json();
const body = data.body as string;
// Extract the checksum block
const match = body.match(/File Checksums \(SHA-256\)[\s\S]*?```([\s\S]*?)```/);
const checksums: Record<string, string> = {};
if (match && match[1]) {
match[1].split('\n').forEach(line => {
const [hash, filename] = line.trim().split(/\s+/, 2);
if (hash && filename) checksums[filename] = hash;
});
}
return checksums;
}