mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 15:52:55 +01:00
move server funcs to init
This commit is contained in:
1 parent
5f737d940d
commit
5c89bcea99
5 files changed
+24
-11
No files matched your search
@@ -1,14 +1,23 @@
|
|||||||
import { readDVPL } from "@blitzkit/core";
|
import { readDVPL } from "@blitzkit/core";
|
||||||
import { Options, parse as parseCSV } from "csv-parse/sync";
|
import { Options, parse as parseCSV } from "csv-parse/browser/esm/sync";
|
||||||
import { XMLParser } from "fast-xml-parser";
|
import { XMLParser } from "fast-xml-parser";
|
||||||
import { normalize } from "path/posix";
|
import type { normalize } from "node:path/posix";
|
||||||
import { parse as parseYaml } from "yaml";
|
import { parse as parseYaml } from "yaml";
|
||||||
|
|
||||||
export abstract class AbstractVFS {
|
export abstract class AbstractVFS {
|
||||||
textDecoder = new TextDecoder();
|
textDecoder = new TextDecoder();
|
||||||
private xmlParser = new XMLParser();
|
private xmlParser = new XMLParser();
|
||||||
|
|
||||||
abstract init(): Promise<typeof this>;
|
protected normalizePath?: typeof normalize;
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
const path = await import("node:path/posix");
|
||||||
|
this.normalizePath = path.normalize;
|
||||||
|
|
||||||
|
await this._init();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract _init(): Promise<typeof this>;
|
||||||
|
|
||||||
abstract dispose(): void;
|
abstract dispose(): void;
|
||||||
|
|
||||||
@@ -17,7 +26,7 @@ export abstract class AbstractVFS {
|
|||||||
abstract raw(path: string): Promise<Uint8Array<ArrayBuffer>>;
|
abstract raw(path: string): Promise<Uint8Array<ArrayBuffer>>;
|
||||||
|
|
||||||
async resolve(path: string) {
|
async resolve(path: string) {
|
||||||
const normalized = normalize(path);
|
const normalized = this.normalizePath!(path);
|
||||||
if (await this.has(normalized)) return normalized;
|
if (await this.has(normalized)) return normalized;
|
||||||
|
|
||||||
const dvplPath = `${normalized}.dvpl`;
|
const dvplPath = `${normalized}.dvpl`;
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import { readdir } from "node:fs/promises";
|
import type { readdir } from "node:fs/promises";
|
||||||
import { AbstractVFS } from "./abstract";
|
import { AbstractVFS } from "./abstract";
|
||||||
|
|
||||||
export class LocalVFS extends AbstractVFS {
|
export class LocalVFS extends AbstractVFS {
|
||||||
|
protected readdir?: typeof readdir;
|
||||||
|
|
||||||
constructor(private base: string) {
|
constructor(private base: string) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async _init() {
|
||||||
|
const path = await import("node:path/posix");
|
||||||
|
this.normalizePath = path.normalize;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +30,7 @@ export class LocalVFS extends AbstractVFS {
|
|||||||
|
|
||||||
async _dir(path: string) {
|
async _dir(path: string) {
|
||||||
try {
|
try {
|
||||||
return await readdir(`${this.base}/${path}`);
|
return await this.readdir!(`${this.base}/${path}`);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export class MixedVFS extends AbstractVFS {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async _init() {
|
||||||
for (const vfs of this.vfses) {
|
for (const vfs of this.vfses) {
|
||||||
await vfs.init();
|
await vfs.init();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export class SteamVFS extends AbstractVFS {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async _init() {
|
||||||
this.steam.logOn({
|
this.steam.logOn({
|
||||||
accountName: this.username,
|
accountName: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
@@ -57,7 +57,6 @@ export class SteamVFS extends AbstractVFS {
|
|||||||
this.steam.getManifest(
|
this.steam.getManifest(
|
||||||
this.app,
|
this.app,
|
||||||
this.depot,
|
this.depot,
|
||||||
// @ts-expect-error
|
|
||||||
productInfo.apps[this.app].appinfo.depots[this.depot].manifests.public
|
productInfo.apps[this.app].appinfo.depots[this.depot].manifests.public
|
||||||
.gid,
|
.gid,
|
||||||
"public",
|
"public",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export class ZipVFS extends AbstractVFS {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async _init() {
|
||||||
const reader = new HTTPRangeReader(this.url);
|
const reader = new HTTPRangeReader(this.url);
|
||||||
const { entries } = await unzip(reader);
|
const { entries } = await unzip(reader);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user