@swan-admin/swan-ai-measurements 1.0.92 → 1.0.93
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 +144 -177
- package/dist/fileUpload.js +1 -1
- package/package.json +1 -1
- package/src/fileUpload.ts +1 -1
package/dist/esm/fileUpload.js
CHANGED
|
@@ -1,193 +1,160 @@
|
|
|
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 axios from "axios";
|
|
51
23
|
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
52
24
|
import { checkMetaDataValue, checkParameters, fetchData, getFileChunks } from "./utils.js";
|
|
53
|
-
|
|
54
|
-
|
|
25
|
+
const Uppy = require("fix-esm").require("@uppy/core");
|
|
26
|
+
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
55
27
|
class FileUpload {
|
|
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
|
-
|
|
87
|
-
|
|
28
|
+
constructor(accessKey) {
|
|
29
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
30
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
31
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
32
|
+
}
|
|
33
|
+
uploadFileFrontend(_a) {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
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: 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: 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: 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
|
+
});
|
|
82
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
83
|
+
source: "manual",
|
|
84
|
+
name: file.name,
|
|
85
|
+
type: file.type,
|
|
86
|
+
data: file,
|
|
87
|
+
});
|
|
88
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
89
|
+
reject(error);
|
|
90
|
+
});
|
|
91
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
92
|
+
resolve({ message: "file uploaded successfully" });
|
|
93
|
+
});
|
|
94
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
95
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
96
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
88
99
|
});
|
|
89
|
-
},
|
|
90
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
91
|
-
fetchData({
|
|
92
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
93
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
94
|
-
body: {
|
|
95
|
-
uploadId,
|
|
96
|
-
objectKey: key,
|
|
97
|
-
parts,
|
|
98
|
-
originalFileName: file.name,
|
|
99
|
-
},
|
|
100
|
-
}),
|
|
101
|
-
signPart: (file, partData) =>
|
|
102
|
-
fetchData({
|
|
103
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
104
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
105
|
-
body: {
|
|
106
|
-
objectKey: partData.key,
|
|
107
|
-
uploadId: partData.uploadId,
|
|
108
|
-
partNumber: partData.partNumber,
|
|
109
|
-
},
|
|
110
|
-
}),
|
|
111
|
-
});
|
|
112
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
113
|
-
source: "manual",
|
|
114
|
-
name: file.name,
|
|
115
|
-
type: file.type,
|
|
116
|
-
data: file,
|
|
117
|
-
});
|
|
118
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
119
|
-
reject(error);
|
|
120
|
-
});
|
|
121
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
122
|
-
resolve({ message: "file uploaded successfully" });
|
|
123
|
-
});
|
|
124
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
125
|
-
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
126
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
127
|
-
}
|
|
128
100
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
135
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
136
|
-
}
|
|
137
|
-
if (!checkMetaDataValue(arrayMetaData)) {
|
|
138
|
-
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
139
|
-
}
|
|
140
|
-
return new Promise((resolve, reject) =>
|
|
141
|
-
__awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
try {
|
|
143
|
-
const res = yield fetchData({
|
|
144
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
145
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
146
|
-
body: {
|
|
147
|
-
objectKey: file.name,
|
|
148
|
-
contentType: file.type,
|
|
149
|
-
objectMetadata: arrayMetaData,
|
|
150
|
-
},
|
|
151
|
-
throwError: true,
|
|
152
|
-
});
|
|
153
|
-
const totalChunks = getFileChunks(file);
|
|
154
|
-
const parts = [];
|
|
155
|
-
for (let i = 0; i < totalChunks.length; i++) {
|
|
156
|
-
const data = yield fetchData({
|
|
157
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
158
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
159
|
-
body: {
|
|
160
|
-
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
161
|
-
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
162
|
-
partNumber: i + 1,
|
|
163
|
-
},
|
|
164
|
-
throwError: true,
|
|
165
|
-
});
|
|
166
|
-
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
|
|
167
|
-
headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
|
|
168
|
-
});
|
|
169
|
-
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
170
|
-
console.log(val, "after uploading");
|
|
101
|
+
}
|
|
102
|
+
uploadFileBackend(_a) {
|
|
103
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
104
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
105
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
171
106
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
107
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
108
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
109
|
+
}
|
|
110
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
try {
|
|
112
|
+
const res = yield fetchData({
|
|
113
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
114
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
115
|
+
body: {
|
|
116
|
+
objectKey: file.name,
|
|
117
|
+
contentType: file.type,
|
|
118
|
+
objectMetadata: arrayMetaData,
|
|
119
|
+
},
|
|
120
|
+
throwError: true,
|
|
121
|
+
});
|
|
122
|
+
const totalChunks = getFileChunks(file);
|
|
123
|
+
const parts = [];
|
|
124
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
125
|
+
const data = yield fetchData({
|
|
126
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
127
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
128
|
+
body: {
|
|
129
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
130
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
131
|
+
partNumber: i + 1,
|
|
132
|
+
},
|
|
133
|
+
throwError: true,
|
|
134
|
+
});
|
|
135
|
+
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") } });
|
|
136
|
+
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
137
|
+
console.log(val === null || val === void 0 ? void 0 : val.headers, "after uploading");
|
|
138
|
+
}
|
|
139
|
+
const completeValue = yield fetchData({
|
|
140
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
141
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
142
|
+
body: {
|
|
143
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
144
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
145
|
+
parts,
|
|
146
|
+
originalFileName: file.name,
|
|
147
|
+
},
|
|
148
|
+
throwError: true,
|
|
149
|
+
});
|
|
150
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
reject(error);
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
});
|
|
157
|
+
}
|
|
191
158
|
}
|
|
192
|
-
|
|
159
|
+
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap();
|
|
193
160
|
export default FileUpload;
|
package/dist/fileUpload.js
CHANGED
|
@@ -115,7 +115,7 @@ class FileUpload {
|
|
|
115
115
|
});
|
|
116
116
|
const val = await axios_1.default.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
|
|
117
117
|
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
118
|
-
console.log(val, "after uploading");
|
|
118
|
+
console.log(val?.headers, "after uploading");
|
|
119
119
|
}
|
|
120
120
|
const completeValue = await (0, utils_js_1.fetchData)({
|
|
121
121
|
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
package/package.json
CHANGED
package/src/fileUpload.ts
CHANGED
|
@@ -137,7 +137,7 @@ export default class FileUpload {
|
|
|
137
137
|
});
|
|
138
138
|
const val = await axios.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
|
|
139
139
|
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
140
|
-
console.log(val, "after uploading");
|
|
140
|
+
console.log(val?.headers, "after uploading");
|
|
141
141
|
}
|
|
142
142
|
const completeValue = await fetchData({
|
|
143
143
|
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|