Files
blitzkit/packages/vfs/src/client.ts
T

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-11-14 11:16:49 -06:00
import { assertSecret } from "@blitzkit/core";
2026-11-23 20:27:55 -06:00
import { fetchWGCClientSource } from "./fetchWGCClientSource";
2026-11-14 11:28:46 -06:00
import { AbstractVFS } from "./abstract";
2026-11-14 11:16:49 -06:00
import { LocalVFS } from "./local";
2026-11-23 19:28:51 -06:00
import { MixedVFS } from "./mixed";
import { SevenZipVFS } from "./sevenZip";
2026-11-14 11:16:49 -06:00
import { ZipVFS } from "./zip";
2026-11-14 11:28:46 -06:00
export async function createClientVFS() {
2026-11-23 19:28:51 -06:00
const provider = import.meta.env.CLIENT_PROVIDER;
2026-11-14 11:28:46 -06:00
let vfs: AbstractVFS;
2026-11-14 11:16:49 -06:00
2026-11-23 19:28:51 -06:00
if (provider === "zip") {
2026-11-14 11:28:46 -06:00
vfs = new ZipVFS(assertSecret(import.meta.env.CLIENT_SOURCE));
2026-11-23 19:28:51 -06:00
} else if (provider === "7z") {
vfs = new SevenZipVFS(assertSecret(import.meta.env.CLIENT_SOURCE));
} else if (provider === "wgc") {
vfs = new SevenZipVFS(await fetchWGCClientSource());
} else if (provider === "local") {
2026-11-14 11:28:46 -06:00
vfs = new LocalVFS(assertSecret(import.meta.env.CLIENT_DIR));
2026-11-23 19:28:51 -06:00
} else {
throw new Error(`Unknown client provider: ${provider}`);
2026-11-14 11:16:49 -06:00
}
2026-11-23 19:28:51 -06:00
// smart dlc patches take precedence over the client
const smartDlcDir = import.meta.env.SMART_DLC_DIR;
2026-11-14 11:28:46 -06:00
2026-11-23 19:28:51 -06:00
if (smartDlcDir) {
vfs = new MixedVFS([new LocalVFS(smartDlcDir), vfs]);
}
return await vfs.init();
2026-11-14 11:16:49 -06:00
}