powr-sdk-web 4.4.6 → 4.4.7
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/uploader/index.js +46 -12
- package/package.json +1 -1
package/dist/uploader/index.js
CHANGED
|
@@ -69,13 +69,15 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
|
|
|
69
69
|
var fileInputRef = (0, _react.useRef)(null);
|
|
70
70
|
var uploadFile = /*#__PURE__*/function () {
|
|
71
71
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(file) {
|
|
72
|
-
var formData, _yield$apiCall, data, ok, response, _t;
|
|
72
|
+
var formData, _yield$apiCall, data, ok, response, normalized, _t;
|
|
73
73
|
return _regenerator().w(function (_context) {
|
|
74
74
|
while (1) switch (_context.p = _context.n) {
|
|
75
75
|
case 0:
|
|
76
76
|
formData = new FormData();
|
|
77
77
|
formData.append('file', file);
|
|
78
|
-
|
|
78
|
+
|
|
79
|
+
// Avoid interpolating apiUrl directly (it may be undefined). Log intent instead.
|
|
80
|
+
console.log(' Uploading file:', file.name, 'to files endpoint');
|
|
79
81
|
_context.p = 1;
|
|
80
82
|
_context.n = 2;
|
|
81
83
|
return (0, _auth.apiCall)(apiUrl, "/files", projectId, {
|
|
@@ -87,16 +89,37 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
|
|
|
87
89
|
data = _yield$apiCall.data;
|
|
88
90
|
ok = _yield$apiCall.ok;
|
|
89
91
|
response = _yield$apiCall.response;
|
|
90
|
-
console.log(' Upload response status:', response.status);
|
|
91
|
-
console.log(' Upload response data
|
|
92
|
+
console.log('📤 Upload response status:', response.status);
|
|
93
|
+
console.log('📦 Upload response raw data............:', data);
|
|
92
94
|
if (ok) {
|
|
93
95
|
_context.n = 3;
|
|
94
96
|
break;
|
|
95
97
|
}
|
|
96
|
-
console.error(' Upload failed with status:', response.status);
|
|
98
|
+
console.error('❌ Upload failed with status:', response.status, 'data:', data);
|
|
97
99
|
throw new Error("Upload failed with status: ".concat(response.status));
|
|
98
100
|
case 3:
|
|
99
|
-
|
|
101
|
+
// Normalize server response to a consistent object shape.
|
|
102
|
+
normalized = null;
|
|
103
|
+
if (typeof data === 'string') {
|
|
104
|
+
// backend returned plain URL string
|
|
105
|
+
normalized = {
|
|
106
|
+
url: data
|
|
107
|
+
};
|
|
108
|
+
} else if (data && data.url) {
|
|
109
|
+
// expected shape
|
|
110
|
+
normalized = data;
|
|
111
|
+
} else if (data && data.file && (data.file.url || data.file.path)) {
|
|
112
|
+
// grouped under `file`
|
|
113
|
+
normalized = data.file;
|
|
114
|
+
} else if (data && data.fileUrl) {
|
|
115
|
+
normalized = {
|
|
116
|
+
url: data.fileUrl
|
|
117
|
+
};
|
|
118
|
+
} else {
|
|
119
|
+
normalized = data || {};
|
|
120
|
+
}
|
|
121
|
+
console.log('🔍 Normalized upload response keys:', Object.keys(normalized || {}));
|
|
122
|
+
return _context.a(2, normalized);
|
|
100
123
|
case 4:
|
|
101
124
|
_context.p = 4;
|
|
102
125
|
_t = _context.v;
|
|
@@ -157,12 +180,19 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
|
|
|
157
180
|
data = _context2.v;
|
|
158
181
|
console.log(' Upload successful, received data:', data);
|
|
159
182
|
uploadedFile = {
|
|
160
|
-
url: data === null || data === void 0 ? void 0 : data.url,
|
|
161
|
-
name: (data === null || data === void 0 ? void 0 : data.originalname) || file.name,
|
|
162
|
-
type: (data === null || data === void 0 ? void 0 : data.mimetype) || file.type,
|
|
183
|
+
url: (data === null || data === void 0 ? void 0 : data.url) || (data === null || data === void 0 ? void 0 : data.fileUrl) || (data === null || data === void 0 ? void 0 : data.path) || (data === null || data === void 0 ? void 0 : data.location) || URL.createObjectURL(file),
|
|
184
|
+
name: (data === null || data === void 0 ? void 0 : data.originalname) || (data === null || data === void 0 ? void 0 : data.name) || (data === null || data === void 0 ? void 0 : data.filename) || file.name,
|
|
185
|
+
type: (data === null || data === void 0 ? void 0 : data.mimetype) || (data === null || data === void 0 ? void 0 : data.type) || (data === null || data === void 0 ? void 0 : data.contentType) || file.type,
|
|
163
186
|
size: (data === null || data === void 0 ? void 0 : data.size) || file.size,
|
|
164
187
|
isUploading: false
|
|
165
188
|
};
|
|
189
|
+
console.log(' Uploaded file URL check:', {
|
|
190
|
+
'data?.url': data === null || data === void 0 ? void 0 : data.url,
|
|
191
|
+
'data?.fileUrl': data === null || data === void 0 ? void 0 : data.fileUrl,
|
|
192
|
+
'data?.path': data === null || data === void 0 ? void 0 : data.path,
|
|
193
|
+
'data?.location': data === null || data === void 0 ? void 0 : data.location,
|
|
194
|
+
'final url': uploadedFile.url
|
|
195
|
+
});
|
|
166
196
|
console.log(' Created uploaded file object:', uploadedFile);
|
|
167
197
|
|
|
168
198
|
// Replace the placeholder with the actual file
|
|
@@ -264,10 +294,14 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
|
|
|
264
294
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
265
295
|
key: index,
|
|
266
296
|
className: "group relative aspect-square bg-muted/50 rounded-md overflow-hidden border border-border hover:border-primary transition-colors"
|
|
267
|
-
}, isImage && showPreview ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("img", {
|
|
297
|
+
}, isImage && showPreview && file.url ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("img", {
|
|
268
298
|
src: file.url,
|
|
269
299
|
alt: file.name,
|
|
270
|
-
className: "w-full h-full object-cover ".concat(file.isUploading ? 'opacity-50' : '')
|
|
300
|
+
className: "w-full h-full object-cover ".concat(file.isUploading ? 'opacity-50' : ''),
|
|
301
|
+
onError: function onError(e) {
|
|
302
|
+
console.error('❌ Image load error for:', file.url);
|
|
303
|
+
e.target.style.display = 'none';
|
|
304
|
+
}
|
|
271
305
|
}), file.isUploading && /*#__PURE__*/_react["default"].createElement("div", {
|
|
272
306
|
className: "absolute inset-0 flex items-center justify-center bg-background/20"
|
|
273
307
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -280,7 +314,7 @@ var PowrBaseUploader = function PowrBaseUploader(_ref) {
|
|
|
280
314
|
className: "text-2xl text-muted-foreground mb-1"
|
|
281
315
|
}, fileIcon), /*#__PURE__*/_react["default"].createElement("div", {
|
|
282
316
|
className: "text-[10px] text-muted-foreground text-center truncate w-full"
|
|
283
|
-
}, file.name))), !file.isUploading && /*#__PURE__*/_react["default"].createElement("div", {
|
|
317
|
+
}, file.name))), !file.isUploading && file.url && /*#__PURE__*/_react["default"].createElement("div", {
|
|
284
318
|
className: "absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2"
|
|
285
319
|
}, /*#__PURE__*/_react["default"].createElement("a", {
|
|
286
320
|
href: file.url,
|