mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
move server funcs to init 2
This commit is contained in:
1 parent
5c89bcea99
commit
8c08a00d64
4 files changed
+17
-10
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import { AbstractVFS, BlitzKitAPI } from "@blitzkit/core";
|
import { AbstractVFS, BlitzKitAPI } from "@blitzkit/core";
|
||||||
|
|
||||||
export async function createDynamicAPI(vfs: AbstractVFS) {
|
export async function createDynamicAPI(vfs: () => Promise<AbstractVFS>) {
|
||||||
let _api: BlitzKitAPI;
|
let _api: BlitzKitAPI;
|
||||||
|
|
||||||
if (import.meta.env.SSR) {
|
if (import.meta.env.SSR) {
|
||||||
@@ -8,7 +8,7 @@ export async function createDynamicAPI(vfs: AbstractVFS) {
|
|||||||
"@blitzkit/core/src/blitzkit/api/server/index"
|
"@blitzkit/core/src/blitzkit/api/server/index"
|
||||||
);
|
);
|
||||||
|
|
||||||
_api = await new ServerBlitzKitAPI(vfs).init();
|
_api = await new ServerBlitzKitAPI(await vfs()).init();
|
||||||
} else {
|
} else {
|
||||||
const { ClientBlitzKitAPI } = await import(
|
const { ClientBlitzKitAPI } = await import(
|
||||||
"@blitzkit/core/src/blitzkit/api/client"
|
"@blitzkit/core/src/blitzkit/api/client"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import SteamUser, { EConnectionProtocol } from "steam-user";
|
import type SteamUser from "steam-user";
|
||||||
import { AbstractVFS } from "./abstract";
|
import { AbstractVFS } from "./abstract";
|
||||||
|
|
||||||
interface SteamManifestFile {
|
interface SteamManifestFile {
|
||||||
@@ -31,7 +31,7 @@ interface SteamManifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SteamVFS extends AbstractVFS {
|
export class SteamVFS extends AbstractVFS {
|
||||||
private steam = new SteamUser({ protocol: EConnectionProtocol.TCP });
|
private steam?: SteamUser;
|
||||||
private manifest: Map<string, SteamManifestFile> = new Map();
|
private manifest: Map<string, SteamManifestFile> = new Map();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -44,12 +44,17 @@ export class SteamVFS extends AbstractVFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _init() {
|
async _init() {
|
||||||
|
const steamUser = await import("steam-user");
|
||||||
|
|
||||||
|
this.steam = new steamUser.default({
|
||||||
|
protocol: steamUser.EConnectionProtocol.TCP,
|
||||||
|
});
|
||||||
this.steam.logOn({
|
this.steam.logOn({
|
||||||
accountName: this.username,
|
accountName: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise((resolve) => this.steam.once("loggedOn", resolve));
|
await new Promise((resolve) => this.steam!.once("loggedOn", resolve));
|
||||||
|
|
||||||
const productInfo = await this.steam.getProductInfo([this.app], []);
|
const productInfo = await this.steam.getProductInfo([this.app], []);
|
||||||
const manifest: SteamManifest = await new Promise((resolve) => {
|
const manifest: SteamManifest = await new Promise((resolve) => {
|
||||||
@@ -105,6 +110,6 @@ export class SteamVFS extends AbstractVFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this.steam.logOff();
|
this.steam!.logOff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { normalize } from "path/posix";
|
|
||||||
import { HTTPRangeReader, unzip, ZipEntry } from "unzipit";
|
import { HTTPRangeReader, unzip, ZipEntry } from "unzipit";
|
||||||
import { AbstractVFS } from "./abstract";
|
import { AbstractVFS } from "./abstract";
|
||||||
|
|
||||||
@@ -17,7 +16,9 @@ export class ZipVFS extends AbstractVFS {
|
|||||||
const { entries } = await unzip(reader);
|
const { entries } = await unzip(reader);
|
||||||
|
|
||||||
for (const entry of Object.values(entries)) {
|
for (const entry of Object.values(entries)) {
|
||||||
const normalized = normalize(entry.name.slice(this.root.length));
|
const normalized = this.normalizePath!(
|
||||||
|
entry.name.slice(this.root.length),
|
||||||
|
);
|
||||||
this.entries.set(normalized, entry);
|
this.entries.set(normalized, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { createDynamicAPI } from "@blitzkit/core";
|
import { createDynamicAPI } from "@blitzkit/core";
|
||||||
import { vfs } from "./vfs";
|
|
||||||
|
|
||||||
export const api = await createDynamicAPI(vfs);
|
export const api = await createDynamicAPI(() =>
|
||||||
|
import("./vfs").then(({ vfs }) => vfs),
|
||||||
|
);
|
||||||
Reference in new issue
Block a user