diff --git a/src/cdn/downloadUrlContents.ts b/src/cdn/downloadUrlContents.ts deleted file mode 100644 index dd8bd5f..0000000 --- a/src/cdn/downloadUrlContents.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as http from 'http'; -import saveResponse from './funcs/saveResponse'; - -/** Downloads the given URL and saves it to disk. Returns the location where file is saved under. Throws error if download fails. */ -export default function downloadUrlContents( - host: string, - path: string, - tempFileName: string, - resolve: (fileName: string) => void, - reject: (reason: Error | string) => void, -): void { - //Create HTTP request - const request = http.request({ - family: 4, - hostname: host, - path, - }, saveResponse.bind(null, tempFileName, resolve, (reason: string) => { request.abort(); reject(reason); })); - - //In case of connection errors, exit early - request.on('error', (error) => { - request.abort(); - reject(error); - }); - - request.end(); -} diff --git a/src/cdn/downloadWrapper.ts b/src/cdn/downloadWrapper.ts index 23f292e..0e5ae5a 100644 --- a/src/cdn/downloadWrapper.ts +++ b/src/cdn/downloadWrapper.ts @@ -1,12 +1,11 @@ import * as os from 'os'; import * as nodePath from 'path'; -import downloadUrlContents from './downloadUrlContents'; import downloadWithCurl from './downloadWithCurl'; import checkLocalCache from './funcs/checkLocalCache'; import createDirRecursively from './funcs/createDirRecursively'; /** Downloads the given URL and saves it to disk. Returns the location where file is saved under. Throws error if download fails. */ -export default async function downloadWrapper({ host, path, size, useCurl = false }: {host: string, path: string, size: number, useCurl: boolean}): Promise { +export default async function downloadWrapper({ host, path, size }: {host: string, path: string, size: number, useCurl: boolean}): Promise { //Generate file name we want to save it under //e.g. on Linux: /tmp/patcher/cdn-patch.swtor.com/patch/assets_swtor_main/assets_swtor_main_-1to0/assets_swtor_main_-1to0.zip const tempFileName = nodePath.join(os.tmpdir(), 'patcher', host, path); @@ -21,24 +20,17 @@ export default async function downloadWrapper({ host, path, size, useCurl = fals return tempFileName; } - //Download either via curl or natively with Node - if (useCurl) { - //Try up to three times - for (let i = 0; i < 3; i += 1) { - try { - const downloadResult = await downloadWithCurl({ host, path, tempFileName }); - return downloadResult; - } catch (err) { - console.error(err); - //ignore error and try again - } + //Download via curl + //Try up to three times + for (let i = 0; i < 3; i += 1) { + try { + const downloadResult = await downloadWithCurl({ host, path, tempFileName }); + return downloadResult; + } catch (err) { + console.error(err); + //ignore error and try again } - //Download failed, throw error - throw new Error('Could not download with curl'); - } else { - const downloadResult = await new Promise((resolve, reject) => { - downloadUrlContents(host, path, tempFileName, resolve, reject); - }) as string; - return downloadResult; } + //Download failed, throw error + throw new Error('Could not download with curl'); } diff --git a/src/ssn/installPatch.ts b/src/ssn/installPatch.ts index 61456cc..f2b30fa 100644 --- a/src/ssn/installPatch.ts +++ b/src/ssn/installPatch.ts @@ -62,7 +62,7 @@ export default async function installPatch({ product, from, to, sourceDirectory, //start download, making sure that .zip file downloads first const indexOfLastFile = solidpkg.files.length - 1; const zipFile = getUrlContents(createUrlObject(solidpkg.files[indexOfLastFile])); - const diskFiles = solidpkg.files.slice(0, indexOfLastFile).map((file) => downloadWrapper.bind(null, { ...createUrlObject(file), useCurl: true })); + const diskFiles = solidpkg.files.slice(0, indexOfLastFile).map((file) => downloadWrapper.bind(null, createUrlObject(file))); //we can parse the file entries as soon as the .zip file is downloaded const fileEntries = readSsnFile(await zipFile);