Skip to content

Commit

Permalink
test update asic model check
Browse files Browse the repository at this point in the history
  • Loading branch information
WantClue committed Sep 8, 2024
1 parent 1e508f2 commit 64ebeac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { FileUploadHandlerEvent } from 'primeng/fileupload';
import { map, Observable, shareReplay, startWith } from 'rxjs';
import { map, Observable, shareReplay, startWith, switchMap } from 'rxjs';
import { GithubUpdateService } from 'src/app/services/github-update.service';
import { LoadingService } from 'src/app/services/loading.service';
import { SystemService } from 'src/app/services/system.service';
Expand Down Expand Up @@ -44,12 +44,17 @@ export class SettingsComponent {

window.addEventListener('resize', this.checkDevTools);
this.checkDevTools();

this.latestRelease$ = this.githubUpdateService.getReleases().pipe(map(releases => {
return releases[0];
}));

this.info$ = this.systemService.getInfo().pipe(shareReplay({refCount: true, bufferSize: 1}))

this.latestRelease$ = this.info$.pipe(
switchMap(info => {
return this.githubUpdateService.getReleases(info.ASICModel).pipe(
map(releases => releases[0])
);
})
);




this.info$.pipe(this.loadingService.lockUIUntilComplete())
Expand Down
34 changes: 24 additions & 10 deletions main/http_server/axe-os/src/app/services/github-update.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { Observable, from } from 'rxjs';
import { map, mergeMap, toArray } from 'rxjs/operators';
import { eASICModel } from 'src/models/enum/eASICModel';

interface GithubRelease {
id: number;
Expand All @@ -11,22 +11,36 @@ interface GithubRelease {
prerelease: boolean;
}

interface ASICModelConfig {
supported_asic_models: eASICModel[];
}

@Injectable({
providedIn: 'root'
})
export class GithubUpdateService {

constructor(
private httpClient: HttpClient
) { }

) {}

public getReleases(): Observable<GithubRelease[]> {
public getReleases(currentASICModel: eASICModel): Observable<GithubRelease[]> {
return this.httpClient.get<GithubRelease[]>(
'https://api.github.com/repos/skot/esp-miner/releases'
'https://api.github.com/repos/wantclue/esp-miner-wantclue/releases'
).pipe(
map((releases: GithubRelease[]) => releases.filter((release: GithubRelease) => !release.prerelease))
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)
)
);
}

}

0 comments on commit 64ebeac

Please sign in to comment.