mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature-107] add diffictulties hightlight for playlist maps
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import { LocalBPList } from "shared/models/playlists/local-playlist.models";
|
||||
import { LocalPlaylistsManagerService } from "../services/additional-content/local-playlists-manager.service";
|
||||
import { IpcService } from "../services/ipc.service";
|
||||
import { from, lastValueFrom, mergeMap, of } from "rxjs";
|
||||
import { BPList } from "shared/models/playlists/playlist.interface";
|
||||
import path from "path";
|
||||
import { LocalMapsManagerService } from "../services/additional-content/maps/local-maps-manager.service";
|
||||
import { Progression } from "main/helpers/fs.helpers";
|
||||
import { lstatSync } from "fs-extra";
|
||||
import { isValidUrl } from "shared/helpers/url.helpers";
|
||||
import { pathToFileURL } from "url";
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ export class LocalPlaylistsManagerService {
|
||||
throw new Error(`Invalid source ${source}`);
|
||||
}
|
||||
|
||||
const bpList = isLocalFile ? JSON.parse(readFileSync(source).toString()) : await this.request.getJSON<BPList>(source);
|
||||
const bpList: BPList = isLocalFile ? JSON.parse(readFileSync(source).toString()) : await this.request.getJSON<BPList>(source);
|
||||
|
||||
return bpList;
|
||||
}
|
||||
@@ -189,7 +189,17 @@ export class LocalPlaylistsManagerService {
|
||||
id: localBPList.customData?.syncURL ? tryExtractPlaylistId(localBPList.customData.syncURL) : undefined
|
||||
}
|
||||
|
||||
const songsDetails = localBPList.songs?.map(s => this.songDetails.getSongDetails(s.hash)).filter(Boolean);
|
||||
const songsDetails = localBPList.songs?.map(s => {
|
||||
if(!s){
|
||||
return undefined;
|
||||
}
|
||||
if(s.hash){
|
||||
return this.songDetails.getSongDetails(s.hash);
|
||||
}
|
||||
if(s.key){
|
||||
return this.songDetails.getSongDetailsById(s.key);
|
||||
}
|
||||
}).filter(Boolean);
|
||||
|
||||
if(songsDetails && songsDetails.length){
|
||||
bpListDetails.duration = songsDetails.reduce((acc, song) => acc + song.duration, 0);
|
||||
|
||||
@@ -37,6 +37,7 @@ export class SongDetailsCacheService {
|
||||
private readonly utils: UtilsService;
|
||||
|
||||
private songDetailsCache: Record<string, SongDetails> = {};
|
||||
private songDetailsIdIndex: Record<string, SongDetails> = {};
|
||||
private readonly _loaded$ = new BehaviorSubject<boolean>(null);
|
||||
|
||||
private constructor(){
|
||||
@@ -52,6 +53,9 @@ export class SongDetailsCacheService {
|
||||
|
||||
await this.downloadCacheFile(etag).then(etag => {
|
||||
this.config.set(this.etagKey, etag);
|
||||
log.info("SongDetailsCache downloaded");
|
||||
this.songDetailsIdIndex = this.createIdIndex(this.songDetailsCache);
|
||||
log.info("SongDetailsIdIndex created");
|
||||
}).catch(err => {
|
||||
log.error("Unable to download cache file", err);
|
||||
});
|
||||
@@ -66,6 +70,14 @@ export class SongDetailsCacheService {
|
||||
})
|
||||
}
|
||||
|
||||
private createIdIndex(songDetailsCache: Record<string, SongDetails>): Record<string, SongDetails> {
|
||||
const res: Record<string, SongDetails> = {};
|
||||
for(const hash in songDetailsCache){
|
||||
res[songDetailsCache[hash].id] = songDetailsCache[hash];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private async readProtoMessageCacheFile(filePath: string): Promise<Record<string, SongDetails>> {
|
||||
const protobufRoot = protobuf.loadSync(this.getProtoShemaPath());
|
||||
const cacheMessage = protobufRoot.lookupType("SongDetailsCache");
|
||||
@@ -82,7 +94,7 @@ export class SongDetailsCacheService {
|
||||
|
||||
for(const rawSong of messageObj.songs){
|
||||
const deserialized = RawSongDetailsDeserializer.deserialize(rawSong);
|
||||
res[deserialized.hash.toLocaleLowerCase()] = deserialized;
|
||||
res[deserialized.hash.toLowerCase()] = deserialized;
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -166,8 +178,12 @@ export class SongDetailsCacheService {
|
||||
}))));
|
||||
}
|
||||
|
||||
public getSongDetails(hash: string): SongDetails {
|
||||
return this.songDetailsCache[hash.toLocaleLowerCase()];
|
||||
public getSongDetails(hash: string): SongDetails | undefined {
|
||||
return this.songDetailsCache[hash.toLowerCase()];
|
||||
}
|
||||
|
||||
public getSongDetailsById(id: string): SongDetails | undefined {
|
||||
return this.songDetailsIdIndex[id.toLowerCase()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user