Merge pull request #645 from Zagrios/bugfix/fix-oneclick-download-playlist-broken

[bugfix] Fix broken oneclick playlist download + issue with specials chars in playlists filenames

(cherry picked from commit d5f2ba3b21)
This commit is contained in:
MathieuG-P
2024-11-05 20:53:12 +01:00
parent 4b60be5846
commit 81c5a7928a
2 changed files with 6 additions and 3 deletions
@@ -13,6 +13,7 @@ import { BeatSaverService } from "../thrid-party/beat-saver/beat-saver.service";
import { copy, copyFile, pathExists, realpath } from "fs-extra";
import { Progression, ensureFolderExist, pathExist } from "../../helpers/fs.helpers";
import { IpcService } from "../ipc.service";
import sanitize from "sanitize-filename";
export class LocalPlaylistsManagerService {
private static instance: LocalPlaylistsManagerService;
@@ -71,12 +72,13 @@ export class LocalPlaylistsManagerService {
private async installBPListFile(bslistSource: string, version: BSVersion): Promise<string> {
const playlistFolder = await this.getPlaylistsFolder(version);
const isLocalFile = await pathExists(bslistSource).catch(e => { log.error(e); return false; });
const filename = isLocalFile ? path.basename(bslistSource) : new URL(bslistSource).pathname.split('/').pop()
const filename = isLocalFile ? path.basename(bslistSource) : sanitize(new URL(bslistSource).pathname.split('/').pop())
const destFile = path.join(playlistFolder, filename);
if (isLocalFile) {
return copyFile(bslistSource, destFile).then(() => destFile);
}
return lastValueFrom(this.request.downloadFile(bslistSource, {
destFolder: playlistFolder,
filename,
+3 -2
View File
@@ -8,8 +8,9 @@ export function resolveHtmlPath (htmlFileName: string) {
const url = new URL(`http://localhost:${port}/${htmlFileName}`);
return url.toString();
}
const filePath = path.resolve(__dirname, "..", "renderer", htmlFileName);
return pathToFileURL(filePath).toString();
const filePath = path.resolve(__dirname, "..", "renderer");
return pathToFileURL(filePath).toString().concat("/", htmlFileName);
};