Skip to content

Commit

Permalink
fix: Leverage curseforge hash to make sure the file is correctly down…
Browse files Browse the repository at this point in the history
…loaded
  • Loading branch information
ci010 committed Mar 29, 2024
1 parent eb5eb6d commit ac00ab5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions xmcl-runtime/curseforge/CurseForgeService.ts
Expand Up @@ -55,9 +55,19 @@ export class CurseForgeService extends AbstractService implements ICurseForgeSer
if (resource && resource.storedPath && existsSync(resource.storedPath)) {
this.log(`The curseforge file ${file.displayName}(${file.downloadUrl}) existed in cache!`)
} else {
const getHash = () => {
const hash = (file.hashes || [])[0]
if (hash) {
const algo = hash.algo === 1 ? 'sha1' : hash.algo === 2 ? 'md5' : undefined
if (algo) {
return { algorithm: algo, hash: hash.value }
}
}
}
const task = new DownloadTask({
...downloadOptions,
url: downloadUrls,
validator: getHash(),
destination,
}).setName('installCurseforgeFile', { modId: file.modId, fileId: file.id })
await this.submit(task)
Expand Down

0 comments on commit ac00ab5

Please sign in to comment.