mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
partial ui for mods
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { Mod } from "shared/models/mods/mod.interface";
|
||||
import { RequestService } from "../request.service";
|
||||
|
||||
export class BeatModsApiService {
|
||||
|
||||
private static instance: BeatModsApiService;
|
||||
|
||||
private readonly requestService: RequestService
|
||||
|
||||
private readonly BEAT_MODS_VERSIONS = "https://versions.beatmods.com/versions.json";
|
||||
private readonly BEAT_MODS_ALIAS = "https://alias.beatmods.com/aliases.json";
|
||||
|
||||
private readonly BEAT_MODS_API_URL = "https://beatmods.com/api/v1/";
|
||||
|
||||
private readonly versionsCache: BSVersion[] = [];
|
||||
private readonly aliasesCache = new Map<string, BSVersion[]>();
|
||||
private readonly versionModsCache = new Map<string, Mod[]>();
|
||||
|
||||
private readonly allModsCache: Mod[] = [];
|
||||
|
||||
public static getInstance(): BeatModsApiService{
|
||||
if(!BeatModsApiService.instance){ BeatModsApiService.instance = new BeatModsApiService(); }
|
||||
return BeatModsApiService.instance;
|
||||
}
|
||||
|
||||
private constructor(){
|
||||
this.requestService = RequestService.getInstance();
|
||||
}
|
||||
|
||||
private getVersionModsUrl(version: BSVersion): string{
|
||||
return `${this.BEAT_MODS_API_URL}mod?status=approved&gameVersion=${version.BSVersion}&sort=&sortDirection=1`;
|
||||
}
|
||||
|
||||
private async getVersionAlias(): Promise<Map<string, BSVersion[]>>{
|
||||
if(this.aliasesCache.size){ return this.aliasesCache; }
|
||||
return this.requestService.get<Record<string, string[]>>(this.BEAT_MODS_ALIAS).then(rawAliases => {
|
||||
Object.entries(rawAliases).forEach(([key, value]) => {
|
||||
this.aliasesCache.set(key, value.map(s => ({BSVersion: s} as BSVersion)));
|
||||
});
|
||||
return this.aliasesCache;
|
||||
})
|
||||
}
|
||||
|
||||
private async getAliasOfVersion(version: BSVersion): Promise<BSVersion>{
|
||||
return this.getVersionAlias().then(aliases => {
|
||||
if(Array.from(aliases.keys()).some(k => k === version.BSVersion)){ return version; }
|
||||
const alias = Array.from(aliases.entries()).find(([key, value]) => value.find(v => v.BSVersion === version.BSVersion))[0];
|
||||
return {BSVersion: alias} as BSVersion
|
||||
});
|
||||
}
|
||||
|
||||
private asignDependencies(mod: Mod, mods: Mod[]): Mod{
|
||||
mod.dependencies.map(dep => mods.find(mod => mod.name === dep.name));
|
||||
return mod;
|
||||
}
|
||||
|
||||
public async getVersionMods(version: BSVersion): Promise<Mod[]>{
|
||||
if(this.versionModsCache.has(version.BSVersion)){ return this.versionModsCache.get(version.BSVersion); }
|
||||
|
||||
const alias = await this.getAliasOfVersion(version);
|
||||
|
||||
return this.requestService.get<Mod[]>(this.getVersionModsUrl(alias)).then(mods => {
|
||||
mods.map(mod => this.asignDependencies(mod, mods));
|
||||
this.versionModsCache.set(version.BSVersion, mods);
|
||||
return mods;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { Mod } from "shared/models/mods/mod.interface";import { BeatModsApiService } from "./beat-mods-api.service";
|
||||
;
|
||||
|
||||
export class BsModsManagerService {
|
||||
|
||||
private static instance: BsModsManagerService;
|
||||
|
||||
private beatModsApi: BeatModsApiService;
|
||||
|
||||
public static getInstance(): BsModsManagerService{
|
||||
if(!BsModsManagerService.instance){ BsModsManagerService.instance = new BsModsManagerService(); }
|
||||
return BsModsManagerService.instance;
|
||||
}
|
||||
|
||||
private constructor(){
|
||||
this.beatModsApi = BeatModsApiService.getInstance();
|
||||
}
|
||||
|
||||
public getAvailableMods(version: BSVersion): Promise<Mod[]>{
|
||||
return this.beatModsApi.getVersionMods(version);
|
||||
}
|
||||
|
||||
public getInstalledMods(version: BSVersion): Promise<Mod[]>{
|
||||
throw "NOT IMPLEMENTED YET";
|
||||
}
|
||||
|
||||
public installMods(mods: Mod[], version: BSVersion){
|
||||
throw "NOT IMPLEMENTED YET";
|
||||
}
|
||||
|
||||
public uninstallMods(mods: Mod[], version: BSVersion){
|
||||
throw "NOT IMPLEMENTED YET";
|
||||
}
|
||||
|
||||
public isModsAvailable(version: BSVersion): Promise<boolean>{
|
||||
throw "NOT IMPLEMENTED YET";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user