@swan-admin/swan-ai-measurements 1.0.88 → 1.0.90
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.d.ts +1 -3
- package/dist/esm/fileUpload.js +51 -29
- package/dist/esm/utils.js +1 -1
- package/dist/fileUpload.d.ts +1 -3
- package/dist/fileUpload.js +42 -22
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/src/fileUpload.ts +41 -27
- package/src/utils.ts +1 -1
package/dist/esm/fileUpload.d.ts
CHANGED
|
@@ -18,8 +18,6 @@ export default class FileUpload {
|
|
|
18
18
|
#private;
|
|
19
19
|
constructor(accessKey: string);
|
|
20
20
|
uploadFileFrontend({ file, arrayMetaData, scanId }: UploadOptions): Promise<unknown>;
|
|
21
|
-
uploadFileBackend({ file, arrayMetaData, scanId }: UploadOptions): Promise<
|
|
22
|
-
message: string;
|
|
23
|
-
}>;
|
|
21
|
+
uploadFileBackend({ file, arrayMetaData, scanId }: UploadOptions): Promise<unknown>;
|
|
24
22
|
}
|
|
25
23
|
export {};
|
package/dist/esm/fileUpload.js
CHANGED
|
@@ -137,35 +137,57 @@ class FileUpload {
|
|
|
137
137
|
if (!checkMetaDataValue(arrayMetaData)) {
|
|
138
138
|
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
139
139
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
+
console.log(res, "res for start");
|
|
154
|
+
const totalChunks = getFileChunks(file);
|
|
155
|
+
console.log(totalChunks, "total chunks");
|
|
156
|
+
const parts = [];
|
|
157
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
158
|
+
const data = yield fetchData({
|
|
159
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
160
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
161
|
+
body: {
|
|
162
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
163
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
164
|
+
partNumber: i + 1,
|
|
165
|
+
},
|
|
166
|
+
throwError: true,
|
|
167
|
+
});
|
|
168
|
+
console.log(data, "data for signed url");
|
|
169
|
+
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
|
|
170
|
+
headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
|
|
171
|
+
});
|
|
172
|
+
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
173
|
+
console.log(val === null || val === void 0 ? void 0 : val.data, "after uploading");
|
|
174
|
+
}
|
|
175
|
+
const completeValue = yield fetchData({
|
|
176
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
177
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
178
|
+
body: {
|
|
179
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
180
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
181
|
+
parts,
|
|
182
|
+
originalFileName: file.name,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
186
|
+
} catch (error) {
|
|
187
|
+
reject(error);
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
);
|
|
169
191
|
});
|
|
170
192
|
}
|
|
171
193
|
}
|
package/dist/esm/utils.js
CHANGED
|
@@ -27,7 +27,7 @@ export function fetchData(options) {
|
|
|
27
27
|
catch (error) {
|
|
28
28
|
console.error(error, "while uploading");
|
|
29
29
|
if (throwError) {
|
|
30
|
-
throw new Error(`Failed to upload: ${error.message}`);
|
|
30
|
+
throw new Error(`Failed to upload: ${(error === null || error === void 0 ? void 0 : error.message) || "something went wrong"}`);
|
|
31
31
|
}
|
|
32
32
|
return {};
|
|
33
33
|
}
|
package/dist/fileUpload.d.ts
CHANGED
|
@@ -18,8 +18,6 @@ export default class FileUpload {
|
|
|
18
18
|
#private;
|
|
19
19
|
constructor(accessKey: string);
|
|
20
20
|
uploadFileFrontend({ file, arrayMetaData, scanId }: UploadOptions): Promise<unknown>;
|
|
21
|
-
uploadFileBackend({ file, arrayMetaData, scanId }: UploadOptions): Promise<
|
|
22
|
-
message: string;
|
|
23
|
-
}>;
|
|
21
|
+
uploadFileBackend({ file, arrayMetaData, scanId }: UploadOptions): Promise<unknown>;
|
|
24
22
|
}
|
|
25
23
|
export {};
|
package/dist/fileUpload.js
CHANGED
|
@@ -88,34 +88,54 @@ class FileUpload {
|
|
|
88
88
|
if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
|
|
89
89
|
throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
return new Promise(async (resolve, reject) => {
|
|
92
|
+
try {
|
|
93
|
+
const res = await (0, utils_js_1.fetchData)({
|
|
94
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
95
|
+
apiKey: this.#accessKey,
|
|
96
|
+
body: {
|
|
97
|
+
objectKey: file.name,
|
|
98
|
+
contentType: file.type,
|
|
99
|
+
objectMetadata: arrayMetaData,
|
|
100
|
+
},
|
|
101
|
+
throwError: true,
|
|
102
|
+
});
|
|
103
|
+
console.log(res, "res for start");
|
|
104
|
+
const totalChunks = (0, utils_js_1.getFileChunks)(file);
|
|
105
|
+
console.log(totalChunks, "total chunks");
|
|
106
|
+
const parts = [];
|
|
107
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
108
|
+
const data = await (0, utils_js_1.fetchData)({
|
|
109
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
110
|
+
apiKey: this.#accessKey,
|
|
111
|
+
body: {
|
|
112
|
+
objectKey: res?.key,
|
|
113
|
+
uploadId: res?.uploadId,
|
|
114
|
+
partNumber: i + 1,
|
|
115
|
+
},
|
|
116
|
+
throwError: true,
|
|
117
|
+
});
|
|
118
|
+
console.log(data, "data for signed url");
|
|
119
|
+
const val = await axios_1.default.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
|
|
120
|
+
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
121
|
+
console.log(val?.data, "after uploading");
|
|
122
|
+
}
|
|
123
|
+
const completeValue = await (0, utils_js_1.fetchData)({
|
|
124
|
+
path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
105
125
|
apiKey: this.#accessKey,
|
|
106
126
|
body: {
|
|
107
|
-
objectKey: res?.key,
|
|
108
127
|
uploadId: res?.uploadId,
|
|
109
|
-
|
|
128
|
+
objectKey: res?.key,
|
|
129
|
+
parts,
|
|
130
|
+
originalFileName: file.name,
|
|
110
131
|
},
|
|
111
132
|
});
|
|
112
|
-
|
|
133
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
113
134
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
reject(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
119
139
|
}
|
|
120
140
|
}
|
|
121
141
|
exports.default = FileUpload;
|
package/dist/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ async function fetchData(options) {
|
|
|
23
23
|
catch (error) {
|
|
24
24
|
console.error(error, "while uploading");
|
|
25
25
|
if (throwError) {
|
|
26
|
-
throw new Error(`Failed to upload: ${error
|
|
26
|
+
throw new Error(`Failed to upload: ${error?.message || "something went wrong"}`);
|
|
27
27
|
}
|
|
28
28
|
return {};
|
|
29
29
|
}
|
package/package.json
CHANGED
package/src/fileUpload.ts
CHANGED
|
@@ -110,38 +110,52 @@ export default class FileUpload {
|
|
|
110
110
|
if (!checkMetaDataValue(arrayMetaData)) {
|
|
111
111
|
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
apiKey: this.#accessKey,
|
|
118
|
-
body: {
|
|
119
|
-
objectKey: file.name,
|
|
120
|
-
contentType: file.type,
|
|
121
|
-
objectMetadata: arrayMetaData,
|
|
122
|
-
},
|
|
123
|
-
throwError: true,
|
|
124
|
-
});
|
|
125
|
-
console.log(res, "res for start");
|
|
126
|
-
const totalChunks = getFileChunks(file);
|
|
127
|
-
console.log(totalChunks, "total chunks");
|
|
128
|
-
for (let i = 0; i < totalChunks.length; i++) {
|
|
129
|
-
const data: { url: string } = await fetchData({
|
|
130
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
113
|
+
return new Promise(async (resolve, reject) => {
|
|
114
|
+
try {
|
|
115
|
+
const res: { key: string; uploadId: string } = await fetchData({
|
|
116
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
131
117
|
apiKey: this.#accessKey,
|
|
132
118
|
body: {
|
|
133
|
-
objectKey:
|
|
134
|
-
|
|
135
|
-
|
|
119
|
+
objectKey: file.name,
|
|
120
|
+
contentType: file.type,
|
|
121
|
+
objectMetadata: arrayMetaData,
|
|
136
122
|
},
|
|
137
123
|
throwError: true,
|
|
138
124
|
});
|
|
139
|
-
console.log(
|
|
140
|
-
|
|
125
|
+
console.log(res, "res for start");
|
|
126
|
+
const totalChunks = getFileChunks(file);
|
|
127
|
+
console.log(totalChunks, "total chunks");
|
|
128
|
+
const parts = [];
|
|
129
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
130
|
+
const data: { url: string } = await fetchData({
|
|
131
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
132
|
+
apiKey: this.#accessKey,
|
|
133
|
+
body: {
|
|
134
|
+
objectKey: res?.key,
|
|
135
|
+
uploadId: res?.uploadId,
|
|
136
|
+
partNumber: i + 1,
|
|
137
|
+
},
|
|
138
|
+
throwError: true,
|
|
139
|
+
});
|
|
140
|
+
console.log(data, "data for signed url");
|
|
141
|
+
const val = await axios.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
|
|
142
|
+
parts.push({ PartNumber: i + 1, ETag: '"958057f9cd1d264e94fcc0d2ccabc09f"' });
|
|
143
|
+
console.log(val?.data, "after uploading");
|
|
144
|
+
}
|
|
145
|
+
const completeValue = await fetchData({
|
|
146
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
147
|
+
apiKey: this.#accessKey,
|
|
148
|
+
body: {
|
|
149
|
+
uploadId: res?.uploadId,
|
|
150
|
+
objectKey: res?.key,
|
|
151
|
+
parts,
|
|
152
|
+
originalFileName: file.name,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
156
|
+
} catch (error: any) {
|
|
157
|
+
reject(error);
|
|
141
158
|
}
|
|
142
|
-
|
|
143
|
-
} catch (error: any) {
|
|
144
|
-
throw new Error(`Failed to upload: ${error?.message || "something went wrong"}`);
|
|
145
|
-
}
|
|
159
|
+
});
|
|
146
160
|
}
|
|
147
161
|
}
|
package/src/utils.ts
CHANGED
|
@@ -76,7 +76,7 @@ export function checkMetaDataValue(arr: ObjMetaData[]): boolean {
|
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export function getFileChunks(file: File, chunkSize = 5 * 1024 * 1024) {
|
|
79
|
+
export function getFileChunks(file: File, chunkSize = 5 * 1024 * 1024): Blob[] {
|
|
80
80
|
const totalSize = file.size;
|
|
81
81
|
const chunks = [];
|
|
82
82
|
let start = 0;
|