triangle-utils 1.4.110 → 1.4.112

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.
@@ -4,7 +4,9 @@ export declare class UtilsBee {
4
4
  constructor(scraping_bee_api_key: string | undefined);
5
5
  get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Error | Buffer<any> | undefined>;
6
6
  get(url: string, params?: Record<string, string | number | boolean>): Promise<string | Error | undefined>;
7
- google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
7
+ google_search(query: string, options?: {
8
+ search_type_id?: string;
9
+ }): Promise<Record<string, any>[] | undefined>;
8
10
  youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
9
11
  youtube_get_subtitles(video_id: string): Promise<Record<string, any> | undefined>;
10
12
  }
@@ -39,42 +39,39 @@ export class UtilsBee {
39
39
  }
40
40
  return this.text_decoder.decode(buffer);
41
41
  }
42
- async google_search(query, news = false) {
42
+ async google_search(query, options = {}) {
43
43
  if (this.bee === undefined) {
44
44
  return undefined;
45
45
  }
46
- for (let i = 0; i < 3; i++) {
47
- try {
48
- const response = await this.bee.googleSearch({
49
- search: query,
50
- params: {
51
- search_type: news ? "news" : undefined
52
- }
53
- });
54
- if (response.status !== 200) {
55
- console.log("Failed to Google:", response.status);
56
- continue;
57
- }
58
- const data = JSON.parse(response.data.toString("utf-8"));
59
- if (data.news_results === undefined || data.organic_results === undefined) {
60
- continue;
61
- }
62
- const results = news ? data.news_results : data.organic_results;
63
- if (results === undefined) {
64
- console.log("Failed to Google.");
65
- continue;
66
- }
67
- if (!Array.isArray(results)) {
68
- console.log("Results are not an array.");
69
- return;
46
+ try {
47
+ const response = await this.bee.googleSearch({
48
+ search: query,
49
+ params: {
50
+ search_type: options.search_type_id
70
51
  }
71
- return results;
52
+ });
53
+ if (response.status !== 200) {
54
+ console.log("Failed to Google:", response.status);
55
+ return;
72
56
  }
73
- catch {
57
+ const data = JSON.parse(response.data.toString("utf-8"));
58
+ if (data.news_results === undefined || data.organic_results === undefined) {
59
+ return;
60
+ }
61
+ const results = options.search_type_id === "news" ? data.news_results : data.organic_results;
62
+ if (results === undefined) {
74
63
  console.log("Failed to Google.");
64
+ return;
65
+ }
66
+ if (!Array.isArray(results)) {
67
+ console.log("Results are not an array.");
68
+ return;
75
69
  }
70
+ return results;
71
+ }
72
+ catch (error) {
73
+ console.log("Failed to Google:", error.stack);
76
74
  }
77
- console.log("Failed to Google thrice, quitting.");
78
75
  return undefined;
79
76
  }
80
77
  async youtube_search(query, options = {}) {
@@ -3,6 +3,7 @@ export declare class GlobalConfig {
3
3
  readonly cognito_user_pool_id: string;
4
4
  readonly secret_key: string;
5
5
  readonly auth_url: string;
6
+ readonly s3_triangle: string;
6
7
  readonly s3_elections: string;
7
8
  readonly s3_prism: string;
8
9
  readonly s3_scout: string;
@@ -3,6 +3,7 @@ export class GlobalConfig {
3
3
  cognito_user_pool_id;
4
4
  secret_key;
5
5
  auth_url;
6
+ s3_triangle;
6
7
  s3_elections;
7
8
  s3_prism;
8
9
  s3_scout;
@@ -22,6 +23,7 @@ export class GlobalConfig {
22
23
  this.cognito_user_pool_id = global_config.cognito_user_pool_id;
23
24
  this.secret_key = global_config.secret_key;
24
25
  this.auth_url = global_config.auth_url;
26
+ this.s3_triangle = global_config.s3_triangle;
25
27
  this.s3_elections = global_config.s3_elections;
26
28
  this.s3_prism = global_config.s3_prism;
27
29
  this.s3_scout = global_config.s3_scout;
@@ -40,6 +42,7 @@ export class GlobalConfig {
40
42
  typeof global_config.cognito_user_pool_id === "string" &&
41
43
  typeof global_config.secret_key === "string" &&
42
44
  typeof global_config.auth_url === "string" &&
45
+ typeof global_config.s3_triangle === "string" &&
43
46
  typeof global_config.s3_elections === "string" &&
44
47
  typeof global_config.s3_prism === "string" &&
45
48
  typeof global_config.s3_scout === "string" &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.110",
3
+ "version": "1.4.112",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsBee.ts CHANGED
@@ -45,44 +45,41 @@ export class UtilsBee {
45
45
  return this.text_decoder.decode(buffer)
46
46
  }
47
47
 
48
- async google_search(query : string, news : boolean = false) : Promise<Record<string, any>[] | undefined> {
48
+ async google_search(query : string, options : { search_type_id? : string } = {}) : Promise<Record<string, any>[] | undefined> {
49
49
  if (this.bee === undefined) {
50
50
  return undefined
51
51
  }
52
- for (let i = 0; i < 3; i++) {
53
- try {
54
- const response = await this.bee.googleSearch({
55
- search : query,
56
- params : {
57
- search_type : news ? "news" : undefined
58
- }
59
- })
60
- if (response.status !== 200) {
61
- console.log("Failed to Google:", response.status)
62
- continue
63
- }
64
- const data : Record<string, any> = JSON.parse(response.data.toString("utf-8"))
65
-
66
- if (data.news_results === undefined || data.organic_results === undefined) {
67
- continue
52
+ try {
53
+ const response = await this.bee.googleSearch({
54
+ search : query,
55
+ params : {
56
+ search_type : options.search_type_id
68
57
  }
69
- const results : Record<string, any>[] | undefined = news ? data.news_results : data.organic_results
58
+ })
59
+ if (response.status !== 200) {
60
+ console.log("Failed to Google:", response.status)
61
+ return
62
+ }
63
+ const data : Record<string, any> = JSON.parse(response.data.toString("utf-8"))
64
+
65
+ if (data.news_results === undefined || data.organic_results === undefined) {
66
+ return
67
+ }
68
+ const results : Record<string, any>[] | undefined = options.search_type_id === "news" ? data.news_results : data.organic_results
70
69
 
71
70
 
72
- if (results === undefined) {
73
- console.log("Failed to Google.")
74
- continue
75
- }
76
- if (!Array.isArray(results)) {
77
- console.log("Results are not an array.")
78
- return
79
- }
80
- return results
81
- } catch {
71
+ if (results === undefined) {
82
72
  console.log("Failed to Google.")
73
+ return
74
+ }
75
+ if (!Array.isArray(results)) {
76
+ console.log("Results are not an array.")
77
+ return
83
78
  }
79
+ return results
80
+ } catch (error : any) {
81
+ console.log("Failed to Google:", error.stack)
84
82
  }
85
- console.log("Failed to Google thrice, quitting.")
86
83
  return undefined
87
84
  }
88
85
 
@@ -3,6 +3,7 @@ export class GlobalConfig {
3
3
  readonly cognito_user_pool_id : string
4
4
  readonly secret_key : string
5
5
  readonly auth_url : string
6
+ readonly s3_triangle : string
6
7
  readonly s3_elections : string
7
8
  readonly s3_prism : string
8
9
  readonly s3_scout : string
@@ -24,6 +25,7 @@ export class GlobalConfig {
24
25
  this.cognito_user_pool_id = global_config.cognito_user_pool_id
25
26
  this.secret_key = global_config.secret_key
26
27
  this.auth_url = global_config.auth_url
28
+ this.s3_triangle = global_config.s3_triangle
27
29
  this.s3_elections = global_config.s3_elections
28
30
  this.s3_prism = global_config.s3_prism
29
31
  this.s3_scout = global_config.s3_scout
@@ -44,6 +46,7 @@ export class GlobalConfig {
44
46
  typeof global_config.cognito_user_pool_id === "string" &&
45
47
  typeof global_config.secret_key === "string" &&
46
48
  typeof global_config.auth_url === "string" &&
49
+ typeof global_config.s3_triangle === "string" &&
47
50
  typeof global_config.s3_elections === "string" &&
48
51
  typeof global_config.s3_prism === "string" &&
49
52
  typeof global_config.s3_scout === "string" &&