mirror of
https://github.com/zen-browser/www.git
synced 2025-07-08 17:30:01 +02:00
Fetch checksums from digest field
This commit is contained in:
parent
c52ab5171c
commit
b686a802f5
1 changed files with 10 additions and 10 deletions
|
@ -1,8 +1,13 @@
|
||||||
import { CONSTANT } from '~/constants'
|
import { CONSTANT } from '~/constants'
|
||||||
|
|
||||||
|
type GitHubAsset = {
|
||||||
|
name: string
|
||||||
|
digest: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the latest release notes from GitHub and parses the SHA-256 checksums.
|
* Fetches the latest release assets from GitHub and extracts their checksums.
|
||||||
* Returns a mapping from filename to checksum.
|
* Returns a mapping from asset name to digest.
|
||||||
*/
|
*/
|
||||||
export async function getChecksums() {
|
export async function getChecksums() {
|
||||||
if (import.meta.env.DEV) {
|
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}`)
|
if (!res.ok) throw new Error(`Failed to fetch GitHub release: ${res.statusText}`)
|
||||||
const data = await res.json()
|
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> = {}
|
const checksums: Record<string, string> = {}
|
||||||
if (match?.[1]) {
|
for (const asset of assets) {
|
||||||
for (const line of match[1].split('\n')) {
|
checksums[asset.name] = asset.digest
|
||||||
const [hash, filename] = line.trim().split(/\s+/, 2)
|
|
||||||
if (hash && filename) checksums[filename] = hash
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return checksums
|
return checksums
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue