mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-24 06:34:18 +01:00
add 7z in-memory streaming
This commit is contained in:
28 files changed
+930
-225
No files matched your search
@@ -1,4 +0,0 @@
|
||||
export const WGC_CLIENT_GUID = "WOTB.WW.PRODUCTION";
|
||||
export const WGC_CLIENT_URL = "https://wgus-eu.wargaming.net";
|
||||
export const WGC_METADATA_PROTOCOL_VERSION = "7.10";
|
||||
export const WGC_PATCHES_CHAIN_PROTOCOL_VERSION = "1.11";
|
||||
@@ -1,9 +0,0 @@
|
||||
// dava engine has a lot of tiny files, this is faster
|
||||
export const DEPOT_DOWNLOADER_MAX_DOWNLOADS = 256;
|
||||
export const DEPOT_DOWNLOADER_OUTPUT = "../../temp/depotdownloader";
|
||||
export const DEPOT_DOWNLOADER_EXECUTABLE = `${DEPOT_DOWNLOADER_OUTPUT}/DepotDownloader`;
|
||||
|
||||
export const ARIA2_OUTPUT = "../../temp/aria2";
|
||||
export const ARIA2_EXECUTABLE = `${ARIA2_OUTPUT}/aria2c`;
|
||||
|
||||
export const WGPKG_DIR = "../../temp/wgpkgs";
|
||||
@@ -1,37 +0,0 @@
|
||||
import { assertSecret } from "@blitzkit/core";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { downloadSteamClient } from "./steam";
|
||||
import { downloadWGCClient } from "./wgc";
|
||||
import { downloadWGPKGClient } from "./wgpkg";
|
||||
|
||||
export const DEPOT_DOWNLOADER_RETRY_TIME = 30_000;
|
||||
|
||||
const provider = import.meta.env.CLIENT_PROVIDER;
|
||||
export const source = import.meta.env.CLIENT_SOURCE;
|
||||
export const dir = assertSecret(import.meta.env.CLIENT_DIR);
|
||||
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
await mkdir(dir, { recursive: true });
|
||||
|
||||
switch (provider) {
|
||||
// steam, identical to wgc
|
||||
case "steam":
|
||||
await downloadSteamClient();
|
||||
break;
|
||||
|
||||
// from zip, read remotely by ZipVFS at build time; nothing to download
|
||||
case "zip":
|
||||
console.log("Zip client provider; skipping download in favor of ZipVFS");
|
||||
break;
|
||||
|
||||
// effectively the same as wgc, but direct for preview
|
||||
case "wgpkg":
|
||||
await downloadWGPKGClient();
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log("Unknown client provider specified, using latest wgc client");
|
||||
case "wgc":
|
||||
await downloadWGCClient();
|
||||
break;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export interface QuickGitHubRelease {
|
||||
assets: Asset[];
|
||||
}
|
||||
|
||||
interface Asset {
|
||||
name: string;
|
||||
browser_download_url: string;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { XMLParser } from "fast-xml-parser";
|
||||
import {
|
||||
WGC_CLIENT_GUID,
|
||||
WGC_CLIENT_URL,
|
||||
WGC_METADATA_PROTOCOL_VERSION,
|
||||
WGC_PATCHES_CHAIN_PROTOCOL_VERSION,
|
||||
} from "../../config/wgcClient";
|
||||
import { downloadWgParts } from "../wgpkg";
|
||||
import { ClientMetadata, PatchesChain } from "./types";
|
||||
|
||||
const parser = new XMLParser();
|
||||
|
||||
export async function downloadWGCClient() {
|
||||
const metadataUrl = new URL("api/v1/metadata", WGC_CLIENT_URL);
|
||||
|
||||
metadataUrl.searchParams.set("guid", WGC_CLIENT_GUID);
|
||||
metadataUrl.searchParams.set("chain_id", "unknown");
|
||||
metadataUrl.searchParams.set(
|
||||
"protocol_version",
|
||||
WGC_METADATA_PROTOCOL_VERSION,
|
||||
);
|
||||
|
||||
const metadata = await fetch(`${metadataUrl}`)
|
||||
.then((response) => response.text())
|
||||
.then((text) => parser.parse(text) as Promise<ClientMetadata>);
|
||||
|
||||
const patchesChainUrl = new URL("api/v1/patches_chain", WGC_CLIENT_URL);
|
||||
|
||||
patchesChainUrl.searchParams.set(
|
||||
"protocol_version",
|
||||
WGC_PATCHES_CHAIN_PROTOCOL_VERSION,
|
||||
);
|
||||
patchesChainUrl.searchParams.set("client_type", "full");
|
||||
patchesChainUrl.searchParams.set("lang", locales.default);
|
||||
patchesChainUrl.searchParams.set(
|
||||
"metadata_version",
|
||||
`${metadata.protocol.version}`,
|
||||
);
|
||||
patchesChainUrl.searchParams.set(
|
||||
"metadata_protocol_version",
|
||||
WGC_METADATA_PROTOCOL_VERSION,
|
||||
);
|
||||
patchesChainUrl.searchParams.set(
|
||||
"chain_id",
|
||||
metadata.protocol.predefined_section.chain_id,
|
||||
);
|
||||
patchesChainUrl.searchParams.set("game_installation", "true");
|
||||
patchesChainUrl.searchParams.set("game_id", WGC_CLIENT_GUID);
|
||||
patchesChainUrl.searchParams.set("client_current_version", "0");
|
||||
|
||||
const patchesChain = await fetch(`${patchesChainUrl}`)
|
||||
.then((response) => response.text())
|
||||
.then((text) => parser.parse(text) as Promise<PatchesChain>);
|
||||
|
||||
const urls = patchesChain.protocol.patches_chain.patch.files.file.map(
|
||||
(file) =>
|
||||
new URL(file.name, patchesChain.protocol.web_seeds.url).toString(),
|
||||
);
|
||||
|
||||
await downloadWgParts(urls);
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
export interface ClientMetadata {
|
||||
protocol: {
|
||||
version: number;
|
||||
predefined_section: PredefinedSection;
|
||||
generated_section: GeneratedSection;
|
||||
};
|
||||
}
|
||||
|
||||
interface GeneratedSection {
|
||||
launch_forbidden: string;
|
||||
stop_supporting: string;
|
||||
}
|
||||
|
||||
interface PredefinedSection {
|
||||
app_id: string;
|
||||
chain_id: string;
|
||||
supported_languages: string;
|
||||
default_language: string;
|
||||
name: string;
|
||||
fs_name: string;
|
||||
shortcut_name: string;
|
||||
executables: { executable: string };
|
||||
keep_patches_interval: number;
|
||||
client_types: { client_type: ClientType };
|
||||
login_enabled: boolean;
|
||||
realms_settings: RealmsSettings;
|
||||
localization: Localization;
|
||||
}
|
||||
|
||||
interface ClientType {
|
||||
initial_app_type: string;
|
||||
final_app_type: string;
|
||||
min_supported_os: string;
|
||||
client_parts: { client_part: string };
|
||||
}
|
||||
|
||||
interface Localization {
|
||||
item: { text: string[] };
|
||||
}
|
||||
|
||||
interface RealmsSettings {
|
||||
instances: { instance: Instance[] };
|
||||
}
|
||||
|
||||
interface Instance {
|
||||
game_id: string;
|
||||
title_id: string;
|
||||
platform_realm_id: string;
|
||||
options: { option: string };
|
||||
content_service_url: string;
|
||||
}
|
||||
|
||||
export interface PatchesChain {
|
||||
protocol: {
|
||||
parts_info: { part: Part };
|
||||
patches_chain: { patch: Patch };
|
||||
delay_preload: string;
|
||||
web_seeds: { url: string };
|
||||
meta_need_update: string;
|
||||
version_name: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface Part {
|
||||
name: string;
|
||||
version: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
interface Patch {
|
||||
files: { file: File[] };
|
||||
torrent: Torrent;
|
||||
part: string;
|
||||
version_from: number;
|
||||
version_to: string;
|
||||
}
|
||||
|
||||
interface File {
|
||||
name: string;
|
||||
size: number;
|
||||
unpacked_size: number;
|
||||
}
|
||||
|
||||
interface Torrent {
|
||||
hash: string;
|
||||
urls: { url: string };
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
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 downloadWgParts(urls);
|
||||
}
|
||||
|
||||
export async function downloadWgParts(urls: string[]) {
|
||||
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 });
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
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