From a3da5bd13166edd29b1687a50dc5333c583fa367 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 27 Jun 2024 02:46:39 +0100 Subject: [PATCH] app: format --- app/package.json | 74 +++++++++++++++++----------------- app/src/lib/Util/functions.ts | 76 +++++++++++++++++++++++------------ 2 files changed, 87 insertions(+), 63 deletions(-) diff --git a/app/package.json b/app/package.json index 13eedaa..810b6bd 100644 --- a/app/package.json +++ b/app/package.json @@ -1,39 +1,39 @@ { - "name": "vite_app", - "version": "0.0.0", - "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^3.0.2", - "@tsconfig/svelte": "^5.0.2", - "autoprefixer": "^10.4.19", - "eslint": "^8.57.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-svelte": "^2.35.1", - "postcss": "^8.4.38", - "prettier": "^3.1.1", - "prettier-plugin-svelte": "^3.1.2", - "prettier-plugin-tailwindcss": "^0.5.13", - "svelte": "^4.2.12", - "svelte-check": "^3.6.7", - "tailwindcss": "^3.4.4", - "tslib": "^2.6.2", - "typescript": "^5.4.3", - "typescript-eslint": "^7.4.0", - "vite": "^5.2.0", - "vite-tsconfig-paths": "^4.3.2", - "vitest": "^1.2.0" - }, - "private": true, - "scripts": { - "dev": "vite build --watch --mode development", - "watch": "vite build --watch --mode development", - "build": "vite build", - "minify": "vite build --minify", - "preview": "vite preview", - "check": "svelte-check --tsconfig ./tsconfig.json", - "test": "vitest", - "eslint": "eslint .", - "lint": "prettier --check . && eslint .", - "format": "prettier --write ." - }, - "type": "module" + "name": "vite_app", + "version": "0.0.0", + "devDependencies": { + "@sveltejs/vite-plugin-svelte": "^3.0.2", + "@tsconfig/svelte": "^5.0.2", + "autoprefixer": "^10.4.19", + "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-svelte": "^2.35.1", + "postcss": "^8.4.38", + "prettier": "^3.1.1", + "prettier-plugin-svelte": "^3.1.2", + "prettier-plugin-tailwindcss": "^0.5.13", + "svelte": "^4.2.12", + "svelte-check": "^3.6.7", + "tailwindcss": "^3.4.4", + "tslib": "^2.6.2", + "typescript": "^5.4.3", + "typescript-eslint": "^7.4.0", + "vite": "^5.2.0", + "vite-tsconfig-paths": "^4.3.2", + "vitest": "^1.2.0" + }, + "private": true, + "scripts": { + "dev": "vite build --watch --mode development", + "watch": "vite build --watch --mode development", + "build": "vite build", + "minify": "vite build --minify", + "preview": "vite preview", + "check": "svelte-check --tsconfig ./tsconfig.json", + "test": "vitest", + "eslint": "eslint .", + "lint": "prettier --check . && eslint .", + "format": "prettier --write ." + }, + "type": "module" } diff --git a/app/src/lib/Util/functions.ts b/app/src/lib/Util/functions.ts index 58f079c..f4bda37 100644 --- a/app/src/lib/Util/functions.ts +++ b/app/src/lib/Util/functions.ts @@ -819,7 +819,7 @@ export function launchOfficialClient( saveConfig(); const launchPath: string = `/launch-${osrs ? 'osrs' : 'rs3'}-${windows ? 'exe' : 'macapp'}?`; const metaPath: string = `${osrs ? 'osrs' : atob(boltSub.provider)}-${windows ? 'win' : 'mac'}`; - const primaryUrl: string = `${atob(boltSub.direct6_url)}${metaPath}/${metaPath}.json` + const primaryUrl: string = `${atob(boltSub.direct6_url)}${metaPath}/${metaPath}.json`; const launch = (hash?: string, exe?: Blob) => { const xml = new XMLHttpRequest(); @@ -851,7 +851,8 @@ export function launchOfficialClient( xml.onreadystatechange = () => { if (xml.readyState == 4) { if (xml.status == 200) { - const metaToken: Direct6Token = JSON.parse(atob(xml.responseText.split('.')[1])).environments.production; + const metaToken: Direct6Token = JSON.parse(atob(xml.responseText.split('.')[1])) + .environments.production; // TODO: check here if metaToken.id matches the already-installed version, if it does, just launch straight away msg(`Downloading client version ${metaToken.version}...`); const catalogUrl: string = `${atob(boltSub.direct6_url)}${metaPath}/catalog/${metaToken.id}/catalog.json`; @@ -861,42 +862,62 @@ export function launchOfficialClient( if (xml2.readyState == 4) { if (xml2.status == 200) { const catalog = JSON.parse(atob(xml2.responseText.split('.')[1])); - const metafileUrl = catalog.metafile.replace("http:", "https:"); + const metafileUrl = catalog.metafile.replace('http:', 'https:'); const xml3 = new XMLHttpRequest(); xml3.open('GET', metafileUrl, true); xml3.onreadystatechange = () => { if (xml3.readyState == 4) { if (xml3.status == 200) { const metafile = JSON.parse(atob(xml3.responseText.split('.')[1])); - const chunk_promises: Promise[] = metafile.pieces.digests.map((x: string) => { - const hex_chunk: string = atob(x).split("").map(c => c.charCodeAt(0).toString(16).padStart(2, "0")).join(""); - const chunk_url: string = catalog.config.remote.baseUrl.replace("http:", "https:").concat(catalog.config.remote.pieceFormat.replace("{SubString:0,2,{TargetDigest}}", hex_chunk.substring(0, 2)).replace("{TargetDigest}", hex_chunk)); - return new Promise((resolve, reject) => { - const xml = new XMLHttpRequest(); - xml.open('GET', chunk_url, true); - xml.responseType = 'blob'; - xml.onreadystatechange = () => { - if (xml.readyState == 4) { - if (xml.status == 200) { - const ds = new DecompressionStream("gzip"); - new Response(xml.response.slice(6).stream().pipeThrough(ds)).blob().then(resolve); - } else { - reject(`Error from ${chunk_url}: ${xml.status}: ${xml.responseText}`); + const chunk_promises: Promise[] = metafile.pieces.digests.map( + (x: string) => { + const hex_chunk: string = atob(x) + .split('') + .map((c) => c.charCodeAt(0).toString(16).padStart(2, '0')) + .join(''); + const chunk_url: string = catalog.config.remote.baseUrl + .replace('http:', 'https:') + .concat( + catalog.config.remote.pieceFormat + .replace('{SubString:0,2,{TargetDigest}}', hex_chunk.substring(0, 2)) + .replace('{TargetDigest}', hex_chunk) + ); + return new Promise((resolve, reject) => { + const xml = new XMLHttpRequest(); + xml.open('GET', chunk_url, true); + xml.responseType = 'blob'; + xml.onreadystatechange = () => { + if (xml.readyState == 4) { + if (xml.status == 200) { + const ds = new DecompressionStream('gzip'); + new Response(xml.response.slice(6).stream().pipeThrough(ds)) + .blob() + .then(resolve); + } else { + reject( + `Error from ${chunk_url}: ${xml.status}: ${xml.responseText}` + ); + } } - } - } - xml.send(); - }); - }); + }; + xml.send(); + }); + } + ); // while all that stuff is downloading, let's read the file list and find the exe's location in the data blob var exeOffset: number = 0; var exeSize: number | null = null; for (let i = 0; i < metafile.files.length; i += 1) { - const isTargetExe: boolean = windows ? metafile.files[i].name.endsWith(".exe") : metafile.files[i].name.includes(".app/Contents/MacOS/"); + const isTargetExe: boolean = windows + ? metafile.files[i].name.endsWith('.exe') + : metafile.files[i].name.includes('.app/Contents/MacOS/'); if (isTargetExe) { if (exeSize !== null) { - err(`Error parsing ${metafileUrl}: file list has multiple possibilities for main exe`, false); + err( + `Error parsing ${metafileUrl}: file list has multiple possibilities for main exe`, + false + ); return; } else { exeSize = metafile.files[i].size; @@ -906,11 +927,14 @@ export function launchOfficialClient( } } if (exeSize === null) { - err(`Error parsing ${metafileUrl}: file list has no possibilities for main exe`, false); + err( + `Error parsing ${metafileUrl}: file list has no possibilities for main exe`, + false + ); return; } - Promise.all(chunk_promises).then(x => { + Promise.all(chunk_promises).then((x) => { const exeFile = new Blob(x).slice(exeOffset, exeOffset + exeSize); launch(metafile.id, exeFile); });