@swan-admin/swan-ai-measurements 1.0.96 → 1.0.97
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 +3 -2
- package/dist/fileUpload.js +132 -134
- package/package.json +1 -1
- package/src/fileUpload.ts +3 -2
package/dist/esm/fileUpload.js
CHANGED
|
@@ -48,8 +48,8 @@ var __classPrivateFieldGet =
|
|
|
48
48
|
};
|
|
49
49
|
var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
|
|
50
50
|
import axios from "axios";
|
|
51
|
-
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
52
|
-
import { checkMetaDataValue, checkParameters, fetchData, getFileChunks } from "./utils.js";
|
|
51
|
+
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL } from "./constants.js";
|
|
52
|
+
import { checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
|
|
53
53
|
import Uppy from "@uppy/core";
|
|
54
54
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
55
55
|
class FileUpload {
|
|
@@ -76,6 +76,7 @@ class FileUpload {
|
|
|
76
76
|
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
|
|
77
77
|
limit: 10,
|
|
78
78
|
retryDelays: [0, 1000, 3000, 5000],
|
|
79
|
+
companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
|
|
79
80
|
getChunkSize: () => 5 * 1024 * 1024,
|
|
80
81
|
createMultipartUpload: (file) => {
|
|
81
82
|
const objectKey = `${scanId}.${file.extension}`;
|
package/dist/fileUpload.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
-
};
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
7
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
6
|
const axios_1 = __importDefault(require("axios"));
|
|
9
7
|
const constants_js_1 = require("./constants.js");
|
|
@@ -11,139 +9,139 @@ const utils_js_1 = require("./utils.js");
|
|
|
11
9
|
const Uppy = require("fix-esm").require("@uppy/core");
|
|
12
10
|
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
13
11
|
class FileUpload {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
async uploadFileFrontend({ file, arrayMetaData, scanId }) {
|
|
22
|
-
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
|
|
23
|
-
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
12
|
+
#uppyIns;
|
|
13
|
+
#accessKey;
|
|
14
|
+
#stagingUrl;
|
|
15
|
+
constructor(accessKey, stagingUrl = false) {
|
|
16
|
+
this.#accessKey = accessKey;
|
|
17
|
+
this.#stagingUrl = stagingUrl;
|
|
24
18
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
if (this.#uppyIns) {
|
|
30
|
-
this.#uppyIns.close();
|
|
31
|
-
}
|
|
32
|
-
this.#uppyIns = new Uppy.default({ autoProceed: true });
|
|
33
|
-
this.#uppyIns.use(AwsS3Multipart.default, {
|
|
34
|
-
limit: 10,
|
|
35
|
-
retryDelays: [0, 1000, 3000, 5000],
|
|
36
|
-
getChunkSize: () => 5 * 1024 * 1024,
|
|
37
|
-
createMultipartUpload: (file) => {
|
|
38
|
-
const objectKey = `${scanId}.${file.extension}`;
|
|
39
|
-
return (0, utils_js_1.fetchData)({
|
|
40
|
-
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
41
|
-
apiKey: this.#accessKey,
|
|
42
|
-
stagingUrl: this.#stagingUrl,
|
|
43
|
-
body: {
|
|
44
|
-
objectKey,
|
|
45
|
-
contentType: file.type,
|
|
46
|
-
objectMetadata: arrayMetaData,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
51
|
-
(0, utils_js_1.fetchData)({
|
|
52
|
-
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
53
|
-
apiKey: this.#accessKey,
|
|
54
|
-
stagingUrl: this.#stagingUrl,
|
|
55
|
-
body: {
|
|
56
|
-
uploadId,
|
|
57
|
-
objectKey: key,
|
|
58
|
-
parts,
|
|
59
|
-
originalFileName: file.name,
|
|
60
|
-
},
|
|
61
|
-
}),
|
|
62
|
-
signPart: (file, partData) =>
|
|
63
|
-
(0, utils_js_1.fetchData)({
|
|
64
|
-
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
65
|
-
stagingUrl: this.#stagingUrl,
|
|
66
|
-
apiKey: this.#accessKey,
|
|
67
|
-
body: {
|
|
68
|
-
objectKey: partData.key,
|
|
69
|
-
uploadId: partData.uploadId,
|
|
70
|
-
partNumber: partData.partNumber,
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
});
|
|
74
|
-
this.#uppyIns.addFile({
|
|
75
|
-
source: "manual",
|
|
76
|
-
name: file.name,
|
|
77
|
-
type: file.type,
|
|
78
|
-
data: file,
|
|
79
|
-
});
|
|
80
|
-
this.#uppyIns.on("upload-error", (file, error, response) => {
|
|
81
|
-
reject(error);
|
|
82
|
-
});
|
|
83
|
-
this.#uppyIns.on("upload-success", () => {
|
|
84
|
-
resolve({ message: "file uploaded successfully" });
|
|
85
|
-
});
|
|
86
|
-
this.#uppyIns.on("complete", (result) => {
|
|
87
|
-
if (this.#uppyIns) {
|
|
88
|
-
this.#uppyIns.close();
|
|
19
|
+
async uploadFileFrontend({ file, arrayMetaData, scanId }) {
|
|
20
|
+
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
|
|
21
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
89
22
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
23
|
+
if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
|
|
24
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
|
|
25
|
+
}
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
if (this.#uppyIns) {
|
|
28
|
+
this.#uppyIns.close();
|
|
29
|
+
}
|
|
30
|
+
this.#uppyIns = new Uppy.default({ autoProceed: true });
|
|
31
|
+
this.#uppyIns.use(AwsS3Multipart.default, {
|
|
32
|
+
limit: 10,
|
|
33
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
34
|
+
companionUrl: (0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl }),
|
|
35
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
36
|
+
createMultipartUpload: (file) => {
|
|
37
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
38
|
+
return (0, utils_js_1.fetchData)({
|
|
39
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
40
|
+
apiKey: this.#accessKey,
|
|
41
|
+
stagingUrl: this.#stagingUrl,
|
|
42
|
+
body: {
|
|
43
|
+
objectKey,
|
|
44
|
+
contentType: file.type,
|
|
45
|
+
objectMetadata: arrayMetaData,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) => (0, utils_js_1.fetchData)({
|
|
50
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
51
|
+
apiKey: this.#accessKey,
|
|
52
|
+
stagingUrl: this.#stagingUrl,
|
|
53
|
+
body: {
|
|
54
|
+
uploadId,
|
|
55
|
+
objectKey: key,
|
|
56
|
+
parts,
|
|
57
|
+
originalFileName: file.name,
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
signPart: (file, partData) => (0, utils_js_1.fetchData)({
|
|
61
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
62
|
+
stagingUrl: this.#stagingUrl,
|
|
63
|
+
apiKey: this.#accessKey,
|
|
64
|
+
body: {
|
|
65
|
+
objectKey: partData.key,
|
|
66
|
+
uploadId: partData.uploadId,
|
|
67
|
+
partNumber: partData.partNumber,
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
this.#uppyIns.addFile({
|
|
72
|
+
source: "manual",
|
|
73
|
+
name: file.name,
|
|
74
|
+
type: file.type,
|
|
75
|
+
data: file,
|
|
76
|
+
});
|
|
77
|
+
this.#uppyIns.on("upload-error", (file, error, response) => {
|
|
78
|
+
reject(error);
|
|
79
|
+
});
|
|
80
|
+
this.#uppyIns.on("upload-success", () => {
|
|
81
|
+
resolve({ message: "file uploaded successfully" });
|
|
82
|
+
});
|
|
83
|
+
this.#uppyIns.on("complete", (result) => {
|
|
84
|
+
if (this.#uppyIns) {
|
|
85
|
+
this.#uppyIns.close();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
112
88
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
body: {
|
|
121
|
-
objectKey: res?.key,
|
|
122
|
-
uploadId: res?.uploadId,
|
|
123
|
-
partNumber: i + 1,
|
|
124
|
-
},
|
|
125
|
-
throwError: true,
|
|
126
|
-
});
|
|
127
|
-
const val = await axios_1.default.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
|
|
128
|
-
parts.push({ PartNumber: i + 1, ETag: val?.headers?.etag });
|
|
89
|
+
}
|
|
90
|
+
async uploadFileBackend({ file, arrayMetaData, scanId }) {
|
|
91
|
+
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
|
|
92
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
93
|
+
}
|
|
94
|
+
if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
|
|
95
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
|
|
129
96
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
97
|
+
return new Promise(async (resolve, reject) => {
|
|
98
|
+
try {
|
|
99
|
+
const res = await (0, utils_js_1.fetchData)({
|
|
100
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
101
|
+
apiKey: this.#accessKey,
|
|
102
|
+
stagingUrl: this.#stagingUrl,
|
|
103
|
+
body: {
|
|
104
|
+
objectKey: file.name,
|
|
105
|
+
contentType: file.type,
|
|
106
|
+
objectMetadata: arrayMetaData,
|
|
107
|
+
},
|
|
108
|
+
throwError: true,
|
|
109
|
+
});
|
|
110
|
+
const totalChunks = (0, utils_js_1.getFileChunks)(file);
|
|
111
|
+
const parts = [];
|
|
112
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
113
|
+
const data = await (0, utils_js_1.fetchData)({
|
|
114
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
115
|
+
apiKey: this.#accessKey,
|
|
116
|
+
stagingUrl: this.#stagingUrl,
|
|
117
|
+
body: {
|
|
118
|
+
objectKey: res?.key,
|
|
119
|
+
uploadId: res?.uploadId,
|
|
120
|
+
partNumber: i + 1,
|
|
121
|
+
},
|
|
122
|
+
throwError: true,
|
|
123
|
+
});
|
|
124
|
+
const val = await axios_1.default.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
|
|
125
|
+
parts.push({ PartNumber: i + 1, ETag: val?.headers?.etag });
|
|
126
|
+
}
|
|
127
|
+
const completeValue = await (0, utils_js_1.fetchData)({
|
|
128
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
129
|
+
apiKey: this.#accessKey,
|
|
130
|
+
stagingUrl: this.#stagingUrl,
|
|
131
|
+
body: {
|
|
132
|
+
uploadId: res?.uploadId,
|
|
133
|
+
objectKey: res?.key,
|
|
134
|
+
parts,
|
|
135
|
+
originalFileName: file.name,
|
|
136
|
+
},
|
|
137
|
+
throwError: true,
|
|
138
|
+
});
|
|
139
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
reject(error);
|
|
143
|
+
}
|
|
141
144
|
});
|
|
142
|
-
|
|
143
|
-
} catch (error) {
|
|
144
|
-
reject(error);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
145
|
+
}
|
|
148
146
|
}
|
|
149
147
|
exports.default = FileUpload;
|
package/package.json
CHANGED
package/src/fileUpload.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
3
|
-
import { checkMetaDataValue, checkParameters, fetchData, getFileChunks } from "./utils.js";
|
|
2
|
+
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL } from "./constants.js";
|
|
3
|
+
import { checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
|
|
4
4
|
const Uppy = require("fix-esm").require("@uppy/core");
|
|
5
5
|
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
6
6
|
interface ObjMetaData {
|
|
@@ -47,6 +47,7 @@ export default class FileUpload {
|
|
|
47
47
|
this.#uppyIns.use(AwsS3Multipart.default, {
|
|
48
48
|
limit: 10,
|
|
49
49
|
retryDelays: [0, 1000, 3000, 5000],
|
|
50
|
+
companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl }),
|
|
50
51
|
getChunkSize: () => 5 * 1024 * 1024,
|
|
51
52
|
createMultipartUpload: (file: any) => {
|
|
52
53
|
const objectKey = `${scanId}.${file.extension}`;
|