Return to the original TukUI api

Add support for the Hub checking for updates.
This commit is contained in:
jliddev
2020-12-11 14:52:05 -06:00
parent 5a6a26b0d8
commit 6e03e1b493
3 changed files with 50 additions and 40 deletions

View File

@@ -18,8 +18,8 @@ import { FileService } from "../services/files/file.service";
import { AddonProvider } from "./addon-provider";
import { AppConfig } from "../../environments/environment";
// const API_URL = "https://www.tukui.org/api.php";
// const CLIENT_API_URL = "https://www.tukui.org/client-api.php";
const API_URL = "https://www.tukui.org/api.php";
const CLIENT_API_URL = "https://www.tukui.org/client-api.php";
const WOWUP_API_URL = AppConfig.wowUpHubUrl;
export class TukUiAddonProvider implements AddonProvider {
@@ -37,7 +37,7 @@ export class TukUiAddonProvider implements AddonProvider {
private _electronService: ElectronService,
private _fileService: FileService
) {
this._circuitBreaker = new CircuitBreaker(this.fetchApiResultsWowUp, {
this._circuitBreaker = new CircuitBreaker(this.fetchApiResults, {
resetTimeout: 60000,
});
@@ -225,43 +225,39 @@ export class TukUiAddonProvider implements AddonProvider {
const url = new URL(`${WOWUP_API_URL}/tukui/${clientTypeName}`);
const addons = await this._httpClient.get<TukUiAddon[]>(url.toString()).toPromise();
// if (this.isRetail(clientType)) {
// addons.push(await this.getTukUiRetailAddon().toPromise());
// addons.push(await this.getElvUiRetailAddon().toPromise());
// }
console.debug("WowUpTukui",addons);
console.debug("WowUpTukui", addons);
return addons;
};
// private fetchApiResults = async (clientType: WowClientType) => {
// const query = this.getAddonsSuffix(clientType);
// const url = new URL(API_URL);
// url.searchParams.append(query, "all");
private fetchApiResults = async (clientType: WowClientType) => {
const query = this.getAddonsSuffix(clientType);
const url = new URL(API_URL);
url.searchParams.append(query, "all");
// const addons = await this._httpClient.get<TukUiAddon[]>(url.toString()).toPromise();
// if (this.isRetail(clientType)) {
// addons.push(await this.getTukUiRetailAddon().toPromise());
// addons.push(await this.getElvUiRetailAddon().toPromise());
// }
const addons = await this._httpClient.get<TukUiAddon[]>(url.toString()).toPromise();
if (this.isRetail(clientType)) {
addons.push(await this.getTukUiRetailAddon().toPromise());
addons.push(await this.getElvUiRetailAddon().toPromise());
}
// return addons;
// };
return addons;
};
// private getTukUiRetailAddon() {
// return this.getClientApiAddon("tukui");
// }
private getTukUiRetailAddon() {
return this.getClientApiAddon("tukui");
}
// private getElvUiRetailAddon() {
// return this.getClientApiAddon("elvui");
// }
private getElvUiRetailAddon() {
return this.getClientApiAddon("elvui");
}
// private getClientApiAddon(addonName: string): Observable<TukUiAddon> {
// const url = new URL(CLIENT_API_URL);
// url.searchParams.append("ui", addonName);
private getClientApiAddon(addonName: string): Observable<TukUiAddon> {
const url = new URL(CLIENT_API_URL);
url.searchParams.append("ui", addonName);
// return this._httpClient.get<TukUiAddon>(url.toString());
// }
return this._httpClient.get<TukUiAddon>(url.toString());
}
private isRetail(clientType: WowClientType) {
switch (clientType) {

View File

@@ -24,6 +24,10 @@ import { map } from "rxjs/operators";
const API_URL = AppConfig.wowUpHubUrl;
export interface GetAddonBatchResponse {
addons: WowUpAddonRepresentation[];
}
export class WowUpAddonProvider implements AddonProvider {
public readonly name = ADDON_PROVIDER_HUB;
public readonly forceIgnore = false;
@@ -34,18 +38,23 @@ export class WowUpAddonProvider implements AddonProvider {
constructor(private _httpClient: HttpClient, private _electronService: ElectronService) {}
async getAll(clientType: WowClientType, addonIds: string[]): Promise<AddonSearchResult[]> {
const url = new URL(`${API_URL}/addons`);
const addons = await this._httpClient.get<WowUpAddonRepresentation[]>(url.toString()).toPromise();
const gameType = this.getWowGameType(clientType);
const url = new URL(`${API_URL}/addons/batch/${gameType}`);
const response = await this._httpClient
.post<GetAddonBatchResponse>(url.toString(), {
addonIds: _.map(addonIds, (id) => parseInt(id, 10)),
})
.toPromise();
// TODO
return [];
const searchResults = _.map(response?.addons, (addon) => this.getSearchResult(addon));
return searchResults;
}
public async getFeaturedAddons(clientType: WowClientType): Promise<AddonSearchResult[]> {
const gameType = this.getWowGameType(clientType);
const url = new URL(`${API_URL}/addons/featured/${gameType}`);
const addons = await this._httpClient.get<WowUpGetAddonsResponse>(url.toString()).toPromise();
console.debug("WOWUP FEAT", addons);
const searchResults = _.map(addons?.addons, (addon) => this.getSearchResult(addon));
return searchResults;
}
@@ -114,8 +123,6 @@ export class WowUpAddonProvider implements AddonProvider {
);
}
const matchedScanResults = scanResults.filter((sr) => !!sr.exactMatch);
for (let addonFolder of addonFolders) {
var scanResult = scanResults.find((sr) => sr.path === addonFolder.path);
if (!scanResult.exactMatch) {

View File

@@ -84,14 +84,21 @@ export class WowUpFolderScanner {
matchingFiles = _.orderBy(matchingFiles, [(f) => f.toLowerCase()], ["asc"]);
const limit = pLimit(4);
const tasks = _.map(matchingFiles, (file) => limit(() => this.hashFile(file)));
const tasks = _.map(matchingFiles, (file) =>
limit(async () => {
return { hash: await this.hashFile(file), file };
})
);
const fileFingerprints = await Promise.all(tasks);
const hashConcat = _.orderBy(fileFingerprints).join("");
const fingerprintList = _.map(fileFingerprints, (ff) => ff.hash);
const hashConcat = _.orderBy(fingerprintList).join("");
const fingerprint = this.hashString(hashConcat);
// log.info(this._folderPath, fingerprint);
const result: WowUpScanResult = {
fileFingerprints,
fileFingerprints: fingerprintList,
fingerprint,
path: this._folderPath,
folderName: path.basename(this._folderPath),