feat: make assets' task accessible

This commit is contained in:
HerozDotExe 2025-11-01 23:24:44 +01:00
parent 71ccc0cbeb
commit 53c0f504e6
3 changed files with 12 additions and 8 deletions

View file

@ -4,7 +4,7 @@ import { AssetIndex, PoolFile, Version } from "../utils/types";
import fs from "fs/promises";
import { downloadFile, DownloadPool } from "../utils/fetch";
export async function download(destination: string, versionManifest: Version) {
export async function AssetsDownloader(destination: string, versionManifest: Version) {
await ensureDir(path.join(destination, "indexes"));
await ensureDir(path.join(destination, "objects"));
@ -14,7 +14,7 @@ export async function download(destination: string, versionManifest: Version) {
`${versionManifest.assetIndex.id}.json`,
);
if (!await exists(assetIndexPath)) {
if (!(await exists(assetIndexPath))) {
await downloadFile({
url: versionManifest.assetIndex.url,
path: assetIndexPath,
@ -35,7 +35,7 @@ export async function download(destination: string, versionManifest: Version) {
const assetPath = path.join(destination, "objects", subhash, asset.hash);
const assetURL = `https://resources.download.minecraft.net/${asset.hash.substring(0, 2)}/${asset.hash}`;
await ensureDir(path.dirname(assetPath))
await ensureDir(path.dirname(assetPath));
files.push({ url: assetURL, path: assetPath });
}
@ -43,5 +43,5 @@ export async function download(destination: string, versionManifest: Version) {
const dPool = new DownloadPool(files, 5);
await dPool.run();
}
return dPool;
}

View file

@ -2,6 +2,7 @@ export * as java from "./java";
export * as version from "./version";
export * as natives from "./natives";
export * as libraries from "./libraries";
export * as assets from "./assets";
export * as arguments from "./arguments"
export * as log4j from "./log4j"
export * as log4j from "./log4j"
export {AssetsDownloader} from "./assets";

View file

@ -24,7 +24,10 @@ test(
{ timeout: 60 * 1000 },
async () => {
const versionManifest = await nlk.core.version.getVersionManifest("1.21.8");
await nlk.core.assets.download(assetsPath, versionManifest);
const assetsDownloader = await nlk.core.AssetsDownloader(assetsPath, versionManifest);
assetsDownloader.progressCallback = console.log
await assetsDownloader.run()
expect(
await exists(path.join(assetsPath, "objects", "00", "00c9fa8115347fb0220aaf72a8d7d921f5354112")),