mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
refactor: use find instead of filter for nicer code and perf
This commit is contained in:
@@ -96,12 +96,12 @@ export class LocalMapsManagerService {
|
||||
|
||||
private async loadMapInfoFromPath(mapPath: string): Promise<BsmLocalMap>{
|
||||
const files = await getFilesInFolder(mapPath);
|
||||
const infoFilePaths = files
|
||||
.filter(file => (path.basename(file).toLowerCase() === "info.dat"))
|
||||
const infoFile = files
|
||||
.find(file => (path.basename(file).toLowerCase() === "info.dat"))
|
||||
|
||||
if(infoFilePaths.length === 0){ return null; }
|
||||
if(infoFile === null){ return null; }
|
||||
|
||||
const rawInfoString = await readFile(infoFilePaths[0], {encoding: "utf-8"});
|
||||
const rawInfoString = await readFile(infoFile, {encoding: "utf-8"});
|
||||
|
||||
const rawInfo: RawMapInfoData = JSON.parse(rawInfoString);
|
||||
const coverUrl = new URL(`file:///${path.join(mapPath, rawInfo._coverImageFilename)}`).href;
|
||||
|
||||
Reference in New Issue
Block a user