From a848f078be9de0b01778bb660af3be23de598baf Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Wed, 17 Jul 2024 10:24:07 +0200 Subject: [PATCH] add useragent headers --- electron/imageUtil.js | 8 +++++++- electron/osuUtil.js | 34 +++++++++++++++++++++++++++------- electron/updateCheck.js | 7 ++++++- main.js | 20 ++++++++++++++++++++ 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/electron/imageUtil.js b/electron/imageUtil.js index 065f45e..2f6f9b8 100644 --- a/electron/imageUtil.js +++ b/electron/imageUtil.js @@ -1,6 +1,12 @@ async function checkImageExists(url) { try { - const response = await fetch(url, { method: "HEAD" }); + const response = await fetch(url, { + method: "HEAD", + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, + }); if (!response.ok) { return false; } diff --git a/electron/osuUtil.js b/electron/osuUtil.js index e116608..f2f0118 100644 --- a/electron/osuUtil.js +++ b/electron/osuUtil.js @@ -152,7 +152,12 @@ function getUserConfig(osuPath) { } async function getUpdateFiles(releaseStream) { - const releaseData = await fetch(checkUpdateURL + releaseStream); + const releaseData = await fetch(checkUpdateURL + releaseStream, { + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, + }); return releaseData.ok ? await releaseData.json() : undefined; } @@ -244,6 +249,10 @@ async function getEZPPLauncherUpdateFiles(osuPath) { const filesToDownload = []; const updateFilesRequest = await fetch(ezppLauncherUpdateList, { method: "PATCH", + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, }); const updateFiles = await updateFilesRequest.json(); for (const updateFile of updateFiles) { @@ -272,23 +281,34 @@ async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) { const startDownload = async () => { //NOTE: delete files that are not in the updateFiles array - const foldersToPrune = allFiles.map(file => path.dirname(path.join(osuPath, ...file.folder.split("/"), file.name))).filter((folder, index, self) => self.indexOf(folder) === index); + const foldersToPrune = allFiles.map((file) => + path.dirname(path.join(osuPath, ...file.folder.split("/"), file.name)) + ).filter((folder, index, self) => self.indexOf(folder) === index); for (const pruneFolder of foldersToPrune) { //NOTE: check if the folder is not the osu root folder. - if (path.basename(pruneFolder) == "osu!") + if (path.basename(pruneFolder) == "osu!") { continue; + } if (fs.existsSync(pruneFolder)) { for (const files of await fs.promises.readdir(pruneFolder)) { const filePath = path.join(pruneFolder, files); - const validFolder = allFiles.find(file => path.dirname(filePath).endsWith(file.folder)); + const validFolder = allFiles.find((file) => + path.dirname(filePath).endsWith(file.folder) + ); if (!validFolder) { - if (allFiles.find(file => file.name == path.basename(filePath)) === undefined) { + if ( + allFiles.find((file) => file.name == path.basename(filePath)) === + undefined + ) { eventEmitter.emit("data", { fileName: path.basename(filePath), }); try { - await fs.promises.rm(filePath, { recursive: true, force: true }); - } catch { } + await fs.promises.rm(filePath, { + recursive: true, + force: true, + }); + } catch {} } } } diff --git a/electron/updateCheck.js b/electron/updateCheck.js index 0dd035c..bc67bb8 100644 --- a/electron/updateCheck.js +++ b/electron/updateCheck.js @@ -10,7 +10,12 @@ const releasesUrl = module.exports = { updateAvailable: async () => { try { - const latestRelease = await fetch(repoApiUrl); + const latestRelease = await fetch(repoApiUrl, { + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, + }); const json = await latestRelease.json(); if (json.length <= 0) return false; return { diff --git a/main.js b/main.js index c520970..514fc3b 100644 --- a/main.js +++ b/main.js @@ -76,6 +76,12 @@ function startOsuStatus() { try { const currentUserInfo = await fetch( `https://api.ez-pp.farm/get_player_info?name=${currentUser.username}&scope=info`, + { + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, + }, ); const currentUserInfoJson = await currentUserInfo.json(); if ( @@ -118,6 +124,12 @@ function startOsuStatus() { const currentStatusRequest = await fetch( "https://api.ez-pp.farm/v1/get_player_status?name=" + currentUser.username, + { + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, + }, ); const currentStatus = await currentStatusRequest.json(); @@ -130,6 +142,12 @@ function startOsuStatus() { const currentInfoRequest = await fetch( "https://api.ez-pp.farm/v1/get_player_info?name=" + currentUser.username + "&scope=all", + { + headers: { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", + }, + }, ); const currentInfo = await currentInfoRequest.json(); let currentUsername = currentInfo.player.info.name; @@ -251,6 +269,8 @@ function registerIPCPipes() { }), headers: { "Content-Type": "application/json", + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0", }, });