triangle-utils 1.4.60 → 1.4.61
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.js +1 -0
- package/dist/src/UtilsS3.d.ts +51 -10
- package/dist/src/UtilsS3.js +59 -71
- package/dist/src/f.js +3 -2
- package/package.json +1 -1
- package/src/UtilsBee.ts +1 -0
- package/src/UtilsS3.ts +60 -72
- package/src/f.ts +4 -2
- package/test/Utils.test.ts +30 -30
package/dist/src/UtilsBee.js
CHANGED
package/dist/src/UtilsS3.d.ts
CHANGED
|
@@ -2,18 +2,59 @@ import { Readable } from "stream";
|
|
|
2
2
|
export declare class UtilsS3 {
|
|
3
3
|
private readonly s3;
|
|
4
4
|
constructor(region: string);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
get_headers(s3_id: string): Promise<false | {
|
|
6
|
+
DeleteMarker?: boolean | undefined;
|
|
7
|
+
AcceptRanges?: string | undefined;
|
|
8
|
+
Expiration?: string | undefined;
|
|
9
|
+
Restore?: string | undefined;
|
|
10
|
+
ArchiveStatus?: import("@aws-sdk/client-s3").ArchiveStatus | undefined;
|
|
11
|
+
LastModified?: Date | undefined;
|
|
12
|
+
ContentLength?: number | undefined;
|
|
13
|
+
ChecksumCRC32?: string | undefined;
|
|
14
|
+
ChecksumCRC32C?: string | undefined;
|
|
15
|
+
ChecksumCRC64NVME?: string | undefined;
|
|
16
|
+
ChecksumSHA1?: string | undefined;
|
|
17
|
+
ChecksumSHA256?: string | undefined;
|
|
18
|
+
ChecksumType?: import("@aws-sdk/client-s3").ChecksumType | undefined;
|
|
19
|
+
ETag?: string | undefined;
|
|
20
|
+
MissingMeta?: number | undefined;
|
|
21
|
+
VersionId?: string | undefined;
|
|
22
|
+
CacheControl?: string | undefined;
|
|
23
|
+
ContentDisposition?: string | undefined;
|
|
24
|
+
ContentEncoding?: string | undefined;
|
|
25
|
+
ContentLanguage?: string | undefined;
|
|
26
|
+
ContentType?: string | undefined;
|
|
27
|
+
ContentRange?: string | undefined;
|
|
28
|
+
Expires?: Date | undefined;
|
|
29
|
+
ExpiresString?: string | undefined;
|
|
30
|
+
WebsiteRedirectLocation?: string | undefined;
|
|
31
|
+
ServerSideEncryption?: import("@aws-sdk/client-s3").ServerSideEncryption | undefined;
|
|
32
|
+
Metadata?: Record<string, string> | undefined;
|
|
33
|
+
SSECustomerAlgorithm?: string | undefined;
|
|
34
|
+
SSECustomerKeyMD5?: string | undefined;
|
|
35
|
+
SSEKMSKeyId?: string | undefined;
|
|
36
|
+
BucketKeyEnabled?: boolean | undefined;
|
|
37
|
+
StorageClass?: import("@aws-sdk/client-s3").StorageClass | undefined;
|
|
38
|
+
RequestCharged?: import("@aws-sdk/client-s3").RequestCharged | undefined;
|
|
39
|
+
ReplicationStatus?: import("@aws-sdk/client-s3").ReplicationStatus | undefined;
|
|
40
|
+
PartsCount?: number | undefined;
|
|
41
|
+
TagCount?: number | undefined;
|
|
42
|
+
ObjectLockMode?: import("@aws-sdk/client-s3").ObjectLockMode | undefined;
|
|
43
|
+
ObjectLockRetainUntilDate?: Date | undefined;
|
|
44
|
+
ObjectLockLegalHoldStatus?: import("@aws-sdk/client-s3").ObjectLockLegalHoldStatus | undefined;
|
|
45
|
+
$metadata: import("@smithy/types").ResponseMetadata;
|
|
46
|
+
size: number | undefined;
|
|
47
|
+
} | undefined>;
|
|
48
|
+
get(s3_id: string, encoding?: string): Promise<string | undefined>;
|
|
49
|
+
get_buffer(s3_id: string): Promise<Buffer | undefined>;
|
|
50
|
+
get_stream(s3_id: string): Promise<Readable | undefined>;
|
|
51
|
+
query_prefix(s3_id_prefix: string, options?: {
|
|
8
52
|
compile?: boolean;
|
|
9
53
|
}): Promise<string[]>;
|
|
10
|
-
|
|
11
|
-
get_file_buffer(s3_filename: string): Promise<Buffer | undefined>;
|
|
12
|
-
get_file_stream(s3_filename: string): Promise<Readable | undefined>;
|
|
13
|
-
create_file(s3_filename: string, content: string | Buffer | Readable, options?: {
|
|
54
|
+
create(s3_id: string, content: string | Buffer | Readable, options?: {
|
|
14
55
|
content_type?: string;
|
|
15
56
|
}): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
57
|
+
delete(s3_id: string): Promise<void>;
|
|
58
|
+
get_download_url(s3_id: string): Promise<string | undefined>;
|
|
59
|
+
get_upload_url(s3_id: string): Promise<string | undefined>;
|
|
19
60
|
}
|
package/dist/src/UtilsS3.js
CHANGED
|
@@ -1,78 +1,36 @@
|
|
|
1
1
|
import { S3, NoSuchKey, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
|
|
2
2
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
3
3
|
import { Readable } from "stream";
|
|
4
|
-
function
|
|
5
|
-
|
|
4
|
+
function get_s3_key(s3_id) {
|
|
5
|
+
const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3);
|
|
6
|
+
if (bucket === undefined || path === undefined) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
const bucket = bucket_filename.split("/")[0];
|
|
10
|
-
const filename = bucket_filename.split("/").slice(1).join("/");
|
|
11
|
-
return { Bucket: bucket, Key: filename };
|
|
9
|
+
return { Bucket: bucket, Key: path };
|
|
12
10
|
}
|
|
13
11
|
export class UtilsS3 {
|
|
14
12
|
s3;
|
|
15
13
|
constructor(region) {
|
|
16
14
|
this.s3 = new S3({ region: region });
|
|
17
15
|
}
|
|
18
|
-
async
|
|
19
|
-
const s3_key =
|
|
16
|
+
async get_headers(s3_id) {
|
|
17
|
+
const s3_key = get_s3_key(s3_id);
|
|
20
18
|
if (s3_key === undefined) {
|
|
21
19
|
return undefined;
|
|
22
20
|
}
|
|
23
21
|
try {
|
|
24
|
-
const
|
|
25
|
-
return
|
|
22
|
+
const headers = await this.s3.headObject(s3_key);
|
|
23
|
+
return {
|
|
24
|
+
size: headers.ContentLength,
|
|
25
|
+
...headers
|
|
26
|
+
};
|
|
26
27
|
}
|
|
27
28
|
catch (error) {
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
async
|
|
32
|
-
const s3_key =
|
|
33
|
-
if (s3_key === undefined) {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const head = await this.s3.headObject(s3_key);
|
|
38
|
-
return head.ContentLength;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async get_s3_filenames(s3_filename_prefix, options = {}) {
|
|
45
|
-
const compile = options.compile !== undefined ? options.compile : false;
|
|
46
|
-
const s3_key = parse_s3_filename(s3_filename_prefix);
|
|
47
|
-
if (s3_key === undefined) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const s3_filenames = [];
|
|
51
|
-
let last_token = undefined;
|
|
52
|
-
while (true) {
|
|
53
|
-
const response = await this.s3.listObjectsV2({
|
|
54
|
-
Bucket: s3_key.Bucket,
|
|
55
|
-
Delimiter: "/",
|
|
56
|
-
Prefix: s3_key.Key,
|
|
57
|
-
ContinuationToken: last_token
|
|
58
|
-
});
|
|
59
|
-
if (response.Contents === undefined) {
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
const new_s3_filenames = response.Contents
|
|
63
|
-
.map(content => content.Key)
|
|
64
|
-
.filter(key => key !== undefined)
|
|
65
|
-
.filter(key => key.substring(key.length - 1) !== "/")
|
|
66
|
-
.map(key => "s3://" + s3_key.Bucket + "/" + key);
|
|
67
|
-
s3_filenames.push(...new_s3_filenames);
|
|
68
|
-
if (response.NextContinuationToken === undefined || !compile) {
|
|
69
|
-
return s3_filenames;
|
|
70
|
-
}
|
|
71
|
-
last_token = response.NextContinuationToken;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async get_file(s3_filename, encoding = "utf-8") {
|
|
75
|
-
const s3_key = parse_s3_filename(s3_filename);
|
|
32
|
+
async get(s3_id, encoding = "utf-8") {
|
|
33
|
+
const s3_key = get_s3_key(s3_id);
|
|
76
34
|
if (s3_key === undefined) {
|
|
77
35
|
return undefined;
|
|
78
36
|
}
|
|
@@ -92,8 +50,8 @@ export class UtilsS3 {
|
|
|
92
50
|
throw error;
|
|
93
51
|
}
|
|
94
52
|
}
|
|
95
|
-
async
|
|
96
|
-
const s3_key =
|
|
53
|
+
async get_buffer(s3_id) {
|
|
54
|
+
const s3_key = get_s3_key(s3_id);
|
|
97
55
|
if (s3_key === undefined) {
|
|
98
56
|
return undefined;
|
|
99
57
|
}
|
|
@@ -113,8 +71,8 @@ export class UtilsS3 {
|
|
|
113
71
|
throw error;
|
|
114
72
|
}
|
|
115
73
|
}
|
|
116
|
-
async
|
|
117
|
-
const s3_key =
|
|
74
|
+
async get_stream(s3_id) {
|
|
75
|
+
const s3_key = get_s3_key(s3_id);
|
|
118
76
|
if (s3_key === undefined) {
|
|
119
77
|
return undefined;
|
|
120
78
|
}
|
|
@@ -136,13 +94,43 @@ export class UtilsS3 {
|
|
|
136
94
|
throw error;
|
|
137
95
|
}
|
|
138
96
|
}
|
|
139
|
-
async
|
|
97
|
+
async query_prefix(s3_id_prefix, options = {}) {
|
|
98
|
+
const compile = options.compile !== undefined ? options.compile : false;
|
|
99
|
+
const s3_key = get_s3_key(s3_id_prefix);
|
|
100
|
+
if (s3_key === undefined) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const s3_ids = [];
|
|
104
|
+
let last_token = undefined;
|
|
105
|
+
while (true) {
|
|
106
|
+
const response = await this.s3.listObjectsV2({
|
|
107
|
+
Bucket: s3_key.Bucket,
|
|
108
|
+
Delimiter: "/",
|
|
109
|
+
Prefix: s3_key.Key,
|
|
110
|
+
ContinuationToken: last_token
|
|
111
|
+
});
|
|
112
|
+
if (response.Contents === undefined) {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
const new_s3_ids = response.Contents
|
|
116
|
+
.map(content => content.Key)
|
|
117
|
+
.filter(key => key !== undefined)
|
|
118
|
+
.filter(key => key.substring(key.length - 1) !== "/")
|
|
119
|
+
.map(key => "s3://" + s3_key.Bucket + "/" + key);
|
|
120
|
+
s3_ids.push(...new_s3_ids);
|
|
121
|
+
if (response.NextContinuationToken === undefined || !compile) {
|
|
122
|
+
return s3_ids;
|
|
123
|
+
}
|
|
124
|
+
last_token = response.NextContinuationToken;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async create(s3_id, content, options = {}) {
|
|
140
128
|
const content_type = options.content_type !== undefined ? options.content_type : undefined;
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
129
|
+
const headers = await this.get_headers(s3_id);
|
|
130
|
+
if (headers !== undefined) {
|
|
143
131
|
return undefined;
|
|
144
132
|
}
|
|
145
|
-
const s3_key =
|
|
133
|
+
const s3_key = get_s3_key(s3_id);
|
|
146
134
|
if (s3_key === undefined) {
|
|
147
135
|
return undefined;
|
|
148
136
|
}
|
|
@@ -152,19 +140,19 @@ export class UtilsS3 {
|
|
|
152
140
|
ContentType: content_type
|
|
153
141
|
});
|
|
154
142
|
}
|
|
155
|
-
async
|
|
156
|
-
const s3_key =
|
|
143
|
+
async delete(s3_id) {
|
|
144
|
+
const s3_key = get_s3_key(s3_id);
|
|
157
145
|
if (s3_key === undefined) {
|
|
158
146
|
return undefined;
|
|
159
147
|
}
|
|
160
148
|
await this.s3.deleteObject(s3_key);
|
|
161
149
|
}
|
|
162
|
-
async
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
150
|
+
async get_download_url(s3_id) {
|
|
151
|
+
const headers = await this.get_headers(s3_id);
|
|
152
|
+
if (headers === undefined) {
|
|
165
153
|
return undefined;
|
|
166
154
|
}
|
|
167
|
-
const s3_key =
|
|
155
|
+
const s3_key = get_s3_key(s3_id);
|
|
168
156
|
if (s3_key === undefined) {
|
|
169
157
|
return undefined;
|
|
170
158
|
}
|
|
@@ -172,8 +160,8 @@ export class UtilsS3 {
|
|
|
172
160
|
const url = await getSignedUrl(this.s3, command);
|
|
173
161
|
return url;
|
|
174
162
|
}
|
|
175
|
-
async
|
|
176
|
-
const s3_key =
|
|
163
|
+
async get_upload_url(s3_id) {
|
|
164
|
+
const s3_key = get_s3_key(s3_id);
|
|
177
165
|
if (s3_key === undefined) {
|
|
178
166
|
return undefined;
|
|
179
167
|
}
|
package/dist/src/f.js
CHANGED
|
@@ -21,5 +21,6 @@ const utils = new TriangleUtils(config);
|
|
|
21
21
|
// console.log(text)
|
|
22
22
|
// const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
23
23
|
// console.log(text)
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const url = "https://dataviewers.tdec.tn.gov/dataviewers/f?p=2005:34051:3300341444471:::34051:P34051_PERMIT_NUMBER:TNR136379";
|
|
25
|
+
const html = await utils.bee.get(url, { render_js: false });
|
|
26
|
+
console.log(html);
|
package/package.json
CHANGED
package/src/UtilsBee.ts
CHANGED
package/src/UtilsS3.ts
CHANGED
|
@@ -7,14 +7,12 @@ interface S3Key {
|
|
|
7
7
|
Key : string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function
|
|
11
|
-
|
|
10
|
+
function get_s3_key(s3_id : string) : S3Key | undefined {
|
|
11
|
+
const [bucket, path] = (s3_id.match(/^s3\:\/\/([^\/]+)\/([^$]+)$/) || []).slice(1, 3)
|
|
12
|
+
if (bucket === undefined || path === undefined) {
|
|
12
13
|
return undefined
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
const bucket = bucket_filename.split("/")[0]
|
|
16
|
-
const filename = bucket_filename.split("/").slice(1).join("/")
|
|
17
|
-
return { Bucket : bucket, Key : filename }
|
|
15
|
+
return { Bucket : bucket, Key : path }
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
export class UtilsS3 {
|
|
@@ -25,65 +23,24 @@ export class UtilsS3 {
|
|
|
25
23
|
this.s3 = new S3({ region : region })
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
async
|
|
29
|
-
const s3_key =
|
|
26
|
+
async get_headers(s3_id : string) {
|
|
27
|
+
const s3_key = get_s3_key(s3_id)
|
|
30
28
|
if (s3_key === undefined) {
|
|
31
29
|
return undefined
|
|
32
30
|
}
|
|
33
31
|
try {
|
|
34
|
-
const
|
|
35
|
-
return
|
|
32
|
+
const headers = await this.s3.headObject(s3_key)
|
|
33
|
+
return {
|
|
34
|
+
size : headers.ContentLength,
|
|
35
|
+
...headers
|
|
36
|
+
}
|
|
36
37
|
} catch (error) {
|
|
37
38
|
return false
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
async
|
|
42
|
-
const s3_key =
|
|
43
|
-
if (s3_key === undefined) {
|
|
44
|
-
return undefined
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
const head = await this.s3.headObject(s3_key)
|
|
48
|
-
return head.ContentLength
|
|
49
|
-
} catch (error) {
|
|
50
|
-
return undefined
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async get_s3_filenames(s3_filename_prefix : string, options : { compile? : boolean } = {}) {
|
|
55
|
-
const compile = options.compile !== undefined ? options.compile : false
|
|
56
|
-
const s3_key = parse_s3_filename(s3_filename_prefix)
|
|
57
|
-
if (s3_key === undefined) {
|
|
58
|
-
return []
|
|
59
|
-
}
|
|
60
|
-
const s3_filenames = []
|
|
61
|
-
let last_token : string | undefined = undefined
|
|
62
|
-
while (true) {
|
|
63
|
-
const response : ListObjectsV2CommandOutput = await this.s3.listObjectsV2({
|
|
64
|
-
Bucket : s3_key.Bucket,
|
|
65
|
-
Delimiter : "/",
|
|
66
|
-
Prefix : s3_key.Key,
|
|
67
|
-
ContinuationToken : last_token
|
|
68
|
-
})
|
|
69
|
-
if (response.Contents === undefined) {
|
|
70
|
-
return []
|
|
71
|
-
}
|
|
72
|
-
const new_s3_filenames = response.Contents
|
|
73
|
-
.map(content => content.Key)
|
|
74
|
-
.filter(key => key !== undefined)
|
|
75
|
-
.filter(key => key.substring(key.length - 1) !== "/")
|
|
76
|
-
.map(key => "s3://" + s3_key.Bucket + "/" + key)
|
|
77
|
-
s3_filenames.push(...new_s3_filenames)
|
|
78
|
-
if (response.NextContinuationToken === undefined || !compile) {
|
|
79
|
-
return s3_filenames
|
|
80
|
-
}
|
|
81
|
-
last_token = response.NextContinuationToken
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async get_file(s3_filename : string, encoding : string = "utf-8") : Promise<string | undefined> {
|
|
86
|
-
const s3_key = parse_s3_filename(s3_filename)
|
|
42
|
+
async get(s3_id : string, encoding : string = "utf-8") : Promise<string | undefined> {
|
|
43
|
+
const s3_key = get_s3_key(s3_id)
|
|
87
44
|
if (s3_key === undefined) {
|
|
88
45
|
return undefined
|
|
89
46
|
}
|
|
@@ -103,8 +60,8 @@ export class UtilsS3 {
|
|
|
103
60
|
}
|
|
104
61
|
}
|
|
105
62
|
|
|
106
|
-
async
|
|
107
|
-
const s3_key =
|
|
63
|
+
async get_buffer(s3_id : string) : Promise<Buffer | undefined> {
|
|
64
|
+
const s3_key = get_s3_key(s3_id)
|
|
108
65
|
if (s3_key === undefined) {
|
|
109
66
|
return undefined
|
|
110
67
|
}
|
|
@@ -124,8 +81,8 @@ export class UtilsS3 {
|
|
|
124
81
|
}
|
|
125
82
|
}
|
|
126
83
|
|
|
127
|
-
async
|
|
128
|
-
const s3_key =
|
|
84
|
+
async get_stream(s3_id : string) : Promise<Readable | undefined> {
|
|
85
|
+
const s3_key = get_s3_key(s3_id)
|
|
129
86
|
if (s3_key === undefined) {
|
|
130
87
|
return undefined
|
|
131
88
|
}
|
|
@@ -147,16 +104,47 @@ export class UtilsS3 {
|
|
|
147
104
|
}
|
|
148
105
|
}
|
|
149
106
|
|
|
150
|
-
async
|
|
107
|
+
async query_prefix(s3_id_prefix : string, options : { compile? : boolean } = {}) {
|
|
108
|
+
const compile = options.compile !== undefined ? options.compile : false
|
|
109
|
+
const s3_key = get_s3_key(s3_id_prefix)
|
|
110
|
+
if (s3_key === undefined) {
|
|
111
|
+
return []
|
|
112
|
+
}
|
|
113
|
+
const s3_ids = []
|
|
114
|
+
let last_token : string | undefined = undefined
|
|
115
|
+
while (true) {
|
|
116
|
+
const response : ListObjectsV2CommandOutput = await this.s3.listObjectsV2({
|
|
117
|
+
Bucket : s3_key.Bucket,
|
|
118
|
+
Delimiter : "/",
|
|
119
|
+
Prefix : s3_key.Key,
|
|
120
|
+
ContinuationToken : last_token
|
|
121
|
+
})
|
|
122
|
+
if (response.Contents === undefined) {
|
|
123
|
+
return []
|
|
124
|
+
}
|
|
125
|
+
const new_s3_ids = response.Contents
|
|
126
|
+
.map(content => content.Key)
|
|
127
|
+
.filter(key => key !== undefined)
|
|
128
|
+
.filter(key => key.substring(key.length - 1) !== "/")
|
|
129
|
+
.map(key => "s3://" + s3_key.Bucket + "/" + key)
|
|
130
|
+
s3_ids.push(...new_s3_ids)
|
|
131
|
+
if (response.NextContinuationToken === undefined || !compile) {
|
|
132
|
+
return s3_ids
|
|
133
|
+
}
|
|
134
|
+
last_token = response.NextContinuationToken
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async create(s3_id : string, content : string | Buffer | Readable, options : {
|
|
151
139
|
content_type? : string
|
|
152
140
|
} = {}) {
|
|
153
141
|
const content_type = options.content_type !== undefined ? options.content_type : undefined
|
|
154
142
|
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
143
|
+
const headers = await this.get_headers(s3_id)
|
|
144
|
+
if (headers !== undefined) {
|
|
157
145
|
return undefined
|
|
158
146
|
}
|
|
159
|
-
const s3_key =
|
|
147
|
+
const s3_key = get_s3_key(s3_id)
|
|
160
148
|
if (s3_key === undefined) {
|
|
161
149
|
return undefined
|
|
162
150
|
}
|
|
@@ -167,20 +155,20 @@ export class UtilsS3 {
|
|
|
167
155
|
})
|
|
168
156
|
}
|
|
169
157
|
|
|
170
|
-
async
|
|
171
|
-
const s3_key =
|
|
158
|
+
async delete(s3_id : string) : Promise<void>{
|
|
159
|
+
const s3_key = get_s3_key(s3_id)
|
|
172
160
|
if (s3_key === undefined) {
|
|
173
161
|
return undefined
|
|
174
162
|
}
|
|
175
163
|
await this.s3.deleteObject(s3_key)
|
|
176
164
|
}
|
|
177
165
|
|
|
178
|
-
async
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
166
|
+
async get_download_url(s3_id : string) : Promise<string | undefined> {
|
|
167
|
+
const headers = await this.get_headers(s3_id)
|
|
168
|
+
if (headers === undefined) {
|
|
181
169
|
return undefined
|
|
182
170
|
}
|
|
183
|
-
const s3_key =
|
|
171
|
+
const s3_key = get_s3_key(s3_id)
|
|
184
172
|
if (s3_key === undefined) {
|
|
185
173
|
return undefined
|
|
186
174
|
}
|
|
@@ -189,8 +177,8 @@ export class UtilsS3 {
|
|
|
189
177
|
return url
|
|
190
178
|
}
|
|
191
179
|
|
|
192
|
-
async
|
|
193
|
-
const s3_key =
|
|
180
|
+
async get_upload_url(s3_id : string) : Promise<string | undefined> {
|
|
181
|
+
const s3_key = get_s3_key(s3_id)
|
|
194
182
|
if (s3_key === undefined) {
|
|
195
183
|
return undefined
|
|
196
184
|
}
|
package/src/f.ts
CHANGED
|
@@ -35,6 +35,8 @@ const utils = new TriangleUtils(config)
|
|
|
35
35
|
// const text = await utils.bedrock.claude_invoke("global.anthropic.claude-opus-4-6-v1", "hi", undefined, { print_usage : true })
|
|
36
36
|
// console.log(text)
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const url = "https://dataviewers.tdec.tn.gov/dataviewers/f?p=2005:34051:3300341444471:::34051:P34051_PERMIT_NUMBER:TNR136379"
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const html = await utils.bee.get(url, { render_js : false })
|
|
41
|
+
|
|
42
|
+
console.log(html)
|
package/test/Utils.test.ts
CHANGED
|
@@ -35,7 +35,7 @@ describe("Testing Utils", () => {
|
|
|
35
35
|
describe("Testing Misc", () => {
|
|
36
36
|
test("email", async () => {
|
|
37
37
|
const utils = new TriangleUtils(config)
|
|
38
|
-
const success = await utils.admin_alert("Testing Admin Alert.")
|
|
38
|
+
const success = await utils.ses.admin_alert("Testing Admin Alert.")
|
|
39
39
|
expect(success).toBeTruthy()
|
|
40
40
|
})
|
|
41
41
|
test("sha256", async () => {
|
|
@@ -109,36 +109,36 @@ describe("Testing Utils", () => {
|
|
|
109
109
|
expect(!candidate_articles.map(candidate_article => candidate_article.article_id.substring(0, 7) === "2025-08").includes(false)).toBeTruthy()
|
|
110
110
|
})
|
|
111
111
|
})
|
|
112
|
-
describe("Testing S3", () => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
112
|
+
// describe("Testing S3", () => {
|
|
113
|
+
// test("exists, get, create, delete, download_url, upload_url", async () => {
|
|
114
|
+
// const utils = new TriangleUtils(config)
|
|
115
|
+
// const s3_filename = "s3://triangleanalytics-raw-scrapes/test_file.txt"
|
|
116
|
+
// await utils.s3.delete_file(s3_filename)
|
|
117
|
+
// const file_exists_0 = await utils.s3.file_exists(s3_filename)
|
|
118
|
+
// expect(file_exists_0).toBeFalsy()
|
|
119
|
+
// await utils.s3.create_file(s3_filename, "test file contents.")
|
|
120
|
+
// const file_exists_1 = await utils.s3.file_exists(s3_filename)
|
|
121
|
+
// expect(file_exists_1).toBeTruthy()
|
|
122
|
+
// const text = await utils.s3.get_file(s3_filename)
|
|
123
|
+
// expect(text).toEqual("test file contents.")
|
|
124
|
+
// const download_url = await utils.s3.generate_download_url(s3_filename)
|
|
125
|
+
// expect(download_url).toBeDefined()
|
|
126
|
+
// if (download_url === undefined) {
|
|
127
|
+
// return
|
|
128
|
+
// }
|
|
129
|
+
// expect(download_url.includes("https://triangleanalytics-raw-scrapes.s3.us-east-1.amazonaws.com/test_file.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&")).toBeDefined()
|
|
130
|
+
// const upload_url = await utils.s3.generate_upload_url(s3_filename)
|
|
131
|
+
// expect(upload_url).toBeDefined()
|
|
132
|
+
// await utils.s3.delete_file(s3_filename)
|
|
133
|
+
// if (upload_url === undefined) {
|
|
134
|
+
// return
|
|
135
|
+
// }
|
|
136
|
+
// expect(upload_url.includes("https://triangleanalytics-raw-scrapes.s3.us-east-1.amazonaws.com/test_file.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&")).toBeDefined()
|
|
137
|
+
// const file_exists_2 = await utils.s3.file_exists(s3_filename)
|
|
138
|
+
// expect(file_exists_2).toBeFalsy()
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
})
|
|
140
|
+
// })
|
|
141
|
+
// })
|
|
142
142
|
// describe("Testing Bee", () => {
|
|
143
143
|
// test("bee get page text", async () => {
|
|
144
144
|
// const utils = new Utils(config)
|