toc meta data

This commit is contained in:
jliddev
2020-08-15 08:48:41 -05:00
parent 1bfbd66596
commit a439a78e79
6 changed files with 72 additions and 8 deletions

View File

@@ -12,6 +12,7 @@ import { AddonChannelType } from "app/models/wowup/addon-channel-type";
import * as _ from 'lodash';
import * as uuid from 'uuid';
import { AddonFolder } from "app/models/wowup/addon-folder";
import { WowUpApiService } from "../wowup-api/wowup-api.service";
@Injectable({
providedIn: 'root'
@@ -22,8 +23,9 @@ export class AddonService {
constructor(
private _addonStorage: AddonStorageService,
private httpClient: HttpClient,
private warcraftService: WarcraftService
private warcraftService: WarcraftService,
private _wowupApiService: WowUpApiService,
httpClient: HttpClient
) {
this._addonProviders = [
new CurseAddonProvider(httpClient)
@@ -69,11 +71,19 @@ export class AddonService {
for (let folder of addonFolders) {
try {
let addon: Addon;
if (folder.toc.curseProjectId) {
addon = await this.getCurseAddonById(folder, clientType);
} else {
}
const response = await this._wowupApiService.scanAddon({
channelType: AddonChannelType.Stable,
clientType,
folderName: folder.name,
tocMetaData: folder.tocMetaData
});
// if (folder.toc.curseProjectId) {
// addon = await this.getCurseAddonById(folder, clientType);
// } else {
// }
if (!addon) {
continue;
@@ -88,7 +98,10 @@ export class AddonService {
return addons;
}
private async getCurseAddonById(addonFolder: AddonFolder, clientType: WowClientType) {
private async getCurseAddonById(
addonFolder: AddonFolder,
clientType: WowClientType
) {
const curseProvider = this._addonProviders.find(p => p instanceof CurseAddonProvider);
const searchResult = await curseProvider.getById(addonFolder.toc.curseProjectId, clientType);
const latestFile = this.getLatestFile(searchResult, AddonChannelType.Stable);

View File

@@ -153,12 +153,14 @@ export class WarcraftService {
}
const toc = await this.getToc(path.join(dirPath, tocFile));
const tocMetaData = this.getTocMetaData(path.join(dirPath, tocFile));
return {
name: dir,
path: dirPath,
status: 'Pending',
toc: toc
toc: toc,
tocMetaData: tocMetaData
};
} catch (e) {
console.error(e);
@@ -171,6 +173,11 @@ export class WarcraftService {
return await parser.parse();
}
private getTocMetaData(filePath: string) {
const parser = new TocParser(filePath);
return parser.parseMetaData();
}
public getClientLocation(clientType: WowClientType) {
const clientLocationKey = this.getClientLocationKey(clientType);
return this.storage.getPreference<string>(clientLocationKey) || '';

View File

@@ -0,0 +1,26 @@
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { tap } from "rxjs/operators";
import { ScanRequest } from "app/models/wowup-api/scan.request";
const API_URL = 'http://localhost:3000/dev';
@Injectable({
providedIn: 'root'
})
export class WowUpApiService {
constructor(
private _httpClient: HttpClient
) { }
public scanAddon(requst: ScanRequest) {
const url = new URL(`${API_URL}/addons/scan`);
return this._httpClient.post(url.toString(), requst)
.pipe(
tap(res => console.log(res))
)
.toPromise();
}
}

View File

@@ -36,6 +36,14 @@ export class TocParser {
};
}
public parseMetaData(): string[] {
this._tocText = fs.readFileSync(this._tocPath, { encoding: 'utf-8' })
return this._tocText
.split('\n')
.filter(line => line.trim().startsWith('## '));
}
private getValue(key: string): string {
const match = new RegExp(`^## ${key}:(.*?)$`, 'm').exec(this._tocText);

View File

@@ -0,0 +1,9 @@
import { WowClientType } from "../warcraft/wow-client-type";
import { AddonChannelType } from "../wowup/addon-channel-type";
export interface ScanRequest {
clientType: WowClientType,
channelType: AddonChannelType;
folderName: string;
tocMetaData: string[];
}

View File

@@ -7,4 +7,5 @@ export interface AddonFolder {
thumbnailUrl?: string;
latestVersion?: string;
toc: Toc;
tocMetaData: string[];
}