-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 32 additions & 21 deletions
53
main/http_server/axe-os/src/app/services/github-update.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,57 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, from } from 'rxjs'; | ||
import { map, mergeMap, toArray } from 'rxjs/operators'; | ||
import { Observable } from 'rxjs'; | ||
import { map, tap } from 'rxjs/operators'; | ||
import { eASICModel } from 'src/models/enum/eASICModel'; | ||
|
||
interface GithubRelease { | ||
id: number; | ||
tag_name: string; | ||
name: string; | ||
body: string; | ||
prerelease: boolean; | ||
} | ||
|
||
interface ASICModelConfig { | ||
supported_asic_models: eASICModel[]; | ||
supported_asic_models: string[]; | ||
} | ||
|
||
interface ReleaseWithConfig { | ||
release: GithubRelease; | ||
supported_asic_models: string[]; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class GithubUpdateService { | ||
constructor( | ||
private httpClient: HttpClient | ||
) {} | ||
constructor(private httpClient: HttpClient) {} | ||
|
||
public getReleases(currentASICModel: eASICModel): Observable<GithubRelease[]> { | ||
console.log('Fetching releases for ASIC model:', currentASICModel); | ||
return this.httpClient.get<GithubRelease[]>( | ||
'https://api.github.com/repos/wantclue/esp-miner-wantclue/releases' | ||
'https://api.github.com/repos/WantClue/ESP-Miner-WantClue/releases' | ||
).pipe( | ||
mergeMap((releases: GithubRelease[]) => from(releases)), | ||
mergeMap((release: GithubRelease) => | ||
this.httpClient.get<ASICModelConfig>( | ||
`https://raw.githubusercontent.com/wantclue/esp-miner-wantclue/${release.tag_name}/asic_models.json` | ||
).pipe( | ||
map(config => ({ release, supported_asic_models: config.supported_asic_models })) | ||
) | ||
), | ||
toArray(), | ||
map((releasesWithConfig) => | ||
releasesWithConfig.filter(({ release, supported_asic_models }) => | ||
!release.prerelease && supported_asic_models.includes(currentASICModel) | ||
).map(({ release }) => release) | ||
) | ||
tap(releases => console.log('Fetched releases:', releases)), | ||
map(releases => releases.map(release => { | ||
const supportedModels = this.parseSupportedModels(release.body); | ||
console.log(`Release ${release.tag_name} supported models:`, supportedModels); | ||
return { ...release, supportedModels }; | ||
})), | ||
map(releases => releases.filter(release => { | ||
const isCompatible = !release.prerelease && release.supportedModels.includes(eASICModel[currentASICModel]); | ||
console.log(`Release ${release.tag_name} compatible: ${isCompatible}`); | ||
return isCompatible; | ||
})), | ||
tap(compatibleReleases => console.log('Compatible releases:', compatibleReleases)) | ||
); | ||
} | ||
|
||
private parseSupportedModels(description: string): string[] { | ||
const match = description.match(/supports the following ASIC models: ([\w, ]+)/); | ||
if (match && match[1]) { | ||
return match[1].split(', ').map(model => model.trim()); | ||
} | ||
return []; | ||
} | ||
} |