diff --git a/src/bindings/js/node/scripts/lib/utils.js b/src/bindings/js/node/scripts/lib/utils.js index 35a144872921d8..9658ec504fa0d9 100644 --- a/src/bindings/js/node/scripts/lib/utils.js +++ b/src/bindings/js/node/scripts/lib/utils.js @@ -1,3 +1,4 @@ +const path = require('node:path'); const https = require('node:https'); const fs = require('node:fs/promises'); const { createWriteStream } = require('node:fs'); @@ -56,15 +57,18 @@ async function checkIfPathExists(path) { * * @function downloadFile * @param {string} url - The file URL. - * @param {string} filePath - Path to downloaded file. + * @param {string} filename - The filename of result file. + * @param {string} destination - The destination path of result file. * @param {string} [proxy=null] - (Optional) The proxy URL. * @returns {Promise} - Path to downloaded file. */ -function downloadFile(url, filePath, proxy = null) { - console.log(`Downloading file by link: ${url} to ${filePath}.`); +function downloadFile(url, destination, filename, proxy = null) { + console.log(`Downloading file by link: ${url} to ${destination}` + + `with filename: ${filename}`); const timeout = 5000; - const file = createWriteStream(filePath); + const fullPath = path.resolve(destination, filename); + const file = createWriteStream(fullPath); if (new URL(url).protocol === 'http:') throw new Error('Http link doesn\'t support'); @@ -94,8 +98,8 @@ function downloadFile(url, filePath, proxy = null) { file.on('finish', () => { file.close(); - console.log(`File was successfully downloaded to '${filePath}'.`); - resolve(filePath); + console.log(`File was successfully downloaded to '${fullPath}'.`); + resolve(fullPath); }); }); diff --git a/src/bindings/js/node/tests/utils.js b/src/bindings/js/node/tests/utils.js index 2832c9fbd55669..8fd852af6da086 100644 --- a/src/bindings/js/node/tests/utils.js +++ b/src/bindings/js/node/tests/utils.js @@ -83,11 +83,21 @@ async function downloadTestModel(model) { const { env } = process; const proxyUrl = env.http_proxy || env.HTTP_PROXY || env.npm_config_proxy; - const modelExists = await checkIfPathExists(model.xml); - if (!modelExists) await downloadFile(model.xmlURL, model.xml, proxyUrl); + const modelExists = await checkIfPathExists(model.xml); + if (!modelExists) await downloadFile( + model.xmlURL, + path.dirname(model.xml), + path.basename(model.xml), + proxyUrl, + ); const weightsExists = await checkIfPathExists(model.bin); - if (!weightsExists) await downloadFile(model.binURL, model.bin, proxyUrl); + if (!weightsExists) await downloadFile( + model.binURL, + path.dirname(model.bin), + path.basename(model.bin), + proxyUrl, + ); } catch(error) { console.error(`Failed to download the model: ${error}.`);