datasync-blob 1.1.35 → 1.1.37

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.
@@ -31,6 +31,7 @@ export interface DsBlobProps {
31
31
  /** Upload image to Datasync cloud storage instead of encoding as base64 */
32
32
  cloud_storage?: boolean;
33
33
  cloud_url_prefix?: string;
34
+ datasync_url?: string;
34
35
  /** Label shown on the upload button */
35
36
  Caption?: string;
36
37
  /** CSS class applied to the upload button */
@@ -47,7 +47,7 @@ const react_1 = __importStar(require("react"));
47
47
  const datasync_core_1 = require("datasync-core");
48
48
  //-----------------------------------------------------------------------------------------------------------------------------------------
49
49
  function DsBlob(props) {
50
- const { item_id, data: dataProp = "", binaryData: binaryDataProp = null, uploadPicture, width, height, maxWidth, maxHeight, maxKBytes, reduceImage, jpegQuality, cloud_storage, cloud_url_prefix, Caption, buttonStyle, pictureStyle, readOnly, onErrorHandler, debugging = false, } = props;
50
+ const { item_id, data: dataProp = "", binaryData: binaryDataProp = null, uploadPicture, width, height, maxWidth, maxHeight, maxKBytes, reduceImage, jpegQuality, cloud_storage, cloud_url_prefix, datasync_url = "http://localhost:8888/datasync-service", Caption, buttonStyle, pictureStyle, readOnly, onErrorHandler, debugging = false, } = props;
51
51
  const [hoverInput, setHoverInput] = (0, react_1.useState)(false);
52
52
  const [hoverImage, setHoverImage] = (0, react_1.useState)(false);
53
53
  const [data, setDataState] = (0, react_1.useState)(dataProp || "");
@@ -112,6 +112,20 @@ function DsBlob(props) {
112
112
  });
113
113
  };
114
114
  //-----------------------------------------
115
+ const getCloudFilename = (p_cloud_prefix) => {
116
+ let ls_cloud_file_name = p_cloud_prefix.split('/').pop() || "";
117
+ if (debugging)
118
+ console.log(`getCloudFilename::ls_cloud_file_name -> ${ls_cloud_file_name}`);
119
+ return (ls_cloud_file_name);
120
+ };
121
+ //-----------------------------------------
122
+ const getCloudPath = (p_datasync_url) => {
123
+ let ls_cloud_path = (p_datasync_url || "").replace(/\/+$/, "");
124
+ if (debugging)
125
+ console.log(`getCloudPath::ls_cloud_path -> ${ls_cloud_path}`);
126
+ return (ls_cloud_path);
127
+ };
128
+ //-----------------------------------------
115
129
  /**
116
130
  * Upload binary data to Datasync Cloud server using the SyncPushCloud endpoint.
117
131
  * Returns true on success, throws on failure.
@@ -119,7 +133,7 @@ function DsBlob(props) {
119
133
  const uploadToDatasyncCloud = (pictureBlob) => __awaiter(this, void 0, void 0, function* () {
120
134
  try {
121
135
  const formData = new FormData();
122
- const cloud_filename = pictureBlob.cloud_url_prefix.split('/').pop() || "";
136
+ const cloud_filename = getCloudFilename(pictureBlob.cloud_url_prefix);
123
137
  console.log("Uploading to Datasync Cloud with filename:", cloud_filename);
124
138
  formData.append('action', "syncPushCloud");
125
139
  formData.append('filename', cloud_filename);
@@ -164,7 +178,7 @@ function DsBlob(props) {
164
178
  formData.append('binary', binaryString);
165
179
  if (debugging)
166
180
  console.log("binaryString ->", binaryString.substring(0, 100) + '...');
167
- const results = yield fetch('http://localhost:8888/datasync-service/Sync.php', {
181
+ const results = yield fetch(`${getCloudPath(datasync_url)}/Sync.php`, {
168
182
  method: 'POST',
169
183
  body: formData,
170
184
  });
@@ -219,11 +233,11 @@ function DsBlob(props) {
219
233
  const deleteFromDatasyncCloud = (pictureBlob) => __awaiter(this, void 0, void 0, function* () {
220
234
  try {
221
235
  const formData = new FormData();
222
- const cloud_filename = pictureBlob.cloud_url_prefix.split('/').pop() || "";
236
+ const cloud_filename = getCloudFilename(cloud_url_prefix || "");
223
237
  console.log("Deleting from Datasync Cloud with filename:", cloud_filename);
224
238
  formData.append('action', "syncDeleteCloud");
225
239
  formData.append('filename', cloud_filename);
226
- const results = yield fetch('http://localhost:8888/datasync-service/Sync.php', {
240
+ const results = yield fetch(`${getCloudPath(datasync_url)}/Sync.php`, {
227
241
  method: 'POST',
228
242
  body: formData,
229
243
  });
@@ -404,15 +418,21 @@ function DsBlob(props) {
404
418
  };
405
419
  //-----------------------------------------------------------------------------------------------------------------------------------------
406
420
  const getImageSrc = () => {
421
+ if (debugging)
422
+ console.log(`getImageSrc:::data->${data}`);
407
423
  if (!data)
408
424
  return "";
409
425
  if (data.startsWith('http://') || data.startsWith('https://') || data.startsWith('blob:')) {
410
- return data;
426
+ if (debugging)
427
+ console.log(`getImageSrc:::data starts with httpx://`);
428
+ return `${data}?${(0, datasync_core_1.CGUID)()}`; //CacheBreaker trial;
411
429
  }
412
430
  if (data.startsWith('data:')) {
431
+ if (debugging)
432
+ console.log(`getImageSrc:::data starts with data:`);
413
433
  return data;
414
434
  }
415
- return data;
435
+ return `${data}?${(0, datasync_core_1.CGUID)()}`; //CacheBreaker trial
416
436
  };
417
437
  //-----------------------------------------------------------------------------------------------------------------------------------------
418
438
  const upload_picture_label = { cursor: "pointer" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datasync-blob",
3
- "version": "1.1.35",
3
+ "version": "1.1.37",
4
4
  "description": "Datasync Blob component",
5
5
  "main": "./dist/components/DsBlob.js",
6
6
  "files": [