@quatrain/worker 1.1.31 → 1.1.33

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
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.FileSystem = void 0;
30
- const node_fs_1 = __importDefault(require("node:fs"));
30
+ const node_fs_1 = __importStar(require("node:fs"));
31
31
  const node_path_1 = __importDefault(require("node:path"));
32
32
  const axios_1 = __importDefault(require("axios"));
33
33
  const Worker_1 = require("./Worker");
@@ -93,6 +93,26 @@ class FileSystem {
93
93
  // try to get more file metadata
94
94
  meta = { ...meta, ...FileSystem.getInfo(filename) };
95
95
  Worker_1.Worker.info(`Uploading file ${filename} to ${meta.uploadUrl}`);
96
+ const { size } = node_fs_1.default.statSync(filename);
97
+ if (size < 32 * 1024) {
98
+ return new Promise((resolve, reject) => {
99
+ (0, node_fetch_native_1.default)(meta.uploadUrl, {
100
+ method: 'PUT',
101
+ mode: 'cors',
102
+ duplex: 'half',
103
+ body: (0, node_fs_1.readFileSync)(filename),
104
+ headers: {
105
+ 'Content-Type': meta.contentType || mime,
106
+ 'Content-length': String(size),
107
+ },
108
+ })
109
+ .then(() => resolve({ ...meta, size, uploadUrl: undefined }))
110
+ .catch((err) => {
111
+ Worker_1.Worker.error(`An error occured while uploading ${filename}: ${err.message}`);
112
+ reject(err);
113
+ });
114
+ });
115
+ }
96
116
  return new Promise((resolve, reject) => {
97
117
  try {
98
118
  let done = 0; // total bytes uploaded
package/lib/Worker.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Core } from '@quatrain/core';
2
2
  import { HandlerParameters } from './types/HandlerParameters';
3
3
  export declare class Worker extends Core {
4
- static endpoint: string;
5
- static logger: any;
4
+ static readonly endpoint: string;
5
+ static readonly logger: any;
6
6
  /**
7
7
  * Execute an external command in a promise
8
8
  * @see https://stackoverflow.com/questions/46289682/how-to-wait-for-child-process-spawn-execution-with-async-await
@@ -11,7 +11,7 @@ export declare class Worker extends Core {
11
11
  * @param array args
12
12
  * @return Promise
13
13
  */
14
- static execPromise: (command: string, args?: any[], cwd?: string) => Promise<any>;
14
+ static readonly execPromise: (command: string, args?: any[], cwd?: string) => Promise<any>;
15
15
  /**
16
16
  * Push an event to the backend endpoint, if available
17
17
  * @param event string
@@ -25,5 +25,5 @@ export declare class Worker extends Core {
25
25
  * @param messageHandler function
26
26
  * @param config object
27
27
  */
28
- static handler: (messageHandler: Function, config: HandlerParameters) => Promise<void>;
28
+ static readonly handler: (messageHandler: Function, config: HandlerParameters) => Promise<void>;
29
29
  }
package/lib/Worker.js CHANGED
@@ -30,7 +30,7 @@ class Worker extends core_1.Core {
30
30
  child.on('close', (code) => {
31
31
  if (code !== 0) {
32
32
  Worker.error(`Command execution failed with code: ${code}`);
33
- reject(code);
33
+ reject(new Error(`Process failed and returned code: ${code}`));
34
34
  }
35
35
  else {
36
36
  Worker.info(`Command execution completed with code: ${code}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/worker",
3
- "version": "1.1.31",
3
+ "version": "1.1.33",
4
4
  "description": "Container Worker helpers",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "typescript": "^5.1.5"
26
26
  },
27
27
  "dependencies": {
28
- "@quatrain/core": "^1.1.19",
28
+ "@quatrain/core": "^1.1.22",
29
29
  "@quatrain/queue": "^1.1.16",
30
30
  "axios": "^1.7.7",
31
31
  "fluent-ffmpeg": "^2.1.2",