@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.
@@ -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 {};
@@ -137,35 +137,57 @@ class FileUpload {
137
137
  if (!checkMetaDataValue(arrayMetaData)) {
138
138
  throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
139
139
  }
140
- try {
141
- const res = yield fetchData({
142
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
143
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
144
- body: {
145
- objectKey: file.name,
146
- contentType: file.type,
147
- objectMetadata: arrayMetaData,
148
- },
149
- });
150
- const totalChunks = getFileChunks(file);
151
- for (let i = 0; i < totalChunks.length; i++) {
152
- const data = yield fetchData({
153
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
154
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
155
- body: {
156
- objectKey: res === null || res === void 0 ? void 0 : res.key,
157
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
158
- partNumber: i + 1,
159
- },
160
- });
161
- yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
162
- headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
163
- });
164
- }
165
- return { message: "successfully uploaded" };
166
- } catch (error) {
167
- throw new Error(`Failed to upload: ${error === null || error === void 0 ? void 0 : error.message}`);
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
  }
@@ -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 {};
@@ -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
- try {
92
- const res = await (0, utils_js_1.fetchData)({
93
- path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_START,
94
- apiKey: this.#accessKey,
95
- body: {
96
- objectKey: file.name,
97
- contentType: file.type,
98
- objectMetadata: arrayMetaData,
99
- },
100
- });
101
- const totalChunks = (0, utils_js_1.getFileChunks)(file);
102
- for (let i = 0; i < totalChunks.length; i++) {
103
- const data = await (0, utils_js_1.fetchData)({
104
- path: constants_js_1.FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
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
- partNumber: i + 1,
128
+ objectKey: res?.key,
129
+ parts,
130
+ originalFileName: file.name,
110
131
  },
111
132
  });
112
- await axios_1.default.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
133
+ resolve({ message: "successfully uploaded", data: completeValue });
113
134
  }
114
- return { message: "successfully uploaded" };
115
- }
116
- catch (error) {
117
- throw new Error(`Failed to upload: ${error?.message}`);
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.message}`);
26
+ throw new Error(`Failed to upload: ${error?.message || "something went wrong"}`);
27
27
  }
28
28
  return {};
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.88",
3
+ "version": "1.0.90",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
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
- try {
115
- const res: { key: string; uploadId: string } = await fetchData({
116
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
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: res?.key,
134
- uploadId: res?.uploadId,
135
- partNumber: i + 1,
119
+ objectKey: file.name,
120
+ contentType: file.type,
121
+ objectMetadata: arrayMetaData,
136
122
  },
137
123
  throwError: true,
138
124
  });
139
- console.log(data, "data for signed url");
140
- await axios.put(data?.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": this.#accessKey } });
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
- return { message: "successfully uploaded" };
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;