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