Merge pull request #643 from UnownPlain/checksums

Fetch checksums from digest field
This commit is contained in:
mr. m 2025-05-31 21:45:09 +02:00 committed by GitHub
commit a3e1ca70e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,8 +1,13 @@
import { CONSTANT } from '~/constants'
type GitHubAsset = {
name: string
digest: string
}
/**
* Fetches the latest release notes from GitHub and parses the SHA-256 checksums.
* Returns a mapping from filename to checksum.
* Fetches the latest release assets from GitHub and extracts their checksums.
* Returns a mapping from asset name to digest.
*/
export async function getChecksums() {
if (import.meta.env.DEV) {
@ -17,16 +22,11 @@ export async function getChecksums() {
})
if (!res.ok) throw new Error(`Failed to fetch GitHub release: ${res.statusText}`)
const data = await res.json()
const body = data.body as string
const assets = data.assets as GitHubAsset[]
// 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
}
for (const asset of assets) {
checksums[asset.name] = asset.digest
}
return checksums
}