mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-10 11:16:10 +01:00
code split download client
This commit is contained in:
4 files changed
+133
-104
No files matched your search
@@ -1,117 +1,31 @@
|
|||||||
import { assertSecret } from "@blitzkit/core";
|
import { assertSecret } from "@blitzkit/core";
|
||||||
import { $ } from "bun";
|
|
||||||
import { mkdir, rm } from "node:fs/promises";
|
import { mkdir, rm } from "node:fs/promises";
|
||||||
import {
|
import { downloadSteamClient } from "./steam";
|
||||||
DEPOT_DOWNLOADER_EXECUTABLE,
|
import { downloadWGPKGClient } from "./wgpkg";
|
||||||
DEPOT_DOWNLOADER_MAX_DOWNLOADS,
|
import { downloadZipClient } from "./zip";
|
||||||
DEPOT_DOWNLOADER_OUTPUT,
|
|
||||||
WGPKG_DIR,
|
|
||||||
} from "./constants";
|
|
||||||
import { QuickGitHubRelease } from "./types";
|
|
||||||
|
|
||||||
const DEPOT_DOWNLOADER_RETRY_TIME = 30_000;
|
export const DEPOT_DOWNLOADER_RETRY_TIME = 30_000;
|
||||||
|
|
||||||
const provider = assertSecret(import.meta.env.CLIENT_PROVIDER);
|
const provider = assertSecret(import.meta.env.CLIENT_PROVIDER);
|
||||||
const source = assertSecret(import.meta.env.CLIENT_SOURCE);
|
export const source = assertSecret(import.meta.env.CLIENT_SOURCE);
|
||||||
const dir = assertSecret(import.meta.env.CLIENT_DIR);
|
export const dir = assertSecret(import.meta.env.CLIENT_DIR);
|
||||||
|
|
||||||
await rm(dir, { recursive: true, force: true });
|
await rm(dir, { recursive: true, force: true });
|
||||||
await mkdir(dir, { recursive: true });
|
await mkdir(dir, { recursive: true });
|
||||||
|
|
||||||
if (provider === "steam") {
|
switch (provider) {
|
||||||
const [id, platform] = source.split("/");
|
case "steam":
|
||||||
|
await downloadSteamClient();
|
||||||
|
break;
|
||||||
|
|
||||||
console.log("Downloading Depot Downloader...");
|
case "zip":
|
||||||
|
await downloadZipClient();
|
||||||
|
break;
|
||||||
|
|
||||||
const releases = await fetch(
|
case "wgpkg":
|
||||||
"https://api.github.com/repos/SteamRE/DepotDownloader/releases/latest",
|
await downloadWGPKGClient();
|
||||||
).then((response) => response.json() as Promise<QuickGitHubRelease>);
|
break;
|
||||||
const asset = releases.assets.find((asset) =>
|
|
||||||
asset.name.includes("linux-x64"),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!asset) {
|
default:
|
||||||
throw new Error("No linux-x64 asset found for Steam DepotDownloader");
|
throw new Error(`Unknown provider: ${provider}`);
|
||||||
}
|
|
||||||
|
|
||||||
await rm(DEPOT_DOWNLOADER_OUTPUT, { recursive: true, force: true });
|
|
||||||
|
|
||||||
await $`curl -L "${asset.browser_download_url}" -o "${DEPOT_DOWNLOADER_OUTPUT}.zip"`;
|
|
||||||
await $`unzip "${DEPOT_DOWNLOADER_OUTPUT}.zip" -d "${DEPOT_DOWNLOADER_OUTPUT}"`;
|
|
||||||
await $`chmod +x "${DEPOT_DOWNLOADER_EXECUTABLE}"`;
|
|
||||||
|
|
||||||
console.log("Downloading client...");
|
|
||||||
|
|
||||||
const username = assertSecret(import.meta.env.STEAM_USERNAME);
|
|
||||||
const password = assertSecret(import.meta.env.STEAM_PASSWORD);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const result = await $`${
|
|
||||||
DEPOT_DOWNLOADER_EXECUTABLE
|
|
||||||
} -os ${platform} -app ${id} -username ${
|
|
||||||
username
|
|
||||||
} -password ${password} -dir ${dir} -max-downloads ${
|
|
||||||
DEPOT_DOWNLOADER_MAX_DOWNLOADS
|
|
||||||
}`.nothrow();
|
|
||||||
|
|
||||||
if (result.exitCode === 0) {
|
|
||||||
console.log("Client downloaded successfully!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.error(
|
|
||||||
`DepotDownloader failed (exit ${result.exitCode}). Retrying in ${DEPOT_DOWNLOADER_RETRY_TIME / 1000} seconds...`,
|
|
||||||
);
|
|
||||||
await new Promise((resolve) =>
|
|
||||||
setTimeout(resolve, DEPOT_DOWNLOADER_RETRY_TIME),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else if (provider === "zip") {
|
|
||||||
const url = assertSecret(import.meta.env.CLIENT_SOURCE);
|
|
||||||
|
|
||||||
console.log("Downloading and extracting zipped client...");
|
|
||||||
|
|
||||||
await mkdir(dir, { recursive: true });
|
|
||||||
await $`curl -L "${url}" | bsdtar -xf- --strip-components=1 -C ${dir}`;
|
|
||||||
} else if (provider === "wgpkg") {
|
|
||||||
let index = 1;
|
|
||||||
const urls: string[] = [];
|
|
||||||
|
|
||||||
console.log("Discovering packages...");
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const url = `${source}.${index.toString().padStart(3, "0")}`;
|
|
||||||
const response = await fetch(url);
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
|
||||||
urls.push(url);
|
|
||||||
} else if (response.status === 404) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
throw new Error(`Wargaming response error status: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Downloading ${urls.length} packages...`);
|
|
||||||
|
|
||||||
await rm(WGPKG_DIR, { recursive: true, force: true });
|
|
||||||
await mkdir(WGPKG_DIR, { recursive: true });
|
|
||||||
|
|
||||||
const inputContent = urls
|
|
||||||
.map((url) => {
|
|
||||||
const name = url.split("/").pop()!;
|
|
||||||
return `${url}\n out=${name}\n dir=${WGPKG_DIR}`;
|
|
||||||
})
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
await $`echo ${inputContent} | aria2c -j ${urls.length} -x 2 -s 2 -i -`;
|
|
||||||
|
|
||||||
const firstChunk = `${WGPKG_DIR}/${urls[0].split("/").pop()!}`;
|
|
||||||
await $`7z x "${firstChunk}" -o${dir} -y`;
|
|
||||||
|
|
||||||
await rm(WGPKG_DIR, { recursive: true });
|
|
||||||
} else {
|
|
||||||
throw new Error(`Unknown provider: ${provider}`);
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { assertSecret } from "@blitzkit/core";
|
||||||
|
import { $ } from "bun";
|
||||||
|
import { rm } from "node:fs/promises";
|
||||||
|
import { DEPOT_DOWNLOADER_RETRY_TIME, dir, source } from ".";
|
||||||
|
import {
|
||||||
|
DEPOT_DOWNLOADER_EXECUTABLE,
|
||||||
|
DEPOT_DOWNLOADER_MAX_DOWNLOADS,
|
||||||
|
DEPOT_DOWNLOADER_OUTPUT,
|
||||||
|
} from "./constants";
|
||||||
|
import { QuickGitHubRelease } from "./types";
|
||||||
|
|
||||||
|
export async function downloadSteamClient() {
|
||||||
|
const [id, platform] = source.split("/");
|
||||||
|
|
||||||
|
console.log("Downloading Depot Downloader...");
|
||||||
|
|
||||||
|
const releases = await fetch(
|
||||||
|
"https://api.github.com/repos/SteamRE/DepotDownloader/releases/latest",
|
||||||
|
).then((response) => response.json() as Promise<QuickGitHubRelease>);
|
||||||
|
const asset = releases.assets.find((asset) =>
|
||||||
|
asset.name.includes("linux-x64"),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!asset) {
|
||||||
|
throw new Error("No linux-x64 asset found for Steam DepotDownloader");
|
||||||
|
}
|
||||||
|
|
||||||
|
await rm(DEPOT_DOWNLOADER_OUTPUT, { recursive: true, force: true });
|
||||||
|
|
||||||
|
await $`curl -L "${asset.browser_download_url}" -o "${DEPOT_DOWNLOADER_OUTPUT}.zip"`;
|
||||||
|
await $`unzip "${DEPOT_DOWNLOADER_OUTPUT}.zip" -d "${DEPOT_DOWNLOADER_OUTPUT}"`;
|
||||||
|
await $`chmod +x "${DEPOT_DOWNLOADER_EXECUTABLE}"`;
|
||||||
|
|
||||||
|
console.log("Downloading client...");
|
||||||
|
|
||||||
|
const username = assertSecret(import.meta.env.STEAM_USERNAME);
|
||||||
|
const password = assertSecret(import.meta.env.STEAM_PASSWORD);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const result =
|
||||||
|
await $`${DEPOT_DOWNLOADER_EXECUTABLE} -os ${platform} -app ${id} -username ${username} -password ${password} -dir ${dir} -max-downloads ${DEPOT_DOWNLOADER_MAX_DOWNLOADS}`.nothrow();
|
||||||
|
|
||||||
|
if (result.exitCode === 0) {
|
||||||
|
console.log("Client downloaded successfully!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
`DepotDownloader failed (exit ${result.exitCode}). Retrying in ${
|
||||||
|
DEPOT_DOWNLOADER_RETRY_TIME / 1000
|
||||||
|
} seconds...`,
|
||||||
|
);
|
||||||
|
await new Promise((resolve) =>
|
||||||
|
setTimeout(resolve, DEPOT_DOWNLOADER_RETRY_TIME),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { $ } from "bun";
|
||||||
|
import { mkdir, rm } from "node:fs/promises";
|
||||||
|
import { dir, source } from ".";
|
||||||
|
import { WGPKG_DIR } from "./constants";
|
||||||
|
|
||||||
|
export async function downloadWGPKGClient() {
|
||||||
|
let index = 1;
|
||||||
|
const urls: string[] = [];
|
||||||
|
|
||||||
|
console.log("Discovering packages...");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const url = `${source}.${index.toString().padStart(3, "0")}`;
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
urls.push(url);
|
||||||
|
} else if (response.status === 404) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Wargaming response error status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Downloading ${urls.length} packages...`);
|
||||||
|
|
||||||
|
await rm(WGPKG_DIR, { recursive: true, force: true });
|
||||||
|
await mkdir(WGPKG_DIR, { recursive: true });
|
||||||
|
|
||||||
|
const inputContent = urls
|
||||||
|
.map((url) => {
|
||||||
|
const name = url.split("/").pop()!;
|
||||||
|
return `${url}\n out=${name}\n dir=${WGPKG_DIR}`;
|
||||||
|
})
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
await $`echo ${inputContent} | aria2c -j ${urls.length} -x 2 -s 2 -i -`;
|
||||||
|
|
||||||
|
const firstChunk = `${WGPKG_DIR}/${urls[0].split("/").pop()!}`;
|
||||||
|
await $`7z x "${firstChunk}" -o${dir} -y`;
|
||||||
|
|
||||||
|
await rm(WGPKG_DIR, { recursive: true });
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { assertSecret } from "@blitzkit/core";
|
||||||
|
import { $ } from "bun";
|
||||||
|
import { mkdir } from "node:fs/promises";
|
||||||
|
import { dir } from ".";
|
||||||
|
|
||||||
|
export async function downloadZipClient() {
|
||||||
|
const url = assertSecret(import.meta.env.CLIENT_SOURCE);
|
||||||
|
|
||||||
|
console.log("Downloading and extracting zipped client...");
|
||||||
|
|
||||||
|
await mkdir(dir, { recursive: true });
|
||||||
|
await $`curl -L "${url}" | bsdtar -xf- --strip-components=1 -C ${dir}`;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user