feat(mc-mods): impl download action
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
7d7180b0aa
commit
a3355725ea
1 changed files with 30 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
import { createWriteStream, mkdirSync, rmSync } from 'fs';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
interface Hashes {
|
interface Hashes {
|
||||||
sha1: string
|
sha1: string
|
||||||
sha512: string
|
sha512: string
|
||||||
|
@ -88,6 +91,9 @@ const showModDownloadUrls = async(modName: string): Promise<boolean> => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const download = async(url: string, path: string) => Readable
|
||||||
|
.fromWeb((await fetch(url)).body!).pipe(createWriteStream(path));
|
||||||
|
|
||||||
const main = () => {
|
const main = () => {
|
||||||
const mods = [
|
const mods = [
|
||||||
'badpackets',
|
'badpackets',
|
||||||
|
@ -112,7 +118,30 @@ const main = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// TODO: add download action
|
else if (action === 'download') {
|
||||||
|
rmSync('./out', { force: true, recursive: true });
|
||||||
|
mkdirSync('./out');
|
||||||
|
|
||||||
|
mods.forEach(async(modName) => {
|
||||||
|
const ver = await checkModCompat(modName);
|
||||||
|
|
||||||
|
if (ver === null) {
|
||||||
|
console.error(`No matching releases of ${modName} were found for ${game_version}`);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName =
|
||||||
|
`${modName}-${ver.version_number}.jar`;
|
||||||
|
|
||||||
|
console.log(`Downloading ${fileName}`);
|
||||||
|
|
||||||
|
await download(
|
||||||
|
ver.files[0].url,
|
||||||
|
`./out/${fileName}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Add table
Reference in a new issue