Skip to content

Commit

Permalink
update working now
Browse files Browse the repository at this point in the history
  • Loading branch information
WantClue committed Sep 8, 2024
1 parent 64ebeac commit 0959629
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 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, switchMap } from 'rxjs';
import { map, Observable, shareReplay, startWith, switchMap, of } 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 @@ -45,12 +45,16 @@ export class SettingsComponent {
window.addEventListener('resize', this.checkDevTools);
this.checkDevTools();
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.latestRelease$ = of(null).pipe(
switchMap(() => {
if (this.ASICModel) {
return this.githubUpdateService.getReleases(this.ASICModel).pipe(
map(releases => releases[0])
);
} else {
return of(null);
}
})
);

Expand Down
53 changes: 32 additions & 21 deletions main/http_server/axe-os/src/app/services/github-update.service.ts
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 [];
}
}

0 comments on commit 0959629

Please sign in to comment.