@swan-admin/swan-ai-measurements 1.0.73 → 1.0.74
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/esm/fileUpload.js +99 -129
- package/dist/esm/utils.js +1 -0
- package/dist/fileUpload.js +1 -0
- package/dist/utils.js +1 -0
- package/package.json +1 -1
- package/src/fileUpload.ts +2 -0
package/dist/esm/fileUpload.js
CHANGED
|
@@ -1,143 +1,113 @@
|
|
|
1
|
-
var __awaiter =
|
|
2
|
-
|
|
3
|
-
function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) {
|
|
5
|
-
return value instanceof P
|
|
6
|
-
? value
|
|
7
|
-
: new P(function (resolve) {
|
|
8
|
-
resolve(value);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
reject(e);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function rejected(value) {
|
|
20
|
-
try {
|
|
21
|
-
step(generator["throw"](value));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
reject(e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function step(result) {
|
|
27
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
28
|
-
}
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
8
|
});
|
|
31
|
-
|
|
32
|
-
var __classPrivateFieldSet =
|
|
33
|
-
(this && this.__classPrivateFieldSet) ||
|
|
34
|
-
function (receiver, state, value, kind, f) {
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
35
11
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
36
12
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
37
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var __classPrivateFieldGet =
|
|
42
|
-
(this && this.__classPrivateFieldGet) ||
|
|
43
|
-
function (receiver, state, kind, f) {
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
44
17
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
45
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
46
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
47
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
48
|
-
|
|
20
|
+
};
|
|
49
21
|
var _FileUpload_uppyIns, _FileUpload_accessKey;
|
|
50
22
|
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
51
23
|
import { checkMetaDataValue, checkParameters, fetchData } from "./utils.js";
|
|
52
|
-
|
|
53
|
-
|
|
24
|
+
const Uppy = require("fix-esm").require("@uppy/core");
|
|
25
|
+
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
54
26
|
class FileUpload {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
27
|
+
constructor(accessKey) {
|
|
28
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
29
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
30
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
31
|
+
}
|
|
32
|
+
uploadFile(_a) {
|
|
33
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
34
|
+
console.log(UPPY_FILE_UPLOAD_ENDPOINT);
|
|
35
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
36
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
37
|
+
}
|
|
38
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
39
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
40
|
+
}
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
43
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
44
|
+
}
|
|
45
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy.default({ autoProceed: true }), "f");
|
|
46
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart.default, {
|
|
47
|
+
limit: 10,
|
|
48
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
49
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
50
|
+
createMultipartUpload: (file) => {
|
|
51
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
52
|
+
return fetchData({
|
|
53
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
54
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
55
|
+
body: {
|
|
56
|
+
objectKey,
|
|
57
|
+
contentType: file.type,
|
|
58
|
+
objectMetadata: arrayMetaData,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
|
|
63
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
64
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
65
|
+
body: {
|
|
66
|
+
uploadId,
|
|
67
|
+
objectKey: key,
|
|
68
|
+
parts,
|
|
69
|
+
originalFileName: file.name,
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
signPart: (file, partData) => fetchData({
|
|
73
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
74
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
75
|
+
body: {
|
|
76
|
+
objectKey: partData.key,
|
|
77
|
+
uploadId: partData.uploadId,
|
|
78
|
+
partNumber: partData.partNumber,
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
abortMultipartUpload: (file, { uploadId, key }) => fetchData({
|
|
82
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
83
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
84
|
+
body: {
|
|
85
|
+
uploadId,
|
|
86
|
+
objectKey: key,
|
|
87
|
+
originalFileName: file.name,
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
92
|
+
source: "manual",
|
|
93
|
+
name: file.name,
|
|
94
|
+
type: file.type,
|
|
95
|
+
data: file,
|
|
96
|
+
});
|
|
97
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
98
|
+
reject(error);
|
|
99
|
+
});
|
|
100
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
101
|
+
resolve({ message: "file uploaded successfully" });
|
|
102
|
+
});
|
|
103
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
104
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
105
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
87
108
|
});
|
|
88
|
-
},
|
|
89
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
90
|
-
fetchData({
|
|
91
|
-
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
92
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
93
|
-
body: {
|
|
94
|
-
uploadId,
|
|
95
|
-
objectKey: key,
|
|
96
|
-
parts,
|
|
97
|
-
originalFileName: file.name,
|
|
98
|
-
},
|
|
99
|
-
}),
|
|
100
|
-
signPart: (file, partData) =>
|
|
101
|
-
fetchData({
|
|
102
|
-
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
103
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
104
|
-
body: {
|
|
105
|
-
objectKey: partData.key,
|
|
106
|
-
uploadId: partData.uploadId,
|
|
107
|
-
partNumber: partData.partNumber,
|
|
108
|
-
},
|
|
109
|
-
}),
|
|
110
|
-
abortMultipartUpload: (file, { uploadId, key }) =>
|
|
111
|
-
fetchData({
|
|
112
|
-
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
113
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
114
|
-
body: {
|
|
115
|
-
uploadId,
|
|
116
|
-
objectKey: key,
|
|
117
|
-
originalFileName: file.name,
|
|
118
|
-
},
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
122
|
-
source: "manual",
|
|
123
|
-
name: file.name,
|
|
124
|
-
type: file.type,
|
|
125
|
-
data: file,
|
|
126
|
-
});
|
|
127
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
128
|
-
reject(error);
|
|
129
109
|
});
|
|
130
|
-
|
|
131
|
-
resolve({ message: "file uploaded successfully" });
|
|
132
|
-
});
|
|
133
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
134
|
-
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
135
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
}
|
|
110
|
+
}
|
|
141
111
|
}
|
|
142
|
-
|
|
112
|
+
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap();
|
|
143
113
|
export default FileUpload;
|
package/dist/esm/utils.js
CHANGED
|
@@ -12,6 +12,7 @@ import { APP_AUTH_BASE_URL, requiredMetaData } from "./constants.js";
|
|
|
12
12
|
export function fetchData(options) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
const { path, body, queryParams, baseUrl = APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
|
|
15
|
+
console.log(body, "body", path, "path");
|
|
15
16
|
const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
|
|
16
17
|
try {
|
|
17
18
|
const res = yield axios.post(apiUrl, body, { headers });
|
package/dist/fileUpload.js
CHANGED
|
@@ -11,6 +11,7 @@ class FileUpload {
|
|
|
11
11
|
this.#accessKey = accessKey;
|
|
12
12
|
}
|
|
13
13
|
async uploadFile({ file, arrayMetaData, scanId }) {
|
|
14
|
+
console.log(constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT);
|
|
14
15
|
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
|
|
15
16
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
16
17
|
}
|
package/dist/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const constants_js_1 = require("./constants.js");
|
|
9
9
|
async function fetchData(options) {
|
|
10
10
|
const { path, body, queryParams, baseUrl = constants_js_1.APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
|
|
11
|
+
console.log(body, "body", path, "path");
|
|
11
12
|
const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
|
|
12
13
|
try {
|
|
13
14
|
const res = await axios_1.default.post(apiUrl, body, { headers });
|
package/package.json
CHANGED
package/src/fileUpload.ts
CHANGED