@dynamicweb/cli 1.0.14 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import FormData from 'form-data';
5
5
  import { setupEnv, getAgent } from './env.js';
6
6
  import { setupUser } from './login.js';
7
7
  import { interactiveConfirm, formatBytes, createThrottledStatusUpdater } from '../utils.js';
8
- import { downloadWithProgress, getFileNameFromResponse } from '../downloader.js';
8
+ import { downloadWithProgress, tryGetFileNameFromResponse } from '../downloader.js';
9
9
  import { extractWithProgress } from '../extractor.js';
10
10
 
11
11
  export function filesCommand() {
@@ -198,7 +198,7 @@ async function download(env, user, dirPath, outPath, recursive, outname, raw, ia
198
198
  agent: getAgent(env.protocol)
199
199
  });
200
200
 
201
- const filename = outname || getFileNameFromResponse(res);
201
+ const filename = outname || tryGetFileNameFromResponse(res, dirPath);
202
202
  if (!filename) return;
203
203
 
204
204
  let filePath = path.resolve(`${path.resolve(outPath)}/${filename}`)
package/bin/downloader.js CHANGED
@@ -6,17 +6,35 @@ import fs from 'fs';
6
6
  * @param {Response} res - The HTTP response object.
7
7
  * @returns {string} The extracted file name.
8
8
  */
9
- export function getFileNameFromResponse(res) {
9
+ export function getFileNameFromResponse(res, dirPath) {
10
10
  const header = res.headers.get('content-disposition');
11
11
  const parts = header?.split(';');
12
12
 
13
13
  if (!parts) {
14
- throw new Error(`No files found in directory '${dirPath}', if you want to download all folders recursively include the -r flag`);
14
+ const msg = `No files found in directory '${dirPath}', if you want to download all folders recursively include the -r flag`;
15
+ throw new Error(msg);
15
16
  }
16
17
 
17
18
  return parts[1].split('=')[1].replace('+', ' ');
18
19
  }
19
20
 
21
+ /**
22
+ * Attempts to extract the file name from an HTTP response.
23
+ * If extraction fails, logs the error message to the console.
24
+ *
25
+ * @param {Object} res - The HTTP response object to extract the file name from.
26
+ * @param {string} dirPath - The directory path to use for file name resolution.
27
+ * @returns {string|null} The extracted file name, or null if extraction fails.
28
+ */
29
+ export function tryGetFileNameFromResponse(res, dirPath) {
30
+ try {
31
+ return getFileNameFromResponse(res, dirPath);
32
+ } catch (err) {
33
+ console.error(err.message);
34
+ return null;
35
+ }
36
+ }
37
+
20
38
  /**
21
39
  * Downloads a file with progress reporting.
22
40
  * @param {Response} res - The response from which to read the stream data.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@dynamicweb/cli",
3
3
  "type": "module",
4
4
  "description": "Dynamicweb CLI is a commandline tool for interacting with Dynamicweb 10 solutions.",
5
- "version": "1.0.14",
5
+ "version": "1.0.15",
6
6
  "main": "bin/index.js",
7
7
  "files": [
8
8
  "bin/*"