Skip to content

Commit

Permalink
Merge pull request #635 from Zagrios/bugfix/updating-naming-sheme-of-…
Browse files Browse the repository at this point in the history
…downloaded-maps-and-playlists

[bugfix] updating naming sheme of downloaded maps and playlists
  • Loading branch information
Zagrios authored Nov 1, 2024
2 parents ed1960c + aa69b3c commit 681ddc6
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 80 deletions.
49 changes: 33 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
"afterSign": ".erb/scripts/notarize.js",
"afterPack": ".erb/scripts/after-pack.js",
"win": {
"signingHashAlgorithms": ["sha256"],
"signingHashAlgorithms": [
"sha256"
],
"target": [
"nsis",
"nsis-web"
Expand Down Expand Up @@ -157,7 +159,7 @@
"@types/dompurify": "^3.0.5",
"@types/got": "^9.6.12",
"@types/jest": "^29.5.11",
"@types/node": "20.11.15",
"@types/node": "22.8.6",
"@types/node-fetch": "^2.6.3",
"@types/pako": "^2.0.1",
"@types/react": "^18.0.33",
Expand Down Expand Up @@ -249,7 +251,7 @@
"format-duration": "^3.0.2",
"framer-motion": "^11.2.6",
"fs-extra": "^11.2.0",
"got": "^14.4.2",
"got": "^14.4.3",
"history": "^5.3.0",
"is-elevated": "^4.0.0",
"jszip": "^3.10.1",
Expand Down Expand Up @@ -321,6 +323,6 @@
"logLevel": "quiet"
},
"volta": {
"node": "20.17.0"
"node": "22.11.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,41 @@ export class LocalPlaylistsManagerService {
version?: BSVersion,
dest?: string
}): Promise<{path: string, localBPList: LocalBPList}> {
const bplist = await this.readPlaylistFromSource(opt.bplistSource);
const { bpList, filename } = await this.readPlaylistFromSource(opt.bplistSource);

const dest = await (async () => {
if(opt.dest && path.isAbsolute(opt.dest) && this.acceptPlaylistFiletype(opt.dest)) { return opt.dest; }
const playlistFolder = await this.getPlaylistsFolder(opt.version);
return path.join(playlistFolder, `${sanitize(bplist.playlistTitle)}.bplist`);
return path.join(playlistFolder, filename);
})();

writeFileSync(dest, JSON.stringify(bplist, null, 2));
writeFileSync(dest, JSON.stringify(bpList, null, 2));

const localBPList: LocalBPList = { ...bplist, path: dest };
const localBPList: LocalBPList = { ...bpList, path: dest };

return { path: dest, localBPList };
}


private async readPlaylistFromSource(source: string): Promise<BPList> {
private async readPlaylistFromSource(source: string): Promise<{ bpList: BPList, filename: string }> {
const isLocalFile = await pathExists(source).catch(e => { log.error(e); return false; });

if(!isLocalFile && !isValidUrl(source)) {
throw new CustomError(`Invalid source (${source})`, "INVALID_SOURCE");
}

const bpList: BPList = await (async () => {
const { bpList, filename }: { bpList: BPList, filename: string } = await (async () => {
if(isLocalFile){
const res = await tryit(async () => JSON.parse(readFileSync(source).toString()));
const res = await tryit(async () => JSON.parse(readFileSync(source).toString()) as BPList);
if(res.error) {
throw CustomError.fromError(res.error, "CANNOT_PARSE_PLAYLIST");
}
return res.result;
return { bpList: res.result, filename: path.basename(source) };
}
return this.request.getJSON<BPList>(source);

const res = await this.request.getJSON<BPList>(source);
const filename = this.request.getFilenameFromContentDisposition(res.headers["content-disposition"]) ?? `${res.data.playlistTitle}.bplist`;
return { bpList: res.data, filename };
})();

if(!bpList?.playlistTitle) {
Expand All @@ -160,7 +163,7 @@ export class LocalPlaylistsManagerService {
{ ...s, hash: findHashInString(s.hash) ?? s.hash }
) : s).filter(Boolean);

return bpList;
return { bpList, filename };
}

private openOneClickDownloadPlaylistWindow(downloadUrl: string): void {
Expand Down Expand Up @@ -189,14 +192,14 @@ export class LocalPlaylistsManagerService {
progress.total = playlistPaths.length;

for (const playlistPath of playlistPaths) {
const {result: bpList, error} = await tryit(() => this.readPlaylistFromSource(playlistPath));
const {result, error} = await tryit(() => this.readPlaylistFromSource(playlistPath));

if(error) {
log.error(error);
continue;
}

const localBpList: LocalBPList = { ...bpList, path: playlistPath };
const localBpList: LocalBPList = { ...result.bpList, path: playlistPath };
bpLists.push(localBpList);
progress.current += 1;
obs.next(progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class LocalMapsManagerService {
log.info("Downloading map", map.name, map.id);

const zipUrl = map.versions.at(0).downloadURL;
const mapFolderName = sanitize(`${map.id}-${map.name}`);
const mapFolderName = sanitize(`${map.id} (${map.metadata.songName} - ${map.metadata.levelAuthorName})`);
const mapsFolder = await this.getMapsFolderPath(version);

const mapPath = path.join(mapsFolder, mapFolderName);
Expand Down
2 changes: 1 addition & 1 deletion src/main/services/bs-version-lib.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class BSVersionLibService {
}

private getRemoteVersions(): Promise<BSVersion[]> {
return this.requestService.getJSON<BSVersion[]>(this.REMOTE_BS_VERSIONS_URL);
return this.requestService.getJSON<BSVersion[]>(this.REMOTE_BS_VERSIONS_URL).then(res => res.data);
}

private async getLocalVersions(): Promise<BSVersion[]> {
Expand Down
8 changes: 4 additions & 4 deletions src/main/services/mods/beat-mods-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class BeatModsApiService {
if (this.aliasesCache.size) {
return this.aliasesCache;
}
return this.requestService.getJSON<Record<string, string[]>>(this.BEAT_MODS_ALIAS).then(rawAliases => {
return this.requestService.getJSON<Record<string, string[]>>(this.BEAT_MODS_ALIAS).then(({ data: rawAliases }) => {
Object.entries(rawAliases).forEach(([key, value]) => {
this.aliasesCache.set(
key,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class BeatModsApiService {

const alias = await this.getAliasOfVersion(version);

return this.requestService.getJSON<Mod[]>(this.getVersionModsUrl(alias)).then(mods => {
return this.requestService.getJSON<Mod[]>(this.getVersionModsUrl(alias)).then(({ data: mods }) => {
mods = mods.map(mod => this.asignDependencies(mod, mods));
this.versionModsCache.set(version.BSVersion, mods);

Expand All @@ -111,7 +111,7 @@ export class BeatModsApiService {
if (this.allModsCache) {
return this.allModsCache;
}
return this.requestService.getJSON<Mod[]>(this.getAllModsUrl()).then(mods => {
return this.requestService.getJSON<Mod[]>(this.getAllModsUrl()).then(({ data: mods }) => {
this.allModsCache = mods;
return this.allModsCache;
});
Expand All @@ -122,7 +122,7 @@ export class BeatModsApiService {
return Promise.resolve(this.modsHashCache.get(hash));
}

return this.requestService.getJSON<Mod[]>(`${this.BEAT_MODS_API_URL}mod?hash=${hash}`).then(mods => {
return this.requestService.getJSON<Mod[]>(`${this.BEAT_MODS_API_URL}mod?hash=${hash}`).then(({ data: mods }) => {
this.updateModsHashCache(mods);
return mods.at(0);
});
Expand Down
Loading

0 comments on commit 681ddc6

Please sign in to comment.