triangle-utils 1.4.33 → 1.4.35
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/src/UtilsBee.d.ts +2 -2
- package/dist/src/UtilsBee.js +6 -2
- package/dist/src/UtilsDynamoDB.d.ts +1 -1
- package/dist/src/UtilsDynamoDB.js +7 -13
- package/dist/src/UtilsNitter.js +5 -5
- package/package.json +1 -1
- package/src/UtilsBee.ts +6 -2
- package/src/UtilsDynamoDB.ts +11 -14
- package/src/UtilsNitter.ts +5 -5
package/dist/src/UtilsBee.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ 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>;
|
|
6
|
-
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | undefined>;
|
|
5
|
+
get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Error | Buffer<any> | undefined>;
|
|
6
|
+
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | Error | undefined>;
|
|
7
7
|
google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
|
|
8
8
|
youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
|
|
9
9
|
}
|
package/dist/src/UtilsBee.js
CHANGED
|
@@ -22,9 +22,10 @@ export class UtilsBee {
|
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
24
|
if (error instanceof Error) {
|
|
25
|
-
|
|
25
|
+
if ((error.stack || "").includes("Request failed with status code 404")) {
|
|
26
|
+
return new Error("404");
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
|
-
console.log("Failed to get from Scraping Bee.");
|
|
28
29
|
}
|
|
29
30
|
return undefined;
|
|
30
31
|
}
|
|
@@ -33,6 +34,9 @@ export class UtilsBee {
|
|
|
33
34
|
if (buffer === undefined) {
|
|
34
35
|
return undefined;
|
|
35
36
|
}
|
|
37
|
+
if (buffer instanceof Error) {
|
|
38
|
+
return buffer;
|
|
39
|
+
}
|
|
36
40
|
return this.text_decoder.decode(buffer);
|
|
37
41
|
}
|
|
38
42
|
async google_search(query, news = false) {
|
|
@@ -10,7 +10,7 @@ export declare class UtilsDynamoDB {
|
|
|
10
10
|
concurrency?: number;
|
|
11
11
|
}): Promise<Record<string, any>[]>;
|
|
12
12
|
get(table: string, key: Record<string, any>, consistent?: boolean): Promise<Record<string, any> | undefined>;
|
|
13
|
-
get_max(table_index_name: string, primary_key: Record<string,
|
|
13
|
+
get_max(table_index_name: string, primary_key: Record<string, string | number>): Promise<Record<string, any> | undefined>;
|
|
14
14
|
query(table_index_name: string, primary_key: Record<string, any>, options?: {
|
|
15
15
|
reverse?: boolean;
|
|
16
16
|
compile?: boolean;
|
|
@@ -158,24 +158,18 @@ export class UtilsDynamoDB {
|
|
|
158
158
|
async get_max(table_index_name, primary_key) {
|
|
159
159
|
const table_name = table_index_name.split(":")[0];
|
|
160
160
|
const index_name = table_index_name.split(":")[1];
|
|
161
|
-
if (Object.keys(primary_key).length !== 1
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
const key = Object.keys(primary_key)[0];
|
|
165
|
-
const value = convert_input(Object.values(primary_key)[0]);
|
|
166
|
-
if (value === undefined) {
|
|
161
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
162
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split("-").length) {
|
|
167
163
|
return undefined;
|
|
168
164
|
}
|
|
169
165
|
const request = {
|
|
170
166
|
TableName: table_name,
|
|
171
167
|
IndexName: index_name,
|
|
172
|
-
ExpressionAttributeNames:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
KeyConditionExpression: "#a = :a",
|
|
168
|
+
ExpressionAttributeNames: Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
169
|
+
ExpressionAttributeValues: Object.fromEntries(Object.entries(primary_key)
|
|
170
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
171
|
+
.filter(([key, value]) => value !== undefined)),
|
|
172
|
+
KeyConditionExpression: Object.keys(primary_key).map(key => ["#" + key, ":" + key]).join(", "),
|
|
179
173
|
Limit: 1,
|
|
180
174
|
ScanIndexForward: false
|
|
181
175
|
};
|
package/dist/src/UtilsNitter.js
CHANGED
|
@@ -109,13 +109,13 @@ export class UtilsNitter extends UtilsBee {
|
|
|
109
109
|
let nitter_html = undefined;
|
|
110
110
|
for (let i = 0; i < 10; i++) {
|
|
111
111
|
nitter_html = await this.get(nitter_url, { render_js: false });
|
|
112
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
112
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
115
|
console.log("Failed to query Nitter, trying again.");
|
|
116
116
|
await UtilsMisc.wait((2 + 2 * i) * 1000);
|
|
117
117
|
}
|
|
118
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
118
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
119
119
|
console.log("Nitter failed for url", nitter_url);
|
|
120
120
|
return [];
|
|
121
121
|
}
|
|
@@ -145,14 +145,14 @@ export class UtilsNitter extends UtilsBee {
|
|
|
145
145
|
let nitter_html = undefined;
|
|
146
146
|
for (let i = 0; i < 10; i++) {
|
|
147
147
|
nitter_html = await this.get(nitter_url, { render_js: false });
|
|
148
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
148
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
151
|
console.log("Failed to query Nitter, trying again.");
|
|
152
152
|
await UtilsMisc.wait((2 + 2 * i) * 1000);
|
|
153
153
|
}
|
|
154
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
155
|
-
console.log("Nitter failed for
|
|
154
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
155
|
+
console.log("Nitter failed for url", nitter_url);
|
|
156
156
|
return [];
|
|
157
157
|
}
|
|
158
158
|
const nitter_data = parse_nitter_html(nitter_html);
|
package/package.json
CHANGED
package/src/UtilsBee.ts
CHANGED
|
@@ -25,9 +25,10 @@ export class UtilsBee {
|
|
|
25
25
|
return undefined
|
|
26
26
|
} catch (error) {
|
|
27
27
|
if (error instanceof Error) {
|
|
28
|
-
|
|
28
|
+
if ((error.stack || "").includes("Request failed with status code 404")) {
|
|
29
|
+
return new Error("404")
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
|
-
console.log("Failed to get from Scraping Bee.")
|
|
31
32
|
}
|
|
32
33
|
return undefined
|
|
33
34
|
|
|
@@ -38,6 +39,9 @@ export class UtilsBee {
|
|
|
38
39
|
if (buffer === undefined) {
|
|
39
40
|
return undefined
|
|
40
41
|
}
|
|
42
|
+
if (buffer instanceof Error) {
|
|
43
|
+
return buffer
|
|
44
|
+
}
|
|
41
45
|
return this.text_decoder.decode(buffer)
|
|
42
46
|
}
|
|
43
47
|
|
package/src/UtilsDynamoDB.ts
CHANGED
|
@@ -183,28 +183,25 @@ export class UtilsDynamoDB {
|
|
|
183
183
|
|
|
184
184
|
async get_max(
|
|
185
185
|
table_index_name : string,
|
|
186
|
-
primary_key : Record<string,
|
|
186
|
+
primary_key : Record<string, string | number>
|
|
187
187
|
) : Promise<Record<string, any> | undefined> {
|
|
188
188
|
const table_name : string = table_index_name.split(":")[0]
|
|
189
189
|
const index_name : string | undefined = table_index_name.split(":")[1]
|
|
190
|
-
if (Object.keys(primary_key).length !== 1
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const key = Object.keys(primary_key)[0]
|
|
194
|
-
const value = convert_input(Object.values(primary_key)[0])
|
|
195
|
-
if (value === undefined) {
|
|
190
|
+
if (index_name === undefined && Object.keys(primary_key).length !== 1 ||
|
|
191
|
+
index_name !== undefined && Object.keys(primary_key).length !== index_name.split("-").length
|
|
192
|
+
) {
|
|
196
193
|
return undefined
|
|
197
194
|
}
|
|
198
195
|
const request : QueryCommandInput = {
|
|
199
196
|
TableName : table_name,
|
|
200
197
|
IndexName : index_name,
|
|
201
|
-
ExpressionAttributeNames:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
KeyConditionExpression: "#
|
|
198
|
+
ExpressionAttributeNames: Object.fromEntries(Object.keys(primary_key).map(key => ["#" + key, key])),
|
|
199
|
+
ExpressionAttributeValues: Object.fromEntries(
|
|
200
|
+
Object.entries(primary_key)
|
|
201
|
+
.map(([key, value]) => [":" + key, convert_input(value)])
|
|
202
|
+
.filter(([key, value]) => value !== undefined)
|
|
203
|
+
),
|
|
204
|
+
KeyConditionExpression: Object.keys(primary_key).map(key => ["#" + key, ":" + key]).join(", "),
|
|
208
205
|
Limit : 1,
|
|
209
206
|
ScanIndexForward : false
|
|
210
207
|
}
|
package/src/UtilsNitter.ts
CHANGED
|
@@ -121,13 +121,13 @@ export class UtilsNitter extends UtilsBee {
|
|
|
121
121
|
let nitter_html = undefined
|
|
122
122
|
for (let i = 0; i < 10; i++) {
|
|
123
123
|
nitter_html = await this.get(nitter_url, { render_js : false })
|
|
124
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
124
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
125
125
|
break
|
|
126
126
|
}
|
|
127
127
|
console.log("Failed to query Nitter, trying again.")
|
|
128
128
|
await UtilsMisc.wait((2 + 2 * i) * 1000)
|
|
129
129
|
}
|
|
130
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
130
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
131
131
|
console.log("Nitter failed for url", nitter_url)
|
|
132
132
|
return []
|
|
133
133
|
}
|
|
@@ -159,14 +159,14 @@ export class UtilsNitter extends UtilsBee {
|
|
|
159
159
|
let nitter_html = undefined
|
|
160
160
|
for (let i = 0; i < 10; i++) {
|
|
161
161
|
nitter_html = await this.get(nitter_url, { render_js : false })
|
|
162
|
-
if (nitter_html !== undefined && nitter_html !== "") {
|
|
162
|
+
if (nitter_html !== undefined && nitter_html !== "" && !(nitter_html instanceof Error)) {
|
|
163
163
|
break
|
|
164
164
|
}
|
|
165
165
|
console.log("Failed to query Nitter, trying again.")
|
|
166
166
|
await UtilsMisc.wait((2 + 2 * i) * 1000)
|
|
167
167
|
}
|
|
168
|
-
if (nitter_html === undefined || nitter_html === "") {
|
|
169
|
-
console.log("Nitter failed for
|
|
168
|
+
if (nitter_html === undefined || nitter_html === "" || nitter_html instanceof Error) {
|
|
169
|
+
console.log("Nitter failed for url", nitter_url)
|
|
170
170
|
return []
|
|
171
171
|
}
|
|
172
172
|
const nitter_data = parse_nitter_html(nitter_html)
|