triangle-utils 1.4.3 → 1.4.5

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.
@@ -2,6 +2,7 @@ export declare class UtilsBee {
2
2
  private readonly bee;
3
3
  private readonly text_decoder;
4
4
  constructor(scraping_bee_api_key: string | undefined);
5
+ get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Buffer<any> | undefined>;
5
6
  get(url: string, params?: Record<string, string | number | boolean>): Promise<string | undefined>;
6
7
  google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
7
8
  youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
@@ -6,7 +6,7 @@ export class UtilsBee {
6
6
  this.bee = scraping_bee_api_key !== undefined ? new ScrapingBeeClient(scraping_bee_api_key) : undefined;
7
7
  this.text_decoder = new TextDecoder();
8
8
  }
9
- async get(url, params = {}) {
9
+ async get_buffer(url, params = {}) {
10
10
  if (this.bee === undefined) {
11
11
  return undefined;
12
12
  }
@@ -16,8 +16,10 @@ export class UtilsBee {
16
16
  url: url,
17
17
  params: params
18
18
  });
19
- const text = this.text_decoder.decode(response.data);
20
- return text;
19
+ if (response.data instanceof Buffer) {
20
+ return response.data;
21
+ }
22
+ return undefined;
21
23
  }
22
24
  catch (error) {
23
25
  if (error instanceof Error) {
@@ -29,6 +31,13 @@ export class UtilsBee {
29
31
  console.log("Failed to get from Scraping Bee, quitting.");
30
32
  return undefined;
31
33
  }
34
+ async get(url, params = {}) {
35
+ const buffer = await this.get_buffer(url, params);
36
+ if (buffer === undefined) {
37
+ return undefined;
38
+ }
39
+ return this.text_decoder.decode(buffer);
40
+ }
32
41
  async google_search(query, news = false) {
33
42
  if (this.bee === undefined) {
34
43
  return undefined;
@@ -1,9 +1,10 @@
1
+ import { Readable } from "stream";
1
2
  export declare class UtilsS3 {
2
3
  private readonly s3;
3
4
  constructor(region: string);
4
5
  file_exists(s3_filename: string): Promise<boolean | undefined>;
5
6
  get_file(s3_filename: string): Promise<string | undefined>;
6
- get_file_stream(s3_filename: string): Promise<(import("node:stream").Readable & import("@smithy/types").SdkStreamMixin) | (Blob & import("@smithy/types").SdkStreamMixin) | (ReadableStream<any> & import("@smithy/types").SdkStreamMixin) | undefined>;
7
+ get_file_stream(s3_filename: string): Promise<Readable | undefined>;
7
8
  create_file(s3_filename: string, content: string | Buffer, options?: {
8
9
  content_type?: string;
9
10
  }): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
@@ -1,5 +1,6 @@
1
1
  import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
2
2
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
3
+ import { Readable } from "stream";
3
4
  function parse_s3_filename(s3_filename) {
4
5
  if (s3_filename.substring(0, 5) !== "s3://") {
5
6
  return undefined;
@@ -59,7 +60,10 @@ export class UtilsS3 {
59
60
  if (body === undefined) {
60
61
  return undefined;
61
62
  }
62
- return body;
63
+ if (body instanceof Readable) {
64
+ return body;
65
+ }
66
+ return undefined;
63
67
  }
64
68
  catch (error) {
65
69
  if (error instanceof NoSuchKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "main": "dist/src/index.js",
5
5
  "directories": {
6
6
  "test": "vitest"
package/src/UtilsBee.ts CHANGED
@@ -10,7 +10,7 @@ export class UtilsBee {
10
10
  this.text_decoder = new TextDecoder()
11
11
  }
12
12
 
13
- async get(url : string, params : Record<string, string | number | boolean> = {}) {
13
+ async get_buffer(url : string, params : Record<string, string | number | boolean> = {}) {
14
14
  if (this.bee === undefined) {
15
15
  return undefined
16
16
  }
@@ -20,8 +20,10 @@ export class UtilsBee {
20
20
  url : url,
21
21
  params : params
22
22
  })
23
- const text = this.text_decoder.decode(response.data)
24
- return text
23
+ if (response.data instanceof Buffer) {
24
+ return response.data
25
+ }
26
+ return undefined
25
27
  } catch (error) {
26
28
  if (error instanceof Error) {
27
29
  console.log(error.stack)
@@ -31,6 +33,15 @@ export class UtilsBee {
31
33
  }
32
34
  console.log("Failed to get from Scraping Bee, quitting.")
33
35
  return undefined
36
+
37
+ }
38
+
39
+ async get(url : string, params : Record<string, string | number | boolean> = {}) {
40
+ const buffer = await this.get_buffer(url, params)
41
+ if (buffer === undefined) {
42
+ return undefined
43
+ }
44
+ return this.text_decoder.decode(buffer)
34
45
  }
35
46
 
36
47
  async google_search(query : string, news : boolean = false) : Promise<Record<string, any>[] | undefined> {
package/src/UtilsS3.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3"
2
2
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
3
+ import { Readable } from "stream"
3
4
 
4
5
  interface S3Key {
5
6
  Bucket : string,
@@ -58,7 +59,7 @@ export class UtilsS3 {
58
59
  }
59
60
  }
60
61
 
61
- async get_file_stream(s3_filename : string) {
62
+ async get_file_stream(s3_filename : string) : Promise<Readable | undefined> {
62
63
  const s3_key = parse_s3_filename(s3_filename)
63
64
  if (s3_key === undefined) {
64
65
  return undefined
@@ -69,7 +70,10 @@ export class UtilsS3 {
69
70
  if (body === undefined) {
70
71
  return undefined
71
72
  }
72
- return body
73
+ if (body instanceof Readable) {
74
+ return body
75
+ }
76
+ return undefined
73
77
  } catch (error) {
74
78
  if (error instanceof NoSuchKey) {
75
79
  return undefined