@promptbook/pdf 0.84.0-12 → 0.84.0-13
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/esm/index.es.js +49 -7
- package/esm/index.es.js.map +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +49 -7
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -24,7 +24,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
24
24
|
* @generated
|
|
25
25
|
* @see https://github.com/webgptorg/promptbook
|
|
26
26
|
*/
|
|
27
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
27
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-12';
|
|
28
28
|
/**
|
|
29
29
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
30
30
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3615,7 +3615,7 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
|
|
|
3615
3615
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3616
3616
|
var _a;
|
|
3617
3617
|
return __awaiter(this, void 0, void 0, function () {
|
|
3618
|
-
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url,
|
|
3618
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, basename, hash, rootDirname_1, filepath, _f, _g, _h, _j, _k, filename_1, fileExtension, mimeType;
|
|
3619
3619
|
return __generator(this, function (_l) {
|
|
3620
3620
|
switch (_l.label) {
|
|
3621
3621
|
case 0:
|
|
@@ -3631,19 +3631,61 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3631
3631
|
url = knowledgeSourceContent;
|
|
3632
3632
|
return [4 /*yield*/, fetch(url)];
|
|
3633
3633
|
case 1:
|
|
3634
|
-
|
|
3635
|
-
mimeType = ((_a =
|
|
3636
|
-
|
|
3634
|
+
response_1 = _l.sent();
|
|
3635
|
+
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3636
|
+
if (tools.fs === undefined || !url.endsWith('.pdf')) {
|
|
3637
|
+
return [2 /*return*/, {
|
|
3638
|
+
source: name,
|
|
3639
|
+
filename: null,
|
|
3640
|
+
url: url,
|
|
3641
|
+
mimeType: mimeType,
|
|
3642
|
+
/*
|
|
3643
|
+
TODO: [🥽]
|
|
3644
|
+
> async asBlob() {
|
|
3645
|
+
> // TODO: [👨🏻🤝👨🏻] This can be called multiple times BUT when called second time, response in already consumed
|
|
3646
|
+
> const content = await response.blob();
|
|
3647
|
+
> return content;
|
|
3648
|
+
> },
|
|
3649
|
+
*/
|
|
3650
|
+
asJson: function () {
|
|
3651
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3652
|
+
var content;
|
|
3653
|
+
return __generator(this, function (_a) {
|
|
3654
|
+
switch (_a.label) {
|
|
3655
|
+
case 0: return [4 /*yield*/, response_1.json()];
|
|
3656
|
+
case 1:
|
|
3657
|
+
content = _a.sent();
|
|
3658
|
+
return [2 /*return*/, content];
|
|
3659
|
+
}
|
|
3660
|
+
});
|
|
3661
|
+
});
|
|
3662
|
+
},
|
|
3663
|
+
asText: function () {
|
|
3664
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3665
|
+
var content;
|
|
3666
|
+
return __generator(this, function (_a) {
|
|
3667
|
+
switch (_a.label) {
|
|
3668
|
+
case 0: return [4 /*yield*/, response_1.text()];
|
|
3669
|
+
case 1:
|
|
3670
|
+
content = _a.sent();
|
|
3671
|
+
return [2 /*return*/, content];
|
|
3672
|
+
}
|
|
3673
|
+
});
|
|
3674
|
+
});
|
|
3675
|
+
},
|
|
3676
|
+
}];
|
|
3677
|
+
}
|
|
3678
|
+
basename = url.split('/').pop() || titleToName(url);
|
|
3637
3679
|
hash = sha256(hexEncoder.parse(url)).toString( /* hex */);
|
|
3638
3680
|
rootDirname_1 = join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3639
|
-
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(
|
|
3681
|
+
filepath = join.apply(void 0, __spreadArray(__spreadArray([], __read(nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */)), false), ["".concat(basename.substring(0, MAX_FILENAME_LENGTH), ".pdf")], false));
|
|
3640
3682
|
return [4 /*yield*/, tools.fs.mkdir(dirname(join(rootDirname_1, filepath)), { recursive: true })];
|
|
3641
3683
|
case 2:
|
|
3642
3684
|
_l.sent();
|
|
3643
3685
|
_g = (_f = tools.fs).writeFile;
|
|
3644
3686
|
_h = [join(rootDirname_1, filepath)];
|
|
3645
3687
|
_k = (_j = Buffer).from;
|
|
3646
|
-
return [4 /*yield*/,
|
|
3688
|
+
return [4 /*yield*/, response_1.arrayBuffer()];
|
|
3647
3689
|
case 3: return [4 /*yield*/, _g.apply(_f, _h.concat([_k.apply(_j, [_l.sent()])]))];
|
|
3648
3690
|
case 4:
|
|
3649
3691
|
_l.sent();
|