@sparkstudio/storage-ui 1.0.8 → 1.0.11
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/index.cjs +48 -11
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +48 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -109,8 +109,23 @@ var Container = class {
|
|
|
109
109
|
if (!response.ok) throw new Error(await response.text());
|
|
110
110
|
return await response.json();
|
|
111
111
|
}
|
|
112
|
-
async
|
|
113
|
-
const url = `${this.baseUrl}/api/Container/
|
|
112
|
+
async DeleteS3(containerDTO) {
|
|
113
|
+
const url = `${this.baseUrl}/api/Container/DeleteS3`;
|
|
114
|
+
const token = localStorage.getItem("auth_token");
|
|
115
|
+
const requestOptions = {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
...token && { Authorization: `Bearer ${token}` }
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify(containerDTO)
|
|
122
|
+
};
|
|
123
|
+
const response = await fetch(url, requestOptions);
|
|
124
|
+
if (!response.ok) throw new Error(await response.text());
|
|
125
|
+
return await response.json();
|
|
126
|
+
}
|
|
127
|
+
async DeleteContainer(id) {
|
|
128
|
+
const url = `${this.baseUrl}/api/Container/DeleteContainer/` + id;
|
|
114
129
|
const token = localStorage.getItem("auth_token");
|
|
115
130
|
const requestOptions = {
|
|
116
131
|
method: "GET",
|
|
@@ -123,8 +138,8 @@ var Container = class {
|
|
|
123
138
|
if (!response.ok) throw new Error(await response.text());
|
|
124
139
|
return await response.json();
|
|
125
140
|
}
|
|
126
|
-
async
|
|
127
|
-
const url = `${this.baseUrl}/api/Container/
|
|
141
|
+
async CreateFileContainer(fileName, size, contentType) {
|
|
142
|
+
const url = `${this.baseUrl}/api/Container/CreateFileContainer/` + fileName + `/` + size + `/` + contentType;
|
|
128
143
|
const token = localStorage.getItem("auth_token");
|
|
129
144
|
const requestOptions = {
|
|
130
145
|
method: "GET",
|
|
@@ -137,6 +152,21 @@ var Container = class {
|
|
|
137
152
|
if (!response.ok) throw new Error(await response.text());
|
|
138
153
|
return await response.json();
|
|
139
154
|
}
|
|
155
|
+
async GetPreSignedUrl(containerDTO) {
|
|
156
|
+
const url = `${this.baseUrl}/api/Container/GetPreSignedUrl`;
|
|
157
|
+
const token = localStorage.getItem("auth_token");
|
|
158
|
+
const requestOptions = {
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: {
|
|
161
|
+
"Content-Type": "application/json",
|
|
162
|
+
...token && { Authorization: `Bearer ${token}` }
|
|
163
|
+
},
|
|
164
|
+
body: JSON.stringify(containerDTO)
|
|
165
|
+
};
|
|
166
|
+
const response = await fetch(url, requestOptions);
|
|
167
|
+
if (!response.ok) throw new Error(await response.text());
|
|
168
|
+
return await response.json();
|
|
169
|
+
}
|
|
140
170
|
};
|
|
141
171
|
|
|
142
172
|
// src/api/Controllers/Home.ts
|
|
@@ -240,17 +270,18 @@ var UploadContainer = ({
|
|
|
240
270
|
throw new Error("getPresignedUrl is not provided.");
|
|
241
271
|
}
|
|
242
272
|
const presignedUrl = await getPresignedUrl(upload.file);
|
|
243
|
-
|
|
273
|
+
const url = presignedUrl?.PresignedUrl ?? "";
|
|
274
|
+
await uploadFileToS3(upload.file, url, (progress) => {
|
|
244
275
|
setUploads(
|
|
245
276
|
(prev) => prev.map(
|
|
246
277
|
(u) => u.id === upload.id ? { ...u, progress } : u
|
|
247
278
|
)
|
|
248
279
|
);
|
|
249
280
|
});
|
|
250
|
-
const fileUrl =
|
|
281
|
+
const fileUrl = url.split("?")[0];
|
|
251
282
|
setUploads(
|
|
252
283
|
(prev) => prev.map(
|
|
253
|
-
(u) => u.id === upload.id ? { ...u, status: "success", progress: 100, s3Url: fileUrl } : u
|
|
284
|
+
(u) => u.id === upload.id ? { ...u, status: "success", progress: 100, s3Url: fileUrl, publicUrl: presignedUrl.PublicUrl } : u
|
|
254
285
|
)
|
|
255
286
|
);
|
|
256
287
|
onUploadComplete?.(upload.file, fileUrl);
|
|
@@ -331,7 +362,11 @@ var UploadContainer = ({
|
|
|
331
362
|
] }),
|
|
332
363
|
uploads.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mt-3", children: uploads.map((u) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mb-2", children: [
|
|
333
364
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "d-flex justify-content-between small mb-1", children: [
|
|
334
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
365
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
366
|
+
u.file.name,
|
|
367
|
+
" - ",
|
|
368
|
+
u?.publicUrl ?? ""
|
|
369
|
+
] }),
|
|
335
370
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: u.status === "success" ? "Completed" : u.status === "error" ? "Error" : `${u.progress}%` })
|
|
336
371
|
] }),
|
|
337
372
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "progress", style: { height: "6px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -387,9 +422,11 @@ function HomeView() {
|
|
|
387
422
|
alert(user?.Id);
|
|
388
423
|
}
|
|
389
424
|
const getPresignedUrl = async (file) => {
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
|
|
425
|
+
const sdkDb = new SparkStudioStorageSDK("https://lf9zyufpuk.execute-api.us-east-2.amazonaws.com/Prod");
|
|
426
|
+
const sdkS3 = new SparkStudioStorageSDK("https://iq0gmcn0pd.execute-api.us-east-2.amazonaws.com/Prod");
|
|
427
|
+
const containerDTO = await sdkDb.container.CreateFileContainer(file.name, file.size, encodeURIComponent(file.type));
|
|
428
|
+
const resultS3 = await sdkS3.container.GetPreSignedUrl(containerDTO);
|
|
429
|
+
return resultS3;
|
|
393
430
|
};
|
|
394
431
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
395
432
|
import_authentication_ui.AuthenticatorProvider,
|
package/dist/index.d.cts
CHANGED
|
@@ -60,8 +60,10 @@ declare class Container {
|
|
|
60
60
|
Read(id: string): Promise<ContainerDTO>;
|
|
61
61
|
Create(containerDTO: ContainerDTO): Promise<ContainerDTO>;
|
|
62
62
|
Update(containerDTO: ContainerDTO): Promise<ContainerDTO>;
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
DeleteS3(containerDTO: ContainerDTO): Promise<ContainerDTO>;
|
|
64
|
+
DeleteContainer(id: string): Promise<ContainerDTO>;
|
|
65
|
+
CreateFileContainer(fileName: string, size: number, contentType: string): Promise<ContainerDTO>;
|
|
66
|
+
GetPreSignedUrl(containerDTO: ContainerDTO): Promise<AWSPresignedUrlDTO>;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -96,7 +98,7 @@ interface UploadContainerProps {
|
|
|
96
98
|
* Your function that returns a pre-signed URL for a given file.
|
|
97
99
|
* Typically calls your backend: /api/uploads/presign
|
|
98
100
|
*/
|
|
99
|
-
getPresignedUrl?: (file: File) => Promise<
|
|
101
|
+
getPresignedUrl?: (file: File) => Promise<AWSPresignedUrlDTO>;
|
|
100
102
|
/**
|
|
101
103
|
* Called when a file has successfully finished uploading.
|
|
102
104
|
* s3Url is usually the final S3 object URL or key (depends on your backend).
|
package/dist/index.d.ts
CHANGED
|
@@ -60,8 +60,10 @@ declare class Container {
|
|
|
60
60
|
Read(id: string): Promise<ContainerDTO>;
|
|
61
61
|
Create(containerDTO: ContainerDTO): Promise<ContainerDTO>;
|
|
62
62
|
Update(containerDTO: ContainerDTO): Promise<ContainerDTO>;
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
DeleteS3(containerDTO: ContainerDTO): Promise<ContainerDTO>;
|
|
64
|
+
DeleteContainer(id: string): Promise<ContainerDTO>;
|
|
65
|
+
CreateFileContainer(fileName: string, size: number, contentType: string): Promise<ContainerDTO>;
|
|
66
|
+
GetPreSignedUrl(containerDTO: ContainerDTO): Promise<AWSPresignedUrlDTO>;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -96,7 +98,7 @@ interface UploadContainerProps {
|
|
|
96
98
|
* Your function that returns a pre-signed URL for a given file.
|
|
97
99
|
* Typically calls your backend: /api/uploads/presign
|
|
98
100
|
*/
|
|
99
|
-
getPresignedUrl?: (file: File) => Promise<
|
|
101
|
+
getPresignedUrl?: (file: File) => Promise<AWSPresignedUrlDTO>;
|
|
100
102
|
/**
|
|
101
103
|
* Called when a file has successfully finished uploading.
|
|
102
104
|
* s3Url is usually the final S3 object URL or key (depends on your backend).
|
package/dist/index.js
CHANGED
|
@@ -76,8 +76,23 @@ var Container = class {
|
|
|
76
76
|
if (!response.ok) throw new Error(await response.text());
|
|
77
77
|
return await response.json();
|
|
78
78
|
}
|
|
79
|
-
async
|
|
80
|
-
const url = `${this.baseUrl}/api/Container/
|
|
79
|
+
async DeleteS3(containerDTO) {
|
|
80
|
+
const url = `${this.baseUrl}/api/Container/DeleteS3`;
|
|
81
|
+
const token = localStorage.getItem("auth_token");
|
|
82
|
+
const requestOptions = {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
...token && { Authorization: `Bearer ${token}` }
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify(containerDTO)
|
|
89
|
+
};
|
|
90
|
+
const response = await fetch(url, requestOptions);
|
|
91
|
+
if (!response.ok) throw new Error(await response.text());
|
|
92
|
+
return await response.json();
|
|
93
|
+
}
|
|
94
|
+
async DeleteContainer(id) {
|
|
95
|
+
const url = `${this.baseUrl}/api/Container/DeleteContainer/` + id;
|
|
81
96
|
const token = localStorage.getItem("auth_token");
|
|
82
97
|
const requestOptions = {
|
|
83
98
|
method: "GET",
|
|
@@ -90,8 +105,8 @@ var Container = class {
|
|
|
90
105
|
if (!response.ok) throw new Error(await response.text());
|
|
91
106
|
return await response.json();
|
|
92
107
|
}
|
|
93
|
-
async
|
|
94
|
-
const url = `${this.baseUrl}/api/Container/
|
|
108
|
+
async CreateFileContainer(fileName, size, contentType) {
|
|
109
|
+
const url = `${this.baseUrl}/api/Container/CreateFileContainer/` + fileName + `/` + size + `/` + contentType;
|
|
95
110
|
const token = localStorage.getItem("auth_token");
|
|
96
111
|
const requestOptions = {
|
|
97
112
|
method: "GET",
|
|
@@ -104,6 +119,21 @@ var Container = class {
|
|
|
104
119
|
if (!response.ok) throw new Error(await response.text());
|
|
105
120
|
return await response.json();
|
|
106
121
|
}
|
|
122
|
+
async GetPreSignedUrl(containerDTO) {
|
|
123
|
+
const url = `${this.baseUrl}/api/Container/GetPreSignedUrl`;
|
|
124
|
+
const token = localStorage.getItem("auth_token");
|
|
125
|
+
const requestOptions = {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
...token && { Authorization: `Bearer ${token}` }
|
|
130
|
+
},
|
|
131
|
+
body: JSON.stringify(containerDTO)
|
|
132
|
+
};
|
|
133
|
+
const response = await fetch(url, requestOptions);
|
|
134
|
+
if (!response.ok) throw new Error(await response.text());
|
|
135
|
+
return await response.json();
|
|
136
|
+
}
|
|
107
137
|
};
|
|
108
138
|
|
|
109
139
|
// src/api/Controllers/Home.ts
|
|
@@ -207,17 +237,18 @@ var UploadContainer = ({
|
|
|
207
237
|
throw new Error("getPresignedUrl is not provided.");
|
|
208
238
|
}
|
|
209
239
|
const presignedUrl = await getPresignedUrl(upload.file);
|
|
210
|
-
|
|
240
|
+
const url = presignedUrl?.PresignedUrl ?? "";
|
|
241
|
+
await uploadFileToS3(upload.file, url, (progress) => {
|
|
211
242
|
setUploads(
|
|
212
243
|
(prev) => prev.map(
|
|
213
244
|
(u) => u.id === upload.id ? { ...u, progress } : u
|
|
214
245
|
)
|
|
215
246
|
);
|
|
216
247
|
});
|
|
217
|
-
const fileUrl =
|
|
248
|
+
const fileUrl = url.split("?")[0];
|
|
218
249
|
setUploads(
|
|
219
250
|
(prev) => prev.map(
|
|
220
|
-
(u) => u.id === upload.id ? { ...u, status: "success", progress: 100, s3Url: fileUrl } : u
|
|
251
|
+
(u) => u.id === upload.id ? { ...u, status: "success", progress: 100, s3Url: fileUrl, publicUrl: presignedUrl.PublicUrl } : u
|
|
221
252
|
)
|
|
222
253
|
);
|
|
223
254
|
onUploadComplete?.(upload.file, fileUrl);
|
|
@@ -298,7 +329,11 @@ var UploadContainer = ({
|
|
|
298
329
|
] }),
|
|
299
330
|
uploads.length > 0 && /* @__PURE__ */ jsx("div", { className: "mt-3", children: uploads.map((u) => /* @__PURE__ */ jsxs("div", { className: "mb-2", children: [
|
|
300
331
|
/* @__PURE__ */ jsxs("div", { className: "d-flex justify-content-between small mb-1", children: [
|
|
301
|
-
/* @__PURE__ */
|
|
332
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
333
|
+
u.file.name,
|
|
334
|
+
" - ",
|
|
335
|
+
u?.publicUrl ?? ""
|
|
336
|
+
] }),
|
|
302
337
|
/* @__PURE__ */ jsx("span", { children: u.status === "success" ? "Completed" : u.status === "error" ? "Error" : `${u.progress}%` })
|
|
303
338
|
] }),
|
|
304
339
|
/* @__PURE__ */ jsx("div", { className: "progress", style: { height: "6px" }, children: /* @__PURE__ */ jsx(
|
|
@@ -354,9 +389,11 @@ function HomeView() {
|
|
|
354
389
|
alert(user?.Id);
|
|
355
390
|
}
|
|
356
391
|
const getPresignedUrl = async (file) => {
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
|
|
392
|
+
const sdkDb = new SparkStudioStorageSDK("https://lf9zyufpuk.execute-api.us-east-2.amazonaws.com/Prod");
|
|
393
|
+
const sdkS3 = new SparkStudioStorageSDK("https://iq0gmcn0pd.execute-api.us-east-2.amazonaws.com/Prod");
|
|
394
|
+
const containerDTO = await sdkDb.container.CreateFileContainer(file.name, file.size, encodeURIComponent(file.type));
|
|
395
|
+
const resultS3 = await sdkS3.container.GetPreSignedUrl(containerDTO);
|
|
396
|
+
return resultS3;
|
|
360
397
|
};
|
|
361
398
|
return /* @__PURE__ */ jsxs2(
|
|
362
399
|
AuthenticatorProvider,
|