microboard-temp 0.5.69 → 0.5.71

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.
@@ -678,6 +678,7 @@ __export(exports_browser, {
678
678
  getPlaceholderImage: () => getPlaceholderImage,
679
679
  getHotkeyLabel: () => getHotkeyLabel,
680
680
  getControlPointData: () => getControlPointData,
681
+ getBlobFromDataURL: () => getBlobFromDataURL,
681
682
  forceNumberIntoInterval: () => forceNumberIntoInterval,
682
683
  fileTosha256: () => fileTosha256,
683
684
  exportBoardSnapshot: () => exportBoardSnapshot,
@@ -41289,14 +41290,56 @@ async function fileTosha256(file) {
41289
41290
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
41290
41291
  }
41291
41292
 
41293
+ // src/api/MediaHelpers.ts
41294
+ var uploadMediaToStorage = async (hash, blob, accessToken, boardId, type) => {
41295
+ try {
41296
+ const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41297
+ method: "POST",
41298
+ headers: {
41299
+ "Content-Type": "application/json",
41300
+ Authorization: `Bearer ${accessToken}`
41301
+ },
41302
+ body: JSON.stringify({
41303
+ fileSize: blob.size,
41304
+ boardId,
41305
+ hash
41306
+ })
41307
+ });
41308
+ if (!generateUrlResponse.ok) {
41309
+ conf.hooks.onUploadMediaError(generateUrlResponse, type);
41310
+ throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41311
+ }
41312
+ const data = await generateUrlResponse.json();
41313
+ if (data.mediaUrl) {
41314
+ console.log("Media already exists, skipping upload.");
41315
+ return data.mediaUrl;
41316
+ }
41317
+ const { uploadUrl, promisedMediaUrl } = data;
41318
+ if (!uploadUrl || !promisedMediaUrl) {
41319
+ throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41320
+ }
41321
+ const uploadResponse = await fetch(uploadUrl, {
41322
+ method: "PUT",
41323
+ headers: {
41324
+ "Content-Type": blob.type
41325
+ },
41326
+ body: blob
41327
+ });
41328
+ if (!uploadResponse.ok) {
41329
+ console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41330
+ throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41331
+ }
41332
+ return promisedMediaUrl;
41333
+ } catch (error) {
41334
+ console.error("Media upload process error:", error);
41335
+ throw error;
41336
+ }
41337
+ };
41338
+
41292
41339
  // src/Items/Image/ImageHelpers.ts
41293
41340
  var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41294
41341
  return new Promise((resolve2, reject) => {
41295
- const base64String = dataURL.split(",")[1];
41296
- const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41297
- const binaryString = window.atob(base64String);
41298
- const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41299
- const blob = new Blob([bytes], { type: mimeType });
41342
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41300
41343
  fetch(`${window?.location.origin}/api/v1/media/image/${boardId}`, {
41301
41344
  method: "POST",
41302
41345
  headers: {
@@ -41318,6 +41361,14 @@ var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41318
41361
  });
41319
41362
  });
41320
41363
  };
41364
+ var getBlobFromDataURL = (dataURL) => {
41365
+ const base64String = dataURL.split(",")[1];
41366
+ const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41367
+ const binaryString = window.atob(base64String);
41368
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41369
+ const blob = new Blob([bytes], { type: mimeType });
41370
+ return { blob, base64String, mimeType };
41371
+ };
41321
41372
  var resizeAndConvertToPng = async (inp) => {
41322
41373
  return new Promise((resolve2, reject) => {
41323
41374
  if (typeof inp !== "string") {
@@ -41385,7 +41436,17 @@ var resizeAndConvertToPng = async (inp) => {
41385
41436
  });
41386
41437
  };
41387
41438
  var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash }) => {
41388
- return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41439
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41440
+ if (mimeType === "image/svg+xml") {
41441
+ return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41442
+ return {
41443
+ imageDimension: { width: width2, height: height2 },
41444
+ base64: dataURL,
41445
+ storageLink: src
41446
+ };
41447
+ });
41448
+ }
41449
+ return uploadMediaToStorage(hash, blob, accessToken, boardId, "image").then((src) => {
41389
41450
  return {
41390
41451
  imageDimension: { width: width2, height: height2 },
41391
41452
  base64: dataURL,
@@ -41394,52 +41455,6 @@ var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).the
41394
41455
  });
41395
41456
  });
41396
41457
 
41397
- // src/api/MediaHelpers.ts
41398
- var uploadMediaToStorage = async (hash, videoBlob, accessToken, boardId, type) => {
41399
- try {
41400
- const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41401
- method: "POST",
41402
- headers: {
41403
- "Content-Type": "application/json",
41404
- Authorization: `Bearer ${accessToken}`
41405
- },
41406
- body: JSON.stringify({
41407
- fileSize: videoBlob.size,
41408
- boardId,
41409
- hash
41410
- })
41411
- });
41412
- if (!generateUrlResponse.ok) {
41413
- conf.hooks.onUploadMediaError(generateUrlResponse, type);
41414
- throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41415
- }
41416
- const data = await generateUrlResponse.json();
41417
- if (data.mediaUrl) {
41418
- console.log("Media already exists, skipping upload.");
41419
- return data.mediaUrl;
41420
- }
41421
- const { uploadUrl, promisedMediaUrl } = data;
41422
- if (!uploadUrl || !promisedMediaUrl) {
41423
- throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41424
- }
41425
- const uploadResponse = await fetch(uploadUrl, {
41426
- method: "PUT",
41427
- headers: {
41428
- "Content-Type": videoBlob.type
41429
- },
41430
- body: videoBlob
41431
- });
41432
- if (!uploadResponse.ok) {
41433
- console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41434
- throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41435
- }
41436
- return promisedMediaUrl;
41437
- } catch (error) {
41438
- console.error("Media upload process error:", error);
41439
- throw error;
41440
- }
41441
- };
41442
-
41443
41458
  // src/Items/Video/VideoHelpers.ts
41444
41459
  var uploadVideoToStorage = async (hash, videoBlob, accessToken, boardId) => {
41445
41460
  return new Promise((resolve2, reject) => {
package/dist/cjs/index.js CHANGED
@@ -678,6 +678,7 @@ __export(exports_src, {
678
678
  getPlaceholderImage: () => getPlaceholderImage,
679
679
  getHotkeyLabel: () => getHotkeyLabel,
680
680
  getControlPointData: () => getControlPointData,
681
+ getBlobFromDataURL: () => getBlobFromDataURL,
681
682
  forceNumberIntoInterval: () => forceNumberIntoInterval,
682
683
  fileTosha256: () => fileTosha256,
683
684
  exportBoardSnapshot: () => exportBoardSnapshot,
@@ -41289,14 +41290,56 @@ async function fileTosha256(file) {
41289
41290
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
41290
41291
  }
41291
41292
 
41293
+ // src/api/MediaHelpers.ts
41294
+ var uploadMediaToStorage = async (hash, blob, accessToken, boardId, type) => {
41295
+ try {
41296
+ const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41297
+ method: "POST",
41298
+ headers: {
41299
+ "Content-Type": "application/json",
41300
+ Authorization: `Bearer ${accessToken}`
41301
+ },
41302
+ body: JSON.stringify({
41303
+ fileSize: blob.size,
41304
+ boardId,
41305
+ hash
41306
+ })
41307
+ });
41308
+ if (!generateUrlResponse.ok) {
41309
+ conf.hooks.onUploadMediaError(generateUrlResponse, type);
41310
+ throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41311
+ }
41312
+ const data = await generateUrlResponse.json();
41313
+ if (data.mediaUrl) {
41314
+ console.log("Media already exists, skipping upload.");
41315
+ return data.mediaUrl;
41316
+ }
41317
+ const { uploadUrl, promisedMediaUrl } = data;
41318
+ if (!uploadUrl || !promisedMediaUrl) {
41319
+ throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41320
+ }
41321
+ const uploadResponse = await fetch(uploadUrl, {
41322
+ method: "PUT",
41323
+ headers: {
41324
+ "Content-Type": blob.type
41325
+ },
41326
+ body: blob
41327
+ });
41328
+ if (!uploadResponse.ok) {
41329
+ console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41330
+ throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41331
+ }
41332
+ return promisedMediaUrl;
41333
+ } catch (error) {
41334
+ console.error("Media upload process error:", error);
41335
+ throw error;
41336
+ }
41337
+ };
41338
+
41292
41339
  // src/Items/Image/ImageHelpers.ts
41293
41340
  var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41294
41341
  return new Promise((resolve2, reject) => {
41295
- const base64String = dataURL.split(",")[1];
41296
- const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41297
- const binaryString = window.atob(base64String);
41298
- const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41299
- const blob = new Blob([bytes], { type: mimeType });
41342
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41300
41343
  fetch(`${window?.location.origin}/api/v1/media/image/${boardId}`, {
41301
41344
  method: "POST",
41302
41345
  headers: {
@@ -41318,6 +41361,14 @@ var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41318
41361
  });
41319
41362
  });
41320
41363
  };
41364
+ var getBlobFromDataURL = (dataURL) => {
41365
+ const base64String = dataURL.split(",")[1];
41366
+ const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41367
+ const binaryString = window.atob(base64String);
41368
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41369
+ const blob = new Blob([bytes], { type: mimeType });
41370
+ return { blob, base64String, mimeType };
41371
+ };
41321
41372
  var resizeAndConvertToPng = async (inp) => {
41322
41373
  return new Promise((resolve2, reject) => {
41323
41374
  if (typeof inp !== "string") {
@@ -41385,7 +41436,17 @@ var resizeAndConvertToPng = async (inp) => {
41385
41436
  });
41386
41437
  };
41387
41438
  var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash }) => {
41388
- return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41439
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41440
+ if (mimeType === "image/svg+xml") {
41441
+ return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41442
+ return {
41443
+ imageDimension: { width: width2, height: height2 },
41444
+ base64: dataURL,
41445
+ storageLink: src
41446
+ };
41447
+ });
41448
+ }
41449
+ return uploadMediaToStorage(hash, blob, accessToken, boardId, "image").then((src) => {
41389
41450
  return {
41390
41451
  imageDimension: { width: width2, height: height2 },
41391
41452
  base64: dataURL,
@@ -41394,52 +41455,6 @@ var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).the
41394
41455
  });
41395
41456
  });
41396
41457
 
41397
- // src/api/MediaHelpers.ts
41398
- var uploadMediaToStorage = async (hash, videoBlob, accessToken, boardId, type) => {
41399
- try {
41400
- const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41401
- method: "POST",
41402
- headers: {
41403
- "Content-Type": "application/json",
41404
- Authorization: `Bearer ${accessToken}`
41405
- },
41406
- body: JSON.stringify({
41407
- fileSize: videoBlob.size,
41408
- boardId,
41409
- hash
41410
- })
41411
- });
41412
- if (!generateUrlResponse.ok) {
41413
- conf.hooks.onUploadMediaError(generateUrlResponse, type);
41414
- throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41415
- }
41416
- const data = await generateUrlResponse.json();
41417
- if (data.mediaUrl) {
41418
- console.log("Media already exists, skipping upload.");
41419
- return data.mediaUrl;
41420
- }
41421
- const { uploadUrl, promisedMediaUrl } = data;
41422
- if (!uploadUrl || !promisedMediaUrl) {
41423
- throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41424
- }
41425
- const uploadResponse = await fetch(uploadUrl, {
41426
- method: "PUT",
41427
- headers: {
41428
- "Content-Type": videoBlob.type
41429
- },
41430
- body: videoBlob
41431
- });
41432
- if (!uploadResponse.ok) {
41433
- console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41434
- throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41435
- }
41436
- return promisedMediaUrl;
41437
- } catch (error) {
41438
- console.error("Media upload process error:", error);
41439
- throw error;
41440
- }
41441
- };
41442
-
41443
41458
  // src/Items/Video/VideoHelpers.ts
41444
41459
  var uploadVideoToStorage = async (hash, videoBlob, accessToken, boardId) => {
41445
41460
  return new Promise((resolve2, reject) => {
package/dist/cjs/node.js CHANGED
@@ -1715,6 +1715,7 @@ __export(exports_node, {
1715
1715
  getPlaceholderImage: () => getPlaceholderImage,
1716
1716
  getHotkeyLabel: () => getHotkeyLabel,
1717
1717
  getControlPointData: () => getControlPointData,
1718
+ getBlobFromDataURL: () => getBlobFromDataURL,
1718
1719
  forceNumberIntoInterval: () => forceNumberIntoInterval,
1719
1720
  fileTosha256: () => fileTosha256,
1720
1721
  exportBoardSnapshot: () => exportBoardSnapshot,
@@ -43762,14 +43763,56 @@ async function fileTosha256(file) {
43762
43763
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
43763
43764
  }
43764
43765
 
43766
+ // src/api/MediaHelpers.ts
43767
+ var uploadMediaToStorage = async (hash, blob, accessToken, boardId, type) => {
43768
+ try {
43769
+ const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
43770
+ method: "POST",
43771
+ headers: {
43772
+ "Content-Type": "application/json",
43773
+ Authorization: `Bearer ${accessToken}`
43774
+ },
43775
+ body: JSON.stringify({
43776
+ fileSize: blob.size,
43777
+ boardId,
43778
+ hash
43779
+ })
43780
+ });
43781
+ if (!generateUrlResponse.ok) {
43782
+ conf.hooks.onUploadMediaError(generateUrlResponse, type);
43783
+ throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
43784
+ }
43785
+ const data = await generateUrlResponse.json();
43786
+ if (data.mediaUrl) {
43787
+ console.log("Media already exists, skipping upload.");
43788
+ return data.mediaUrl;
43789
+ }
43790
+ const { uploadUrl, promisedMediaUrl } = data;
43791
+ if (!uploadUrl || !promisedMediaUrl) {
43792
+ throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
43793
+ }
43794
+ const uploadResponse = await fetch(uploadUrl, {
43795
+ method: "PUT",
43796
+ headers: {
43797
+ "Content-Type": blob.type
43798
+ },
43799
+ body: blob
43800
+ });
43801
+ if (!uploadResponse.ok) {
43802
+ console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
43803
+ throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
43804
+ }
43805
+ return promisedMediaUrl;
43806
+ } catch (error) {
43807
+ console.error("Media upload process error:", error);
43808
+ throw error;
43809
+ }
43810
+ };
43811
+
43765
43812
  // src/Items/Image/ImageHelpers.ts
43766
43813
  var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
43767
43814
  return new Promise((resolve2, reject) => {
43768
- const base64String = dataURL.split(",")[1];
43769
- const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
43770
- const binaryString = window.atob(base64String);
43771
- const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
43772
- const blob = new Blob([bytes], { type: mimeType });
43815
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
43773
43816
  fetch(`${window?.location.origin}/api/v1/media/image/${boardId}`, {
43774
43817
  method: "POST",
43775
43818
  headers: {
@@ -43791,6 +43834,14 @@ var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
43791
43834
  });
43792
43835
  });
43793
43836
  };
43837
+ var getBlobFromDataURL = (dataURL) => {
43838
+ const base64String = dataURL.split(",")[1];
43839
+ const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
43840
+ const binaryString = window.atob(base64String);
43841
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
43842
+ const blob = new Blob([bytes], { type: mimeType });
43843
+ return { blob, base64String, mimeType };
43844
+ };
43794
43845
  var resizeAndConvertToPng = async (inp) => {
43795
43846
  return new Promise((resolve2, reject) => {
43796
43847
  if (typeof inp !== "string") {
@@ -43858,7 +43909,17 @@ var resizeAndConvertToPng = async (inp) => {
43858
43909
  });
43859
43910
  };
43860
43911
  var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash }) => {
43861
- return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
43912
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
43913
+ if (mimeType === "image/svg+xml") {
43914
+ return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
43915
+ return {
43916
+ imageDimension: { width: width2, height: height2 },
43917
+ base64: dataURL,
43918
+ storageLink: src
43919
+ };
43920
+ });
43921
+ }
43922
+ return uploadMediaToStorage(hash, blob, accessToken, boardId, "image").then((src) => {
43862
43923
  return {
43863
43924
  imageDimension: { width: width2, height: height2 },
43864
43925
  base64: dataURL,
@@ -43867,52 +43928,6 @@ var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).the
43867
43928
  });
43868
43929
  });
43869
43930
 
43870
- // src/api/MediaHelpers.ts
43871
- var uploadMediaToStorage = async (hash, videoBlob, accessToken, boardId, type) => {
43872
- try {
43873
- const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
43874
- method: "POST",
43875
- headers: {
43876
- "Content-Type": "application/json",
43877
- Authorization: `Bearer ${accessToken}`
43878
- },
43879
- body: JSON.stringify({
43880
- fileSize: videoBlob.size,
43881
- boardId,
43882
- hash
43883
- })
43884
- });
43885
- if (!generateUrlResponse.ok) {
43886
- conf.hooks.onUploadMediaError(generateUrlResponse, type);
43887
- throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
43888
- }
43889
- const data = await generateUrlResponse.json();
43890
- if (data.mediaUrl) {
43891
- console.log("Media already exists, skipping upload.");
43892
- return data.mediaUrl;
43893
- }
43894
- const { uploadUrl, promisedMediaUrl } = data;
43895
- if (!uploadUrl || !promisedMediaUrl) {
43896
- throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
43897
- }
43898
- const uploadResponse = await fetch(uploadUrl, {
43899
- method: "PUT",
43900
- headers: {
43901
- "Content-Type": videoBlob.type
43902
- },
43903
- body: videoBlob
43904
- });
43905
- if (!uploadResponse.ok) {
43906
- console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
43907
- throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
43908
- }
43909
- return promisedMediaUrl;
43910
- } catch (error) {
43911
- console.error("Media upload process error:", error);
43912
- throw error;
43913
- }
43914
- };
43915
-
43916
43931
  // src/Items/Video/VideoHelpers.ts
43917
43932
  var uploadVideoToStorage = async (hash, videoBlob, accessToken, boardId) => {
43918
43933
  return new Promise((resolve2, reject) => {
@@ -41135,14 +41135,56 @@ async function fileTosha256(file) {
41135
41135
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
41136
41136
  }
41137
41137
 
41138
+ // src/api/MediaHelpers.ts
41139
+ var uploadMediaToStorage = async (hash, blob, accessToken, boardId, type) => {
41140
+ try {
41141
+ const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41142
+ method: "POST",
41143
+ headers: {
41144
+ "Content-Type": "application/json",
41145
+ Authorization: `Bearer ${accessToken}`
41146
+ },
41147
+ body: JSON.stringify({
41148
+ fileSize: blob.size,
41149
+ boardId,
41150
+ hash
41151
+ })
41152
+ });
41153
+ if (!generateUrlResponse.ok) {
41154
+ conf.hooks.onUploadMediaError(generateUrlResponse, type);
41155
+ throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41156
+ }
41157
+ const data = await generateUrlResponse.json();
41158
+ if (data.mediaUrl) {
41159
+ console.log("Media already exists, skipping upload.");
41160
+ return data.mediaUrl;
41161
+ }
41162
+ const { uploadUrl, promisedMediaUrl } = data;
41163
+ if (!uploadUrl || !promisedMediaUrl) {
41164
+ throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41165
+ }
41166
+ const uploadResponse = await fetch(uploadUrl, {
41167
+ method: "PUT",
41168
+ headers: {
41169
+ "Content-Type": blob.type
41170
+ },
41171
+ body: blob
41172
+ });
41173
+ if (!uploadResponse.ok) {
41174
+ console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41175
+ throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41176
+ }
41177
+ return promisedMediaUrl;
41178
+ } catch (error) {
41179
+ console.error("Media upload process error:", error);
41180
+ throw error;
41181
+ }
41182
+ };
41183
+
41138
41184
  // src/Items/Image/ImageHelpers.ts
41139
41185
  var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41140
41186
  return new Promise((resolve2, reject) => {
41141
- const base64String = dataURL.split(",")[1];
41142
- const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41143
- const binaryString = window.atob(base64String);
41144
- const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41145
- const blob = new Blob([bytes], { type: mimeType });
41187
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41146
41188
  fetch(`${window?.location.origin}/api/v1/media/image/${boardId}`, {
41147
41189
  method: "POST",
41148
41190
  headers: {
@@ -41164,6 +41206,14 @@ var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41164
41206
  });
41165
41207
  });
41166
41208
  };
41209
+ var getBlobFromDataURL = (dataURL) => {
41210
+ const base64String = dataURL.split(",")[1];
41211
+ const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41212
+ const binaryString = window.atob(base64String);
41213
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41214
+ const blob = new Blob([bytes], { type: mimeType });
41215
+ return { blob, base64String, mimeType };
41216
+ };
41167
41217
  var resizeAndConvertToPng = async (inp) => {
41168
41218
  return new Promise((resolve2, reject) => {
41169
41219
  if (typeof inp !== "string") {
@@ -41231,7 +41281,17 @@ var resizeAndConvertToPng = async (inp) => {
41231
41281
  });
41232
41282
  };
41233
41283
  var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash }) => {
41234
- return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41284
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41285
+ if (mimeType === "image/svg+xml") {
41286
+ return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41287
+ return {
41288
+ imageDimension: { width: width2, height: height2 },
41289
+ base64: dataURL,
41290
+ storageLink: src
41291
+ };
41292
+ });
41293
+ }
41294
+ return uploadMediaToStorage(hash, blob, accessToken, boardId, "image").then((src) => {
41235
41295
  return {
41236
41296
  imageDimension: { width: width2, height: height2 },
41237
41297
  base64: dataURL,
@@ -41240,52 +41300,6 @@ var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).the
41240
41300
  });
41241
41301
  });
41242
41302
 
41243
- // src/api/MediaHelpers.ts
41244
- var uploadMediaToStorage = async (hash, videoBlob, accessToken, boardId, type) => {
41245
- try {
41246
- const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41247
- method: "POST",
41248
- headers: {
41249
- "Content-Type": "application/json",
41250
- Authorization: `Bearer ${accessToken}`
41251
- },
41252
- body: JSON.stringify({
41253
- fileSize: videoBlob.size,
41254
- boardId,
41255
- hash
41256
- })
41257
- });
41258
- if (!generateUrlResponse.ok) {
41259
- conf.hooks.onUploadMediaError(generateUrlResponse, type);
41260
- throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41261
- }
41262
- const data = await generateUrlResponse.json();
41263
- if (data.mediaUrl) {
41264
- console.log("Media already exists, skipping upload.");
41265
- return data.mediaUrl;
41266
- }
41267
- const { uploadUrl, promisedMediaUrl } = data;
41268
- if (!uploadUrl || !promisedMediaUrl) {
41269
- throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41270
- }
41271
- const uploadResponse = await fetch(uploadUrl, {
41272
- method: "PUT",
41273
- headers: {
41274
- "Content-Type": videoBlob.type
41275
- },
41276
- body: videoBlob
41277
- });
41278
- if (!uploadResponse.ok) {
41279
- console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41280
- throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41281
- }
41282
- return promisedMediaUrl;
41283
- } catch (error) {
41284
- console.error("Media upload process error:", error);
41285
- throw error;
41286
- }
41287
- };
41288
-
41289
41303
  // src/Items/Video/VideoHelpers.ts
41290
41304
  var uploadVideoToStorage = async (hash, videoBlob, accessToken, boardId) => {
41291
41305
  return new Promise((resolve2, reject) => {
@@ -57090,6 +57104,7 @@ export {
57090
57104
  getPlaceholderImage,
57091
57105
  getHotkeyLabel,
57092
57106
  getControlPointData,
57107
+ getBlobFromDataURL,
57093
57108
  forceNumberIntoInterval,
57094
57109
  fileTosha256,
57095
57110
  exportBoardSnapshot,
package/dist/esm/index.js CHANGED
@@ -41128,14 +41128,56 @@ async function fileTosha256(file) {
41128
41128
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
41129
41129
  }
41130
41130
 
41131
+ // src/api/MediaHelpers.ts
41132
+ var uploadMediaToStorage = async (hash, blob, accessToken, boardId, type) => {
41133
+ try {
41134
+ const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41135
+ method: "POST",
41136
+ headers: {
41137
+ "Content-Type": "application/json",
41138
+ Authorization: `Bearer ${accessToken}`
41139
+ },
41140
+ body: JSON.stringify({
41141
+ fileSize: blob.size,
41142
+ boardId,
41143
+ hash
41144
+ })
41145
+ });
41146
+ if (!generateUrlResponse.ok) {
41147
+ conf.hooks.onUploadMediaError(generateUrlResponse, type);
41148
+ throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41149
+ }
41150
+ const data = await generateUrlResponse.json();
41151
+ if (data.mediaUrl) {
41152
+ console.log("Media already exists, skipping upload.");
41153
+ return data.mediaUrl;
41154
+ }
41155
+ const { uploadUrl, promisedMediaUrl } = data;
41156
+ if (!uploadUrl || !promisedMediaUrl) {
41157
+ throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41158
+ }
41159
+ const uploadResponse = await fetch(uploadUrl, {
41160
+ method: "PUT",
41161
+ headers: {
41162
+ "Content-Type": blob.type
41163
+ },
41164
+ body: blob
41165
+ });
41166
+ if (!uploadResponse.ok) {
41167
+ console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41168
+ throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41169
+ }
41170
+ return promisedMediaUrl;
41171
+ } catch (error) {
41172
+ console.error("Media upload process error:", error);
41173
+ throw error;
41174
+ }
41175
+ };
41176
+
41131
41177
  // src/Items/Image/ImageHelpers.ts
41132
41178
  var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41133
41179
  return new Promise((resolve2, reject) => {
41134
- const base64String = dataURL.split(",")[1];
41135
- const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41136
- const binaryString = window.atob(base64String);
41137
- const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41138
- const blob = new Blob([bytes], { type: mimeType });
41180
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41139
41181
  fetch(`${window?.location.origin}/api/v1/media/image/${boardId}`, {
41140
41182
  method: "POST",
41141
41183
  headers: {
@@ -41157,6 +41199,14 @@ var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
41157
41199
  });
41158
41200
  });
41159
41201
  };
41202
+ var getBlobFromDataURL = (dataURL) => {
41203
+ const base64String = dataURL.split(",")[1];
41204
+ const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
41205
+ const binaryString = window.atob(base64String);
41206
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
41207
+ const blob = new Blob([bytes], { type: mimeType });
41208
+ return { blob, base64String, mimeType };
41209
+ };
41160
41210
  var resizeAndConvertToPng = async (inp) => {
41161
41211
  return new Promise((resolve2, reject) => {
41162
41212
  if (typeof inp !== "string") {
@@ -41224,7 +41274,17 @@ var resizeAndConvertToPng = async (inp) => {
41224
41274
  });
41225
41275
  };
41226
41276
  var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash }) => {
41227
- return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41277
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
41278
+ if (mimeType === "image/svg+xml") {
41279
+ return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
41280
+ return {
41281
+ imageDimension: { width: width2, height: height2 },
41282
+ base64: dataURL,
41283
+ storageLink: src
41284
+ };
41285
+ });
41286
+ }
41287
+ return uploadMediaToStorage(hash, blob, accessToken, boardId, "image").then((src) => {
41228
41288
  return {
41229
41289
  imageDimension: { width: width2, height: height2 },
41230
41290
  base64: dataURL,
@@ -41233,52 +41293,6 @@ var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).the
41233
41293
  });
41234
41294
  });
41235
41295
 
41236
- // src/api/MediaHelpers.ts
41237
- var uploadMediaToStorage = async (hash, videoBlob, accessToken, boardId, type) => {
41238
- try {
41239
- const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
41240
- method: "POST",
41241
- headers: {
41242
- "Content-Type": "application/json",
41243
- Authorization: `Bearer ${accessToken}`
41244
- },
41245
- body: JSON.stringify({
41246
- fileSize: videoBlob.size,
41247
- boardId,
41248
- hash
41249
- })
41250
- });
41251
- if (!generateUrlResponse.ok) {
41252
- conf.hooks.onUploadMediaError(generateUrlResponse, type);
41253
- throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
41254
- }
41255
- const data = await generateUrlResponse.json();
41256
- if (data.mediaUrl) {
41257
- console.log("Media already exists, skipping upload.");
41258
- return data.mediaUrl;
41259
- }
41260
- const { uploadUrl, promisedMediaUrl } = data;
41261
- if (!uploadUrl || !promisedMediaUrl) {
41262
- throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
41263
- }
41264
- const uploadResponse = await fetch(uploadUrl, {
41265
- method: "PUT",
41266
- headers: {
41267
- "Content-Type": videoBlob.type
41268
- },
41269
- body: videoBlob
41270
- });
41271
- if (!uploadResponse.ok) {
41272
- console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
41273
- throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
41274
- }
41275
- return promisedMediaUrl;
41276
- } catch (error) {
41277
- console.error("Media upload process error:", error);
41278
- throw error;
41279
- }
41280
- };
41281
-
41282
41296
  // src/Items/Video/VideoHelpers.ts
41283
41297
  var uploadVideoToStorage = async (hash, videoBlob, accessToken, boardId) => {
41284
41298
  return new Promise((resolve2, reject) => {
@@ -56988,6 +57002,7 @@ export {
56988
57002
  getPlaceholderImage,
56989
57003
  getHotkeyLabel,
56990
57004
  getControlPointData,
57005
+ getBlobFromDataURL,
56991
57006
  forceNumberIntoInterval,
56992
57007
  fileTosha256,
56993
57008
  exportBoardSnapshot,
package/dist/esm/node.js CHANGED
@@ -43596,14 +43596,56 @@ async function fileTosha256(file) {
43596
43596
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
43597
43597
  }
43598
43598
 
43599
+ // src/api/MediaHelpers.ts
43600
+ var uploadMediaToStorage = async (hash, blob, accessToken, boardId, type) => {
43601
+ try {
43602
+ const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
43603
+ method: "POST",
43604
+ headers: {
43605
+ "Content-Type": "application/json",
43606
+ Authorization: `Bearer ${accessToken}`
43607
+ },
43608
+ body: JSON.stringify({
43609
+ fileSize: blob.size,
43610
+ boardId,
43611
+ hash
43612
+ })
43613
+ });
43614
+ if (!generateUrlResponse.ok) {
43615
+ conf.hooks.onUploadMediaError(generateUrlResponse, type);
43616
+ throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
43617
+ }
43618
+ const data = await generateUrlResponse.json();
43619
+ if (data.mediaUrl) {
43620
+ console.log("Media already exists, skipping upload.");
43621
+ return data.mediaUrl;
43622
+ }
43623
+ const { uploadUrl, promisedMediaUrl } = data;
43624
+ if (!uploadUrl || !promisedMediaUrl) {
43625
+ throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
43626
+ }
43627
+ const uploadResponse = await fetch(uploadUrl, {
43628
+ method: "PUT",
43629
+ headers: {
43630
+ "Content-Type": blob.type
43631
+ },
43632
+ body: blob
43633
+ });
43634
+ if (!uploadResponse.ok) {
43635
+ console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
43636
+ throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
43637
+ }
43638
+ return promisedMediaUrl;
43639
+ } catch (error) {
43640
+ console.error("Media upload process error:", error);
43641
+ throw error;
43642
+ }
43643
+ };
43644
+
43599
43645
  // src/Items/Image/ImageHelpers.ts
43600
43646
  var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
43601
43647
  return new Promise((resolve2, reject) => {
43602
- const base64String = dataURL.split(",")[1];
43603
- const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
43604
- const binaryString = window.atob(base64String);
43605
- const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
43606
- const blob = new Blob([bytes], { type: mimeType });
43648
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
43607
43649
  fetch(`${window?.location.origin}/api/v1/media/image/${boardId}`, {
43608
43650
  method: "POST",
43609
43651
  headers: {
@@ -43625,6 +43667,14 @@ var uploadToTheStorage = async (hash, dataURL, accessToken, boardId) => {
43625
43667
  });
43626
43668
  });
43627
43669
  };
43670
+ var getBlobFromDataURL = (dataURL) => {
43671
+ const base64String = dataURL.split(",")[1];
43672
+ const mimeType = dataURL.split(",")[0].split(":")[1].split(";")[0];
43673
+ const binaryString = window.atob(base64String);
43674
+ const bytes = Uint8Array.from(binaryString, (char) => char.charCodeAt(0));
43675
+ const blob = new Blob([bytes], { type: mimeType });
43676
+ return { blob, base64String, mimeType };
43677
+ };
43628
43678
  var resizeAndConvertToPng = async (inp) => {
43629
43679
  return new Promise((resolve2, reject) => {
43630
43680
  if (typeof inp !== "string") {
@@ -43692,7 +43742,17 @@ var resizeAndConvertToPng = async (inp) => {
43692
43742
  });
43693
43743
  };
43694
43744
  var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash }) => {
43695
- return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
43745
+ const { blob, mimeType } = getBlobFromDataURL(dataURL);
43746
+ if (mimeType === "image/svg+xml") {
43747
+ return uploadToTheStorage(hash, dataURL, accessToken, boardId).then((src) => {
43748
+ return {
43749
+ imageDimension: { width: width2, height: height2 },
43750
+ base64: dataURL,
43751
+ storageLink: src
43752
+ };
43753
+ });
43754
+ }
43755
+ return uploadMediaToStorage(hash, blob, accessToken, boardId, "image").then((src) => {
43696
43756
  return {
43697
43757
  imageDimension: { width: width2, height: height2 },
43698
43758
  base64: dataURL,
@@ -43701,52 +43761,6 @@ var prepareImage = (inp, accessToken, boardId) => resizeAndConvertToPng(inp).the
43701
43761
  });
43702
43762
  });
43703
43763
 
43704
- // src/api/MediaHelpers.ts
43705
- var uploadMediaToStorage = async (hash, videoBlob, accessToken, boardId, type) => {
43706
- try {
43707
- const generateUrlResponse = await fetch(`${window.location.origin}/api/v1/media/generate-upload-url`, {
43708
- method: "POST",
43709
- headers: {
43710
- "Content-Type": "application/json",
43711
- Authorization: `Bearer ${accessToken}`
43712
- },
43713
- body: JSON.stringify({
43714
- fileSize: videoBlob.size,
43715
- boardId,
43716
- hash
43717
- })
43718
- });
43719
- if (!generateUrlResponse.ok) {
43720
- conf.hooks.onUploadMediaError(generateUrlResponse, type);
43721
- throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
43722
- }
43723
- const data = await generateUrlResponse.json();
43724
- if (data.mediaUrl) {
43725
- console.log("Media already exists, skipping upload.");
43726
- return data.mediaUrl;
43727
- }
43728
- const { uploadUrl, promisedMediaUrl } = data;
43729
- if (!uploadUrl || !promisedMediaUrl) {
43730
- throw new Error("Server did not provide an uploadUrl or promisedMediaUrl in the response.");
43731
- }
43732
- const uploadResponse = await fetch(uploadUrl, {
43733
- method: "PUT",
43734
- headers: {
43735
- "Content-Type": videoBlob.type
43736
- },
43737
- body: videoBlob
43738
- });
43739
- if (!uploadResponse.ok) {
43740
- console.error("Direct upload to storage failed:", uploadResponse.status, uploadResponse.statusText);
43741
- throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
43742
- }
43743
- return promisedMediaUrl;
43744
- } catch (error) {
43745
- console.error("Media upload process error:", error);
43746
- throw error;
43747
- }
43748
- };
43749
-
43750
43764
  // src/Items/Video/VideoHelpers.ts
43751
43765
  var uploadVideoToStorage = async (hash, videoBlob, accessToken, boardId) => {
43752
43766
  return new Promise((resolve2, reject) => {
@@ -59623,6 +59637,7 @@ export {
59623
59637
  getPlaceholderImage,
59624
59638
  getHotkeyLabel,
59625
59639
  getControlPointData,
59640
+ getBlobFromDataURL,
59626
59641
  forceNumberIntoInterval,
59627
59642
  fileTosha256,
59628
59643
  exportBoardSnapshot,
@@ -1,5 +1,10 @@
1
1
  import { ImageConstructorData } from './Image';
2
2
  export declare const uploadToTheStorage: (hash: string, dataURL: string, accessToken: string | null, boardId: string) => Promise<string>;
3
+ export declare const getBlobFromDataURL: (dataURL: string) => {
4
+ blob: Blob;
5
+ base64String: string;
6
+ mimeType: string;
7
+ };
3
8
  export declare const resizeAndConvertToPng: (inp: string | ArrayBuffer | null | undefined) => Promise<{
4
9
  dataURL: string;
5
10
  width: number;
@@ -1 +1 @@
1
- export declare const uploadMediaToStorage: (hash: string, videoBlob: Blob, accessToken: string | null, boardId: string, type: "video" | "audio" | "image") => Promise<string>;
1
+ export declare const uploadMediaToStorage: (hash: string, blob: Blob, accessToken: string | null, boardId: string, type: "video" | "audio" | "image") => Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.5.69",
3
+ "version": "0.5.71",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",