ag-common 0.0.856 → 0.0.857
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/node/helpers/fetch/fetchFile.d.ts +8 -0
- package/dist/node/helpers/fetch/fetchFile.js +47 -0
- package/dist/node/helpers/fetch/index.d.ts +2 -0
- package/dist/node/helpers/fetch/index.js +18 -0
- package/dist/node/helpers/{fetch.d.ts → fetch/others.d.ts} +0 -8
- package/dist/node/helpers/{fetch.js → fetch/others.js} +4 -40
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.fetchFile = fetchFile;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
/**
|
|
18
|
+
* download(fetch) file
|
|
19
|
+
* @param p
|
|
20
|
+
*/
|
|
21
|
+
function fetchFile(p) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const response = yield fetch(p.FILE_URL);
|
|
24
|
+
if (!response.ok || !response.body) {
|
|
25
|
+
throw new Error(`Failed to download: ${response.statusText}`);
|
|
26
|
+
}
|
|
27
|
+
const fileStream = fs_1.default.createWriteStream(p.FILE_PATH);
|
|
28
|
+
const reader = response.body.getReader();
|
|
29
|
+
const write = () => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const { done, value } = yield reader.read();
|
|
31
|
+
if (done) {
|
|
32
|
+
fileStream.close();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
fileStream.write(value);
|
|
36
|
+
yield write();
|
|
37
|
+
});
|
|
38
|
+
yield write();
|
|
39
|
+
try {
|
|
40
|
+
fileStream.close();
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
//
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fetchFile"), exports);
|
|
18
|
+
__exportStar(require("./others"), exports);
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* download(fetch) file
|
|
3
|
-
* @param p
|
|
4
|
-
*/
|
|
5
|
-
export declare function fetchFile(p: {
|
|
6
|
-
FILE_URL: string;
|
|
7
|
-
FILE_PATH: string;
|
|
8
|
-
}): Promise<void>;
|
|
9
1
|
export declare function fetchToMemory(imageUrl: string): Promise<{
|
|
10
2
|
type: string;
|
|
11
3
|
arraybuffer: ArrayBuffer;
|
|
@@ -8,49 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.fetchFile = fetchFile;
|
|
16
12
|
exports.fetchToMemory = fetchToMemory;
|
|
17
13
|
exports.fetchExists = fetchExists;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const node_cache_1 = require("./node-cache");
|
|
23
|
-
/**
|
|
24
|
-
* download(fetch) file
|
|
25
|
-
* @param p
|
|
26
|
-
*/
|
|
27
|
-
function fetchFile(p) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const response = yield fetch(p.FILE_URL);
|
|
30
|
-
if (!response.ok || !response.body) {
|
|
31
|
-
throw new Error(`Failed to download: ${response.statusText}`);
|
|
32
|
-
}
|
|
33
|
-
const fileStream = fs_1.default.createWriteStream(p.FILE_PATH);
|
|
34
|
-
const reader = response.body.getReader();
|
|
35
|
-
const write = () => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const { done, value } = yield reader.read();
|
|
37
|
-
if (done) {
|
|
38
|
-
fileStream.close();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
fileStream.write(value);
|
|
42
|
-
yield write();
|
|
43
|
-
});
|
|
44
|
-
yield write();
|
|
45
|
-
try {
|
|
46
|
-
fileStream.close();
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
//
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
14
|
+
const withRetry_1 = require("../../../api/helpers/withRetry");
|
|
15
|
+
const log_1 = require("../../../common/helpers/log");
|
|
16
|
+
const headers_1 = require("../headers");
|
|
17
|
+
const node_cache_1 = require("../node-cache");
|
|
54
18
|
function fetchToMemory(imageUrl) {
|
|
55
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
20
|
try {
|
package/package.json
CHANGED