mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
create download maps modal
This commit is contained in:
@@ -15,6 +15,57 @@ export class BeatSaverApiService {
|
||||
|
||||
private constructor(){}
|
||||
|
||||
private mapFilterToUrlParams(filter: MapFilter): URLSearchParams{
|
||||
|
||||
if(!filter){ return new URLSearchParams(); }
|
||||
|
||||
const enbledTagsString = Array.from(filter.enabledTags);
|
||||
const excludedTagsString = Array.from(filter.excludedTags).map(tag => `!${tag}`);
|
||||
|
||||
const tags = [...enbledTagsString, excludedTagsString].join("|");
|
||||
|
||||
const params = {
|
||||
automapper: String(filter.automapper ?? ""),
|
||||
chroma: String(filter.chroma ?? ""),
|
||||
cinema: String(filter.cinema ?? ""),
|
||||
me: String(filter.me ?? ""),
|
||||
noodle: String(filter.noodle ?? ""),
|
||||
ranked: String(filter.ranked ?? ""),
|
||||
verified: String(filter.ranked ?? ""),
|
||||
curated: String(filter.curated ?? ""),
|
||||
fullSpread : String(filter.fullSpread ?? ""),
|
||||
from: String(filter.from ?? ""),
|
||||
to: String(filter.to ?? ""),
|
||||
tags: tags,
|
||||
minDuration: String(filter.minDuration ?? ""),
|
||||
maxDuration: String(filter.maxDuration ?? ""),
|
||||
minNps: String(filter.minNps ?? ""),
|
||||
maxNps: String(filter.maxNps ?? ""),
|
||||
};
|
||||
|
||||
return new URLSearchParams(params);
|
||||
|
||||
}
|
||||
|
||||
private searchParamsToUrlParams(search: SearchParams): URLSearchParams{
|
||||
|
||||
if(!search){ return new URLSearchParams(); }
|
||||
|
||||
const searchParams = {
|
||||
includeEmpty: String(search.includeEmpty ?? ""),
|
||||
sortOrder: String(search.sortOrder ?? ""),
|
||||
q: String(search.q ?? "")
|
||||
};
|
||||
|
||||
const filterUrlParms = this.mapFilterToUrlParams(search.filter);
|
||||
|
||||
return new URLSearchParams({
|
||||
...searchParams,
|
||||
...Object.fromEntries(filterUrlParms)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public async getMapsDetailsByHashs<T extends string>(hashs: T[]): Promise<ApiResult<Record<Lowercase<T>, BsvMapDetail>>>{
|
||||
|
||||
if(hashs.length > 50){ throw "too musch map hashs"; }
|
||||
@@ -37,8 +88,24 @@ export class BeatSaverApiService {
|
||||
|
||||
}
|
||||
|
||||
public async searchMaps(params: SearchParams): Promise<ApiResult<SearchResponse>>{
|
||||
|
||||
public async searchMaps(search: SearchParams): Promise<ApiResult<SearchResponse>>{
|
||||
|
||||
const url = new URL(`${this.bsaverApiUrl}/search/text/${search?.page ?? 0}`);
|
||||
|
||||
url.search = this.searchParamsToUrlParams(search).toString();
|
||||
|
||||
const res = await fetch(url);
|
||||
|
||||
console.log(res);
|
||||
|
||||
if(!res.ok){
|
||||
return {status: res.status, data: null};
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
return {status: res.status, data};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { splitIntoChunk } from "renderer/helpers/array-tools";
|
||||
import { of } from "rxjs";
|
||||
import { Observable } from "rxjs";
|
||||
import { BsvMapDetail } from "shared/models/maps";
|
||||
import { SearchParams } from "shared/models/maps/beat-saver.model";
|
||||
import { OsDiagnosticService } from "../os-diagnostic.service";
|
||||
import { BeatSaverApiService } from "./beat-saver-api.service";
|
||||
|
||||
@@ -61,8 +62,20 @@ export class BeatSaverService {
|
||||
|
||||
observer.complete();
|
||||
})()
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
public searchMaps(search: SearchParams): Promise<BsvMapDetail[]>{
|
||||
|
||||
return this.bsaverApi.searchMaps(search).then(res => {
|
||||
return res.status === 200 ? res.data.docs : [];
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
return [];
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { DownloadMapsModal } from "renderer/components/modal/modal-types/download-maps-modal.component";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { ModalResponse, ModalService } from "./modale.service";
|
||||
|
||||
export class MapsDownloaderService {
|
||||
|
||||
@@ -9,12 +11,16 @@ export class MapsDownloaderService {
|
||||
return MapsDownloaderService.instance;
|
||||
}
|
||||
|
||||
private constructor(){
|
||||
private readonly modals: ModalService;
|
||||
|
||||
private constructor(){
|
||||
this.modals = ModalService.getInsance();
|
||||
}
|
||||
|
||||
public openDownloadMapModal(version?: BSVersion){
|
||||
public openDownloadMapModal(version?: BSVersion): Promise<ModalResponse<void>>{
|
||||
|
||||
return this.modals.openModal(DownloadMapsModal, version);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user