@innovastudio/contentbuilder 1.4.92 → 1.4.93

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbuilder",
3
3
  "type": "module",
4
- "version": "1.4.92",
4
+ "version": "1.4.93",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "files": [
@@ -81890,45 +81890,39 @@ class ContentBuilder {
81890
81890
  }
81891
81891
  const filename = result.filename;
81892
81892
  let images = [];
81893
- const numOfImages = result.data.data.length;
81894
- const imageList = result.data.data;
81895
- imageList.forEach(item => {
81896
- const base64 = item.b64_json;
81897
- const src = `data:image/jpeg;base64,${base64}`;
81898
- var newWidth = 1024;
81899
- var newHeight = 1024;
81900
- var img = new Image();
81901
- img.src = src;
81902
- img.onload = () => {
81903
- var canvas = document.createElement('canvas');
81904
- canvas.width = newWidth;
81905
- canvas.height = newHeight;
81906
- var ctx = canvas.getContext('2d');
81907
- ctx.drawImage(img, 0, 0, newWidth, newHeight);
81908
- var resizedBase64 = canvas.toDataURL('image/jpeg');
81909
- let image = resizedBase64;
81910
- image = image.replace(/^data:image\/(png|jpeg);base64,/, '');
81911
- const reqBody = {
81912
- image: image,
81913
- filename: filename
81914
- };
81915
- fetch(this.uploadBase64Url, {
81916
- method: 'POST',
81917
- body: JSON.stringify(reqBody),
81918
- headers: {
81919
- 'Content-Type': 'application/json'
81920
- }
81921
- }).then(response => response.json()).then(response => {
81922
- if (!response.error) {
81923
- const uploadedImageUrl = response.url;
81924
- images.push(uploadedImageUrl);
81925
- if (images.length === numOfImages) {
81926
- callback(images);
81927
- }
81928
- }
81929
- });
81893
+ const base64 = result.data;
81894
+ const src = `data:image/jpeg;base64,${base64}`;
81895
+ var newWidth = 1024;
81896
+ var newHeight = 1024;
81897
+ var img = new Image();
81898
+ img.src = src;
81899
+ img.onload = () => {
81900
+ var canvas = document.createElement('canvas');
81901
+ canvas.width = newWidth;
81902
+ canvas.height = newHeight;
81903
+ var ctx = canvas.getContext('2d');
81904
+ ctx.drawImage(img, 0, 0, newWidth, newHeight);
81905
+ var resizedBase64 = canvas.toDataURL('image/jpeg');
81906
+ let image = resizedBase64;
81907
+ image = image.replace(/^data:image\/(png|jpeg);base64,/, '');
81908
+ const reqBody = {
81909
+ image: image,
81910
+ filename: filename
81930
81911
  };
81931
- });
81912
+ fetch(this.uploadBase64Url, {
81913
+ method: 'POST',
81914
+ body: JSON.stringify(reqBody),
81915
+ headers: {
81916
+ 'Content-Type': 'application/json'
81917
+ }
81918
+ }).then(response => response.json()).then(response => {
81919
+ if (!response.error) {
81920
+ const uploadedImageUrl = response.url;
81921
+ images.push(uploadedImageUrl);
81922
+ callback(images);
81923
+ }
81924
+ });
81925
+ };
81932
81926
  } catch (error) {
81933
81927
  if (error.name === 'AbortError') ; else {
81934
81928
  // CORS or code errors goes here
@@ -81940,6 +81934,92 @@ class ContentBuilder {
81940
81934
  }
81941
81935
  }
81942
81936
 
81937
+ /*
81938
+ async generateImage(prompt, num, callback) {
81939
+ if(!(this.generateImageUrl && this.uploadBase64Url)) return;
81940
+ this.controller = new AbortController(); // Create a new AbortController
81941
+ this.signal = this.controller.signal; // Get a new signal object
81942
+ const messages = { prompt, num };
81943
+ try {
81944
+ const response = await fetch(this.generateImageUrl, {
81945
+ signal: this.signal, // Abort
81946
+ method: 'POST',
81947
+ headers: {
81948
+ 'Content-Type': 'application/json',
81949
+ },
81950
+ body: JSON.stringify(messages),
81951
+ });
81952
+
81953
+ const result = await response.json();
81954
+
81955
+ if(result.error) {
81956
+ console.log('Error:\n'+result.error);
81957
+ return;
81958
+ }
81959
+
81960
+ const filename = result.filename;
81961
+
81962
+ let images = [];
81963
+
81964
+ const numOfImages = result.data.data.length;
81965
+
81966
+ const imageList = result.data.data;
81967
+ imageList.forEach(item=>{
81968
+ const base64 = item.b64_json;
81969
+ const src = `data:image/jpeg;base64,${base64}`;
81970
+
81971
+ var newWidth = 1024;
81972
+ var newHeight = 1024;
81973
+ var img = new Image();
81974
+ img.src = src;
81975
+ img.onload = () => {
81976
+
81977
+ var canvas = document.createElement('canvas');
81978
+ canvas.width = newWidth;
81979
+ canvas.height = newHeight;
81980
+
81981
+ var ctx = canvas.getContext('2d');
81982
+ ctx.drawImage(img, 0, 0, newWidth, newHeight);
81983
+ var resizedBase64 = canvas.toDataURL('image/jpeg');
81984
+
81985
+ let image = resizedBase64;
81986
+ image = image.replace(/^data:image\/(png|jpeg);base64,/, '');
81987
+
81988
+ const reqBody = { image: image, filename: filename };
81989
+ fetch(this.uploadBase64Url, {
81990
+ method:'POST',
81991
+ body: JSON.stringify(reqBody),
81992
+ headers: {
81993
+ 'Content-Type': 'application/json',
81994
+ }
81995
+ })
81996
+ .then(response=>response.json())
81997
+ .then(response=>{
81998
+ if(!response.error) {
81999
+ const uploadedImageUrl = response.url;
82000
+ images.push(uploadedImageUrl);
82001
+ if(images.length===numOfImages) {
82002
+ callback(images);
82003
+ }
82004
+ }
82005
+ });
82006
+ };
82007
+
82008
+ });
82009
+ } catch (error) {
82010
+ if (error.name === 'AbortError') {
82011
+ // Do Nothing
82012
+ // console.log('Request aborted by user.');
82013
+ } else {
82014
+ // CORS or code errors goes here
82015
+ console.error('Error:', error);
82016
+ // console.log('Error:\n'+error);
82017
+ this.dictation.finish(); // Must be called after finished
82018
+ }
82019
+ }
82020
+ }
82021
+ */
82022
+
81943
82023
  lightboxOpen(col) {
81944
82024
  // Open Lightbox
81945
82025
  if (this.useLightbox) {