www/src/utils/githubChecksums.ts
taroj1205 6a7bd311c0
feat(download): enhance download page with checksum integration and platform-specific releases
- Added a new `release-data.ts` file to manage release information with dynamic checksums.
- Introduced `CHECKSUMS` constant for easy access to file checksums.
- Updated `PlatformDownload.astro` to support additional release types and improved type safety.
- Enhanced the download page to correctly display platform-specific download links and checksums.
- Refactored tests to validate the new download functionality and checksum integration.
2025-05-16 12:30:14 +12:00

32 lines
1 KiB
TypeScript

import { CONSTANT } from '~/constants'
/**
* Fetches the latest release notes from GitHub and parses the SHA-256 checksums.
* Returns a mapping from filename to checksum.
*/
export async function getChecksums() {
if (import.meta.env.DEV) {
return CONSTANT.CHECKSUMS
}
const res = await fetch('https://api.github.com/repos/zen-browser/desktop/releases/latest', {
headers: {
Accept: 'application/vnd.github+json',
'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?.[1]) {
for (const line of match[1].split('\n')) {
const [hash, filename] = line.trim().split(/\s+/, 2)
if (hash && filename) checksums[filename] = hash
}
}
return checksums
}