Merge pull request 'Add Useragent Headers, better error message handling on login, fix logger toggle' (#19) from dev into master

Reviewed-on: #19
This commit is contained in:
HorizonCode 2024-07-17 08:37:41 +00:00
commit f046746037
11 changed files with 138 additions and 63 deletions

View File

@ -1,4 +1,4 @@
const appName = "EZPPLauncher";
const appVersion = "2.1.6";
const appVersion = "2.1.7";
module.exports = { appName, appVersion };

View File

@ -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;
}

View File

@ -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 {}
}
}
}

View File

@ -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 {

52
main.js
View File

@ -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 (
@ -116,7 +122,14 @@ function startOsuStatus() {
const windowTitle = firstInstance.processTitle;
lastOsuStatus = windowTitle;
const currentStatusRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_status?name=" + currentUser.username,
"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();
@ -127,7 +140,14 @@ function startOsuStatus() {
const currentModeString = gamemodes[currentMode];
const currentInfoRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_info?name=" + currentUser.username + "&scope=all",
"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;
@ -237,7 +257,7 @@ function registerIPCPipes() {
};
}
const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 8000);
const timeoutId = setTimeout(() => timeout.abort(), 1000 * 10);
logger.log(`Logging in with user ${args.username}...`);
try {
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
@ -249,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",
},
});
@ -268,7 +290,7 @@ function registerIPCPipes() {
return result;
}
logger.log(
`Login failed for user ${username}.\nResponse:\n${await fetchResult
`Login failed for user ${args.username}.\nResponse:\n${await fetchResult
.text()}`,
);
return {
@ -317,6 +339,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",
},
});
@ -384,7 +408,7 @@ function registerIPCPipes() {
}
if (key == "logging") {
logger.enabled = logging;
logger.enabled = value;
}
if (typeof value == "boolean") {
@ -432,8 +456,9 @@ function registerIPCPipes() {
ipcMain.handle("ezpplauncher:checkUpdate", async (e) => {
const updateInfo = await updateAvailable();
if (updateInfo.update)
if (updateInfo.update) {
mainWindow.webContents.send("ezpplauncher:update", updateInfo.release);
}
});
ipcMain.handle("ezpplauncher:exitAndUpdate", async (e) => {
@ -529,7 +554,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress),
});
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
});
});
@ -557,13 +583,15 @@ function registerIPCPipes() {
status: "Looking for patcher updates...",
});
await new Promise((res) => setTimeout(res, 1000));
const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles(osuPath);
const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles(
osuPath,
);
if (patchFiles.length > 0) {
logger.log("EZPPLauncher updates found.");
const patcherDownloader = await downloadEZPPLauncherUpdateFiles(
osuPath,
patchFiles,
allUpdateFiles
allUpdateFiles,
);
let errored = false;
patcherDownloader.eventEmitter.on("error", (data) => {
@ -584,7 +612,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress),
});
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)
status: `Downloading ${data.fileName}(${
formatBytes(data.loaded)
}/${formatBytes(data.total)})...`,
});
});
@ -728,7 +757,8 @@ function registerIPCPipes() {
const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) {
logger.log(
`Cleanup complete, took ${((performance.now() - timeStart) / 1000).toFixed(3)
`Cleanup complete, took ${
((performance.now() - timeStart) / 1000).toFixed(3)
} seconds.`,
);
clearInterval(cleanup);

View File

@ -1,6 +1,6 @@
{
"name": "ezpplauncher-next",
"version": "2.1.6",
"version": "2.1.7",
"description": "EZPPLauncher rewritten with Svelte.",
"private": false,
"license": "MIT",

View File

@ -69,6 +69,7 @@ export default {
resolve({
browser: true,
dedupe: ["svelte"],
exportConditions: ["svelte"],
}),
typescript({
sourceMap: !production,

View File

@ -1,20 +1,16 @@
<script lang="ts">
import {
Avatar,
Dropdown,
DropdownItem,
DropdownHeader,
DropdownDivider,
Button,
Indicator,
} from "flowbite-svelte";
import {
ArrowLeftSolid,
ArrowRightFromBracketSolid,
ArrowRightToBracketSolid,
HeartSolid,
UserSettingsSolid,
} from "flowbite-svelte-icons";
import Avatar from "flowbite-svelte/Avatar.svelte";
import Dropdown from "flowbite-svelte/Dropdown.svelte";
import DropdownItem from "flowbite-svelte/DropdownItem.svelte";
import DropdownHeader from "flowbite-svelte/DropdownHeader.svelte";
import DropdownDivider from "flowbite-svelte/DropdownDivider.svelte";
import Button from "flowbite-svelte/Button.svelte";
import Indicator from "flowbite-svelte/Indicator.svelte";
import ArrowLeftSolid from "flowbite-svelte-icons/ArrowLeftSolid.svelte";
import ArrowRightFromBracketSolid from "flowbite-svelte-icons/ArrowRightFromBracketSolid.svelte";
import ArrowRightToBracketSolid from "flowbite-svelte-icons/ArrowRightToBracketSolid.svelte";
import HeartSolid from "flowbite-svelte-icons/HeartSolid.svelte";
import UserSettingsSolid from "flowbite-svelte-icons/UserSettingsSolid.svelte";
import ezppLogo from "../public/favicon.png";
import {
currentPage,

View File

@ -1,11 +1,11 @@
<script lang="ts">
import { Button } from "flowbite-svelte";
import Button from "flowbite-svelte/Button.svelte";
import Progressbar from "../lib/Progressbar.svelte";
import {
launching,
patch,
launchStatus,
launchPercentage
launchPercentage,
} from "./../storage/localStore";
let progressbarFix = true;

View File

@ -1,10 +1,14 @@
<script lang="ts">
import { Input, Button, Spinner, Checkbox } from "flowbite-svelte";
import Input from "flowbite-svelte/Input.svelte";
import Button from "flowbite-svelte/Button.svelte";
import Spinner from "flowbite-svelte/Spinner.svelte";
import Checkbox from "flowbite-svelte/Checkbox.svelte";
import { type User } from "../types/user";
import { currentPage, currentUser, startup } from "../storage/localStore";
import toast from "svelte-french-toast";
import { Page } from "../consts/pages";
import { EyeSlashSolid, EyeSolid } from "flowbite-svelte-icons";
import EyeSolid from "flowbite-svelte-icons/EyeSolid.svelte";
import EyeSlashSolid from "flowbite-svelte-icons/EyeSlashSolid.svelte";
let loading = false;
let username = "";
@ -13,11 +17,20 @@
let showPassword = false;
const processLogin = async () => {
if (username.length <= 0 || password.length <= 0) {
toast.error(`Please provice a valid Username and Password!`, {
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000,
});
return;
}
loading = true;
const loginPromise = new Promise<void>((res, rej) => {
const loginPromise = new Promise<string>((res, rej) => {
window.addEventListener(
"login-result",
(e) => {
async (e) => {
const customEvent = e as CustomEvent;
const resultData = customEvent.detail;
const wasSuccessful = "user" in resultData;
@ -30,26 +43,26 @@
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 1500,
}); */
rej();
rej(resultData.message);
loading = false;
return;
}
const userResult = resultData.user as User;
currentUser.set(userResult);
currentPage.set(Page.Launch);
res();
res("");
toast.success(`Welcome back, ${userResult.name}!`, {
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000
duration: 3000,
});
},
{ once: true }
);
window.dispatchEvent(
new CustomEvent("login-attempt", {
detail: { username, password, saveCredentials }
detail: { username, password, saveCredentials },
})
);
});
@ -58,20 +71,20 @@
{
loading: "Logging in...",
success: "Successfully logged in!",
error: "Invalid Username or Password!"
error: (e) => e,
},
{
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000
duration: 0,
}
);
};
const tryAutoLogin = async () => {
loading = true;
const loginPromise = new Promise<void>((res, rej) => {
const loginPromise = new Promise<string>((res, rej) => {
window.addEventListener(
"login-result",
(e) => {
@ -81,29 +94,29 @@
const wasSuccessful = "user" in resultData;
if (isGuest) {
currentPage.set(Page.Launch);
res();
res("");
toast.success(`Logged in as Guest`, {
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000
duration: 3000,
});
return;
}
if (!wasSuccessful) {
loading = false;
rej();
rej(resultData.message);
return;
}
const userResult = resultData.user as User;
currentUser.set(userResult);
currentPage.set(Page.Launch);
res();
res("");
toast.success(`Welcome back, ${userResult.name}!`, {
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000
duration: 3000,
});
loading = false;
},
@ -116,13 +129,13 @@
{
loading: "Logging in...",
success: "Successfully logged in!",
error: "Failed to login."
error: (e) => e,
},
{
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000
duration: 0,
}
);
};
@ -134,7 +147,7 @@
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000
duration: 3000,
});
};

View File

@ -1,6 +1,10 @@
<script lang="ts">
import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte";
import { FileSearchSolid, FolderSolid } from "flowbite-svelte-icons";
import Button from "flowbite-svelte/Button.svelte";
import ButtonGroup from "flowbite-svelte/ButtonGroup.svelte";
import Input from "flowbite-svelte/Input.svelte";
import Toggle from "flowbite-svelte/Toggle.svelte";
import FileSearchSolid from "flowbite-svelte-icons/FileSearchSolid.svelte";
import FolderSolid from "flowbite-svelte-icons/FolderSolid.svelte";
import { patch, presence, logging } from "./../storage/localStore";
let folderPath: string = "";