mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
can now link and unlink version maps
This commit is contained in:
@@ -22,9 +22,18 @@ export class BeatSaverApiService {
|
||||
|
||||
const resp = await fetch(`${this.bsaverApiUrl}/maps/hash/${paramsHashs}`);
|
||||
|
||||
const data = await resp.json() as Record<Lowercase<T>, BsvMapDetail>;
|
||||
const data = await resp.json() as Record<Lowercase<T>, BsvMapDetail> | BsvMapDetail;
|
||||
|
||||
return {status: resp.status, data: data};
|
||||
if((data as BsvMapDetail).id){
|
||||
const key = (data as BsvMapDetail).versions.at(0).hash.toLowerCase();
|
||||
const parsedData = {
|
||||
[key]: data as BsvMapDetail
|
||||
} as Record<Lowercase<T>, BsvMapDetail>;
|
||||
|
||||
return {status: resp.status, data: parsedData}
|
||||
}
|
||||
|
||||
return {status: resp.status, data: (data as Record<Lowercase<T>, BsvMapDetail>)};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Observable } from "rxjs";
|
||||
import { Subject, Observable } from "rxjs";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { BsmLocalMap } from "shared/models/maps/bsm-local-map.interface";
|
||||
import { BeatSaverService } from "./beat-saver/beat-saver.service";
|
||||
@@ -16,6 +16,9 @@ export class MapsManagerService {
|
||||
private readonly ipcService: IpcService;
|
||||
private readonly bsaver: BeatSaverService;
|
||||
|
||||
private readonly lastLinkedVersion$: Subject<BSVersion> = new Subject();
|
||||
private readonly lastUnlinkedVersion$: Subject<BSVersion> = new Subject();
|
||||
|
||||
private constructor(){
|
||||
this.ipcService = IpcService.getInstance();
|
||||
this.bsaver = BeatSaverService.getInstance();
|
||||
@@ -44,14 +47,30 @@ export class MapsManagerService {
|
||||
})
|
||||
}
|
||||
|
||||
public downloadMap(map: any, version?: BSVersion){
|
||||
|
||||
public linkVersion(version: BSVersion): Promise<void>{
|
||||
return this.ipcService.send<void, {version: BSVersion, keepMaps: boolean}>("link-version-maps", {args: {version, keepMaps: true}}).then(res => {
|
||||
if(res.success){
|
||||
return this.lastLinkedVersion$.next(version);
|
||||
}
|
||||
throw res.error;
|
||||
});
|
||||
}
|
||||
|
||||
public deleteMaps(maps: any[], version?: BSVersion){
|
||||
|
||||
public unlinkVersion(version: BSVersion): Promise<void>{
|
||||
return this.ipcService.send<void, {version: BSVersion, keepMaps: boolean}>("unlink-version-maps", {args: {version, keepMaps: true}}).then(res => {
|
||||
if(res.success){
|
||||
return this.lastUnlinkedVersion$.next(version);
|
||||
}
|
||||
throw res.error;
|
||||
});
|
||||
}
|
||||
|
||||
public get versionLinked$(): Observable<BSVersion>{
|
||||
return this.lastLinkedVersion$.asObservable();
|
||||
}
|
||||
|
||||
public get versionUnlinked$(): Observable<BSVersion>{
|
||||
return this.lastUnlinkedVersion$.asObservable();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user