Added an upgrade command

This commit is contained in:
Kallum Jones
2022-08-07 14:03:34 +01:00
parent b801d59352
commit 39c1d72219
8 changed files with 175 additions and 97 deletions

View File

@ -1,8 +0,0 @@
declare global {
type DownloadTask = {
fileName: string,
url: string
}
}
export {}

View File

@ -6,14 +6,14 @@ import ModManager from "../mod-manager.js";
export default class FileDownloader {
static downloadMod(task: DownloadTask): void {
https.get(task.url, res => {
const filePath = path.join(ModManager.FilePaths.MODS_FOLDER_PATH, task.fileName);
static downloadMod(version: Version): void {
https.get(version.url, res => {
const filePath = path.join(ModManager.FilePaths.MODS_FOLDER_PATH, version.fileName);
const writeStream = createWriteStream(filePath);
res.pipe(writeStream);
writeStream.on("finish", () => writeStream.close());
writeStream.on('error', () => {
throw new DownloadError(`Failed to download ${task.fileName} from ${task.url}`)
throw new DownloadError(`Failed to download ${version.fileName} from ${version.url}`)
})
})
}