Add Useragent Headers, better error message handling on login, fix logger toggle #19

Merged
HorizonCode merged 6 commits from dev into master 2024-07-17 08:37:42 +00:00
4 changed files with 60 additions and 9 deletions
Showing only changes of commit a848f078be - Show all commits

View File

@ -1,6 +1,12 @@
async function checkImageExists(url) { async function checkImageExists(url) {
try { 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) { if (!response.ok) {
return false; return false;
} }

View File

@ -152,7 +152,12 @@ function getUserConfig(osuPath) {
} }
async function getUpdateFiles(releaseStream) { 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; return releaseData.ok ? await releaseData.json() : undefined;
} }
@ -244,6 +249,10 @@ async function getEZPPLauncherUpdateFiles(osuPath) {
const filesToDownload = []; const filesToDownload = [];
const updateFilesRequest = await fetch(ezppLauncherUpdateList, { const updateFilesRequest = await fetch(ezppLauncherUpdateList, {
method: "PATCH", 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(); const updateFiles = await updateFilesRequest.json();
for (const updateFile of updateFiles) { for (const updateFile of updateFiles) {
@ -272,23 +281,34 @@ async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) {
const startDownload = async () => { const startDownload = async () => {
//NOTE: delete files that are not in the updateFiles array //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) { for (const pruneFolder of foldersToPrune) {
//NOTE: check if the folder is not the osu root folder. //NOTE: check if the folder is not the osu root folder.
if (path.basename(pruneFolder) == "osu!") if (path.basename(pruneFolder) == "osu!") {
continue; continue;
}
if (fs.existsSync(pruneFolder)) { if (fs.existsSync(pruneFolder)) {
for (const files of await fs.promises.readdir(pruneFolder)) { for (const files of await fs.promises.readdir(pruneFolder)) {
const filePath = path.join(pruneFolder, files); 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 (!validFolder) {
if (allFiles.find(file => file.name == path.basename(filePath)) === undefined) { if (
allFiles.find((file) => file.name == path.basename(filePath)) ===
undefined
) {
eventEmitter.emit("data", { eventEmitter.emit("data", {
fileName: path.basename(filePath), fileName: path.basename(filePath),
}); });
try { try {
await fs.promises.rm(filePath, { recursive: true, force: true }); await fs.promises.rm(filePath, {
} catch { } recursive: true,
force: true,
});
} catch {}
} }
} }
} }

View File

@ -10,7 +10,12 @@ const releasesUrl =
module.exports = { module.exports = {
updateAvailable: async () => { updateAvailable: async () => {
try { 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(); const json = await latestRelease.json();
if (json.length <= 0) return false; if (json.length <= 0) return false;
return { return {

20
main.js
View File

@ -76,6 +76,12 @@ function startOsuStatus() {
try { try {
const currentUserInfo = await fetch( const currentUserInfo = await fetch(
`https://api.ez-pp.farm/get_player_info?name=${currentUser.username}&scope=info`, `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(); const currentUserInfoJson = await currentUserInfo.json();
if ( if (
@ -118,6 +124,12 @@ function startOsuStatus() {
const currentStatusRequest = await fetch( const currentStatusRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_status?name=" + "https://api.ez-pp.farm/v1/get_player_status?name=" +
currentUser.username, 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(); const currentStatus = await currentStatusRequest.json();
@ -130,6 +142,12 @@ function startOsuStatus() {
const currentInfoRequest = await fetch( const currentInfoRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_info?name=" + "https://api.ez-pp.farm/v1/get_player_info?name=" +
currentUser.username + "&scope=all", 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(); const currentInfo = await currentInfoRequest.json();
let currentUsername = currentInfo.player.info.name; let currentUsername = currentInfo.player.info.name;
@ -251,6 +269,8 @@ function registerIPCPipes() {
}), }),
headers: { headers: {
"Content-Type": "application/json", "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",
}, },
}); });