mirror of
https://github.com/WowUp/WowUp.git
synced 2026-04-29 02:07:55 -04:00
toc meta data
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) || '';
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
9
wowup-electron/src/app/models/wowup-api/scan.request.ts
Normal file
9
wowup-electron/src/app/models/wowup-api/scan.request.ts
Normal 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[];
|
||||
}
|
||||
@@ -7,4 +7,5 @@ export interface AddonFolder {
|
||||
thumbnailUrl?: string;
|
||||
latestVersion?: string;
|
||||
toc: Toc;
|
||||
tocMetaData: string[];
|
||||
}
|
||||
Reference in New Issue
Block a user