@quatrain/worker 1.1.25 → 1.1.27

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.
package/lib/FileSystem.js CHANGED
@@ -63,6 +63,7 @@ class FileSystem {
63
63
  }
64
64
  static async downloadFile(url, filepath) {
65
65
  try {
66
+ Worker_1.Worker.debug(`Downloading file at ${url} to ${filepath}`);
66
67
  const writer = node_fs_1.default.createWriteStream(filepath);
67
68
  const response = await axios_1.default.get(url, {
68
69
  responseType: 'stream',
@@ -73,9 +74,9 @@ class FileSystem {
73
74
  writer.on('error', reject);
74
75
  });
75
76
  }
76
- catch (error) {
77
- console.error(`Download error: ${error.message}`);
78
- throw error;
77
+ catch (err) {
78
+ Worker_1.Worker.error(`Download error: ${err.message}`);
79
+ throw err;
79
80
  }
80
81
  }
81
82
  static safeString(name) {
package/lib/Helpers.d.ts CHANGED
@@ -7,5 +7,5 @@ export declare class Helpers {
7
7
  * @param width width of thumbnail (4/3 ratio)
8
8
  * @returns
9
9
  */
10
- static generateVideoThumbnail: (videoPath: string, frame?: number, width?: number) => Promise<any>;
10
+ static generateVideoThumbnail: (videoPath: string, outputPath: string, frame?: number, width?: number) => Promise<any>;
11
11
  }
package/lib/Helpers.js CHANGED
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Helpers = void 0;
7
4
  const Worker_1 = require("./Worker");
8
- const path_1 = __importDefault(require("path"));
9
5
  class Helpers {
10
6
  static FFMPEG = '/usr/bin/ffmpeg';
11
7
  /**
@@ -15,16 +11,15 @@ class Helpers {
15
11
  * @param width width of thumbnail (4/3 ratio)
16
12
  * @returns
17
13
  */
18
- static generateVideoThumbnail = async (videoPath, frame = 0, width = 320) => {
14
+ static generateVideoThumbnail = async (videoPath, outputPath, frame = 0, width = 320) => {
19
15
  const resolution = `${width}x${Math.ceil(width * 0.75)}`;
20
- const outputPath = path_1.default.resolve(videoPath.split('.')[0], `_${frame}_${resolution}.jpg`);
21
16
  const ffmpegParams = [
22
17
  '-i',
23
18
  videoPath,
24
19
  '-vframes',
25
20
  '1',
26
21
  '-vf',
27
- `select=gte(n\,${frame})`,
22
+ `"select=gte(n\,${frame})"`,
28
23
  '-s',
29
24
  resolution,
30
25
  '-ss',
package/lib/Worker.js CHANGED
@@ -20,23 +20,29 @@ class Worker extends core_1.Core {
20
20
  * @return Promise
21
21
  */
22
22
  static execPromise = (command, args = [], cwd = process.cwd()) => {
23
- Worker.info(`Executing command ${command} in ${cwd} with arguments:`);
24
- args.forEach((arg) => console.log(`\t${arg}`));
25
- return new Promise((resolve, reject) => {
26
- const child = (0, child_process_1.spawn)(command, args, { cwd });
27
- child.stdout.on('data', (data) => Worker.debug(data.toString()));
28
- child.stderr.on('data', (data) => Worker.debug(data.toString()));
29
- child.on('close', (code) => {
30
- if (code !== 0) {
31
- Worker.error(`Command execution failed with code: ${code}`);
32
- reject(code);
33
- }
34
- else {
35
- Worker.info(`Command execution completed with code: ${code}`);
36
- resolve(undefined);
37
- }
23
+ try {
24
+ Worker.info(`Executing command ${command} in ${cwd} with arguments:`);
25
+ args.forEach((arg) => console.log(`\t${arg}`));
26
+ return new Promise((resolve, reject) => {
27
+ const child = (0, child_process_1.spawn)(command, args, { cwd });
28
+ child.stdout.on('data', (data) => Worker.debug(data.toString()));
29
+ child.stderr.on('data', (data) => Worker.debug(data.toString()));
30
+ child.on('close', (code) => {
31
+ if (code !== 0) {
32
+ Worker.error(`Command execution failed with code: ${code}`);
33
+ reject(code);
34
+ }
35
+ else {
36
+ Worker.info(`Command execution completed with code: ${code}`);
37
+ resolve(undefined);
38
+ }
39
+ });
38
40
  });
39
- });
41
+ }
42
+ catch (err) {
43
+ Worker.error(err.message);
44
+ throw err;
45
+ }
40
46
  };
41
47
  /**
42
48
  * Push an event to the backend endpoint, if available
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/worker",
3
- "version": "1.1.25",
3
+ "version": "1.1.27",
4
4
  "description": "Container Worker helpers",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",