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