datasync-blob 1.1.34 → 1.1.36
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 || "");
|
|
@@ -87,7 +87,8 @@ function DsBlob(props) {
|
|
|
87
87
|
// Cleanup on unmount
|
|
88
88
|
(0, react_1.useEffect)(() => {
|
|
89
89
|
return () => {
|
|
90
|
-
|
|
90
|
+
/* Disabled because cloud image was deleted on component unmount
|
|
91
|
+
cleanupBlobUrl();*/
|
|
91
92
|
if (_DOM_image.current) {
|
|
92
93
|
_DOM_image.current.onload = null;
|
|
93
94
|
_DOM_image.current = null;
|
|
@@ -111,6 +112,20 @@ function DsBlob(props) {
|
|
|
111
112
|
});
|
|
112
113
|
};
|
|
113
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
|
+
//-----------------------------------------
|
|
114
129
|
/**
|
|
115
130
|
* Upload binary data to Datasync Cloud server using the SyncPushCloud endpoint.
|
|
116
131
|
* Returns true on success, throws on failure.
|
|
@@ -118,7 +133,7 @@ function DsBlob(props) {
|
|
|
118
133
|
const uploadToDatasyncCloud = (pictureBlob) => __awaiter(this, void 0, void 0, function* () {
|
|
119
134
|
try {
|
|
120
135
|
const formData = new FormData();
|
|
121
|
-
const cloud_filename = pictureBlob.cloud_url_prefix
|
|
136
|
+
const cloud_filename = getCloudFilename(pictureBlob.cloud_url_prefix);
|
|
122
137
|
console.log("Uploading to Datasync Cloud with filename:", cloud_filename);
|
|
123
138
|
formData.append('action', "syncPushCloud");
|
|
124
139
|
formData.append('filename', cloud_filename);
|
|
@@ -163,7 +178,7 @@ function DsBlob(props) {
|
|
|
163
178
|
formData.append('binary', binaryString);
|
|
164
179
|
if (debugging)
|
|
165
180
|
console.log("binaryString ->", binaryString.substring(0, 100) + '...');
|
|
166
|
-
const results = yield fetch(
|
|
181
|
+
const results = yield fetch(`${getCloudPath(datasync_url)}/Sync.php`, {
|
|
167
182
|
method: 'POST',
|
|
168
183
|
body: formData,
|
|
169
184
|
});
|
|
@@ -218,11 +233,11 @@ function DsBlob(props) {
|
|
|
218
233
|
const deleteFromDatasyncCloud = (pictureBlob) => __awaiter(this, void 0, void 0, function* () {
|
|
219
234
|
try {
|
|
220
235
|
const formData = new FormData();
|
|
221
|
-
const cloud_filename =
|
|
236
|
+
const cloud_filename = getCloudFilename(cloud_url_prefix || "");
|
|
222
237
|
console.log("Deleting from Datasync Cloud with filename:", cloud_filename);
|
|
223
238
|
formData.append('action', "syncDeleteCloud");
|
|
224
239
|
formData.append('filename', cloud_filename);
|
|
225
|
-
const results = yield fetch(
|
|
240
|
+
const results = yield fetch(`${getCloudPath(datasync_url)}/Sync.php`, {
|
|
226
241
|
method: 'POST',
|
|
227
242
|
body: formData,
|
|
228
243
|
});
|