bigjpg 1.0.2 → 1.0.3

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/dist/bigjpg.js CHANGED
@@ -13,7 +13,7 @@ const baseUrl = "https://bigjpg.com/api";
13
13
  class Bigjpg {
14
14
  constructor({ apiKey, taskCheckDelay }) {
15
15
  this.apiKey = apiKey;
16
- this.taskCheckDelay = taskCheckDelay !== null && taskCheckDelay !== void 0 ? taskCheckDelay : 500;
16
+ this.taskCheckDelay = taskCheckDelay !== null && taskCheckDelay !== void 0 ? taskCheckDelay : 2000;
17
17
  }
18
18
  async enlarge({ style, noise, enlargeValue, imageUrl }) {
19
19
  const url = `${baseUrl}/task/`;
@@ -26,7 +26,7 @@ class Bigjpg {
26
26
  const headers = { "X-API-KEY": this.apiKey };
27
27
  const response = await axios_1.default.post(url, data, { headers: headers });
28
28
  const responseData = response.data;
29
- if ("status" in responseData) {
29
+ if ("status" in responseData && responseData.status !== "ok") {
30
30
  const status = responseData.status;
31
31
  if (status === enums_1.ApiErrorStatus.ValidApiKeyRequired) {
32
32
  throw new error_1.BigjpgError("Invalid API token, get your API token on the website by registering 'https://bigjpg.com/' and going to the 'API' section and copying your token that is present in the example code");
@@ -34,6 +34,12 @@ class Bigjpg {
34
34
  else if (status === enums_1.ApiErrorStatus.ParamError) {
35
35
  throw new error_1.BigjpgError("Some invalid parameter, check parameters and features available in your account and try again");
36
36
  }
37
+ else if (status === enums_1.ApiErrorStatus.RequiresVip) {
38
+ throw new error_1.BigjpgError("VIP account required for this feature or API request");
39
+ }
40
+ else {
41
+ throw new error_1.BigjpgError(`Bigjpg API error: ${status}`);
42
+ }
37
43
  }
38
44
  const remainingApiCalls = responseData.remaining_api_calls;
39
45
  const taskId = responseData.tid;
@@ -1,4 +1,5 @@
1
1
  export declare enum ApiErrorStatus {
2
2
  ValidApiKeyRequired = "valid_api_key_required",
3
- ParamError = "param_error"
3
+ ParamError = "param_error",
4
+ RequiresVip = "requires_vip"
4
5
  }
@@ -5,4 +5,5 @@ var ApiErrorStatus;
5
5
  (function (ApiErrorStatus) {
6
6
  ApiErrorStatus["ValidApiKeyRequired"] = "valid_api_key_required";
7
7
  ApiErrorStatus["ParamError"] = "param_error";
8
+ ApiErrorStatus["RequiresVip"] = "requires_vip";
8
9
  })(ApiErrorStatus || (exports.ApiErrorStatus = ApiErrorStatus = {}));
package/dist/error.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare class BigjpgError extends Error {
2
+ constructor(message?: string);
2
3
  }
package/dist/error.js CHANGED
@@ -2,5 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BigjpgError = void 0;
4
4
  class BigjpgError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "BigjpgError";
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ }
5
10
  }
6
11
  exports.BigjpgError = BigjpgError;
package/dist/image.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import imageDownloader from "image-downloader";
2
1
  export type BigjpgImageOptions = {
3
2
  url: string;
4
3
  remainingApiCalls: number;
@@ -7,5 +6,5 @@ export declare class BigjpgImage {
7
6
  readonly url: string;
8
7
  readonly remainingApiCalls: number;
9
8
  constructor({ url, remainingApiCalls }: BigjpgImageOptions);
10
- download(filePath: string): Promise<imageDownloader.DownloadResult>;
9
+ download(filePath: string): Promise<void>;
11
10
  }
package/dist/image.js CHANGED
@@ -4,18 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BigjpgImage = void 0;
7
- const image_downloader_1 = __importDefault(require("image-downloader"));
7
+ const promises_1 = require("node:stream/promises");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const node_fs_1 = __importDefault(require("node:fs"));
8
10
  class BigjpgImage {
9
11
  constructor({ url, remainingApiCalls }) {
10
12
  this.url = url;
11
13
  this.remainingApiCalls = remainingApiCalls;
12
14
  }
13
15
  async download(filePath) {
14
- return await image_downloader_1.default.image({
15
- url: this.url,
16
- dest: filePath,
17
- timeout: 0
16
+ const response = await axios_1.default.get(this.url, {
17
+ responseType: "stream"
18
18
  });
19
+ const writer = node_fs_1.default.createWriteStream(filePath);
20
+ await (0, promises_1.pipeline)(response.data, writer);
19
21
  }
20
22
  }
21
23
  exports.BigjpgImage = BigjpgImage;
package/dist/task.js CHANGED
@@ -16,8 +16,18 @@ class BigjpgTask {
16
16
  async fetchUntilAchieveTheResult() {
17
17
  while (true) {
18
18
  const response = await axios_1.default.get(this.url);
19
- const dataResponse = response.data;
20
- const data = dataResponse[this.taskId];
19
+ let dataResponse = response.data;
20
+ if (typeof dataResponse === "string") {
21
+ try {
22
+ dataResponse = JSON.parse(dataResponse);
23
+ }
24
+ catch { }
25
+ }
26
+ const data = dataResponse === null || dataResponse === void 0 ? void 0 : dataResponse[this.taskId];
27
+ if (!data) {
28
+ await (0, utils_1.sleep)(this.checkDelay);
29
+ continue;
30
+ }
21
31
  const status = data.status;
22
32
  if (status === "success") {
23
33
  return data;
@@ -25,7 +35,7 @@ class BigjpgTask {
25
35
  else if (status === "error") {
26
36
  throw new error_1.BigjpgError("Error processing the image!");
27
37
  }
28
- await (0, utils_1.sleep)(.5);
38
+ await (0, utils_1.sleep)(this.checkDelay);
29
39
  }
30
40
  }
31
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bigjpg",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "API Wrapper for bigjpg.com",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -10,7 +10,8 @@
10
10
  "!/**/__tests__"
11
11
  ],
12
12
  "scripts": {
13
- "build": "tsc"
13
+ "build": "tsc",
14
+ "test": "jest"
14
15
  },
15
16
  "keywords": [
16
17
  "bigjpg",
@@ -20,19 +21,22 @@
20
21
  "author": "Marcuth",
21
22
  "license": "MIT",
22
23
  "dependencies": {
23
- "axios": "^1.13.2",
24
- "image-downloader": "^4.3.0"
24
+ "axios": "^1.20.0"
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
28
- "url": "git+https://github.com/1Marcuth/bigjpg-js.git"
28
+ "url": "git+https://github.com/marcuth/ts.bigjpg.git"
29
29
  },
30
30
  "bugs": {
31
- "url": "https://github.com/1Marcuth/bigjpg-js/issues"
31
+ "url": "https://github.com/marcuth/ts.bigjpg/issues"
32
32
  },
33
- "homepage": "https://github.com/1Marcuth/bigjpg-js#readme",
33
+ "homepage": "https://github.com/marcuth/ts.bigjpg#readme",
34
34
  "devDependencies": {
35
- "@types/node": "^18.11.18",
35
+ "@types/jest": "^30.0.0",
36
+ "@types/node": "^18.19.130",
37
+ "dotenv": "^17.4.2",
38
+ "jest": "^30.5.1",
39
+ "ts-jest": "^29.4.12",
36
40
  "ts-node": "^10.9.2",
37
41
  "typescript": "^5.9.3"
38
42
  }