hydrousdb 3.5.3 → 3.5.4
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 +26 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +26 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -149,7 +149,7 @@ var HttpClient = class {
|
|
|
149
149
|
* Uses XHR in browsers for onprogress support; fetch in Node.
|
|
150
150
|
*/
|
|
151
151
|
async putToSignedUrl(signedUrl, data, mimeType, onProgress) {
|
|
152
|
-
const body = data
|
|
152
|
+
const body = data;
|
|
153
153
|
if (typeof XMLHttpRequest !== "undefined" && typeof onProgress === "function") {
|
|
154
154
|
await new Promise((resolve, reject) => {
|
|
155
155
|
const xhr = new XMLHttpRequest();
|
|
@@ -1061,8 +1061,32 @@ var StorageManager = class {
|
|
|
1061
1061
|
* ```
|
|
1062
1062
|
*/
|
|
1063
1063
|
async upload(data, path, options = {}) {
|
|
1064
|
-
const { isPublic = false, overwrite = false, mimeType } = options;
|
|
1064
|
+
const { isPublic = false, overwrite = false, mimeType, onProgress } = options;
|
|
1065
1065
|
const mime = mimeType ?? guessMimeType(path);
|
|
1066
|
+
let size = 0;
|
|
1067
|
+
if (data instanceof Blob) {
|
|
1068
|
+
size = data.size;
|
|
1069
|
+
} else if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
1070
|
+
size = data.byteLength;
|
|
1071
|
+
} else if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
|
|
1072
|
+
size = data.length;
|
|
1073
|
+
}
|
|
1074
|
+
const useDirectUpload = onProgress !== void 0 || size > 5 * 1024 * 1024;
|
|
1075
|
+
if (useDirectUpload) {
|
|
1076
|
+
const { uploadUrl, path: cleanPath } = await this.getUploadUrl({
|
|
1077
|
+
path,
|
|
1078
|
+
mimeType: mime,
|
|
1079
|
+
size,
|
|
1080
|
+
isPublic,
|
|
1081
|
+
overwrite
|
|
1082
|
+
});
|
|
1083
|
+
await this.uploadToSignedUrl(uploadUrl, data, mime, onProgress);
|
|
1084
|
+
return this.confirmUpload({
|
|
1085
|
+
path: cleanPath,
|
|
1086
|
+
mimeType: mime,
|
|
1087
|
+
isPublic
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1066
1090
|
const formData = new FormData();
|
|
1067
1091
|
const blob = data instanceof Blob ? data : new Blob([data], { type: mime });
|
|
1068
1092
|
formData.append("file", blob, path.split("/").pop() ?? "file");
|