@tradly/asset 1.0.12 → 1.0.14
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/README.md +257 -13
- package/dist/components/FileUpload.js +8 -247
- package/dist/components/FileUpload.native.js +13 -0
- package/dist/components/Icons.js +10 -33
- package/dist/components/Icons.native.js +16 -0
- package/dist/components/ImagesSkeleton.js +7 -15
- package/dist/components/ImagesSkeleton.native.js +13 -0
- package/dist/components/MediaGallery.js +8 -148
- package/dist/components/MediaGallery.native.js +13 -0
- package/dist/components/MediaPopup.js +8 -99
- package/dist/components/MediaPopup.native.js +13 -0
- package/dist/components/MediaTab.js +7 -180
- package/dist/components/MediaTab.native.js +13 -0
- package/dist/components/Pagination.js +8 -136
- package/dist/components/Pagination.native.js +13 -0
- package/dist/components/VideosGallery.js +8 -148
- package/dist/components/VideosGallery.native.js +13 -0
- package/dist/core/MediaApiService.js +396 -0
- package/dist/esm/components/FileUpload.js +1 -246
- package/dist/esm/components/FileUpload.native.js +1 -0
- package/dist/esm/components/Icons.js +1 -32
- package/dist/esm/components/Icons.native.js +1 -0
- package/dist/esm/components/ImagesSkeleton.js +1 -14
- package/dist/esm/components/ImagesSkeleton.native.js +1 -0
- package/dist/esm/components/MediaGallery.js +1 -144
- package/dist/esm/components/MediaGallery.native.js +1 -0
- package/dist/esm/components/MediaPopup.js +1 -97
- package/dist/esm/components/MediaPopup.native.js +1 -0
- package/dist/esm/components/MediaTab.js +1 -177
- package/dist/esm/components/MediaTab.native.js +1 -0
- package/dist/esm/components/Pagination.js +1 -134
- package/dist/esm/components/Pagination.native.js +1 -0
- package/dist/esm/components/VideosGallery.js +1 -144
- package/dist/esm/components/VideosGallery.native.js +1 -0
- package/dist/esm/core/MediaApiService.js +390 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/native/FileUpload.native.js +298 -0
- package/dist/esm/native/Icons.native.js +51 -0
- package/dist/esm/native/ImagesSkeleton.native.js +45 -0
- package/dist/esm/native/MediaGallery.native.js +221 -0
- package/dist/esm/native/MediaPopup.native.js +151 -0
- package/dist/esm/native/MediaTab.native.js +175 -0
- package/dist/esm/native/Pagination.native.js +186 -0
- package/dist/esm/native/VideosGallery.native.js +233 -0
- package/dist/esm/services/apiService.js +1 -372
- package/dist/esm/web/FileUpload.web.js +253 -0
- package/dist/esm/web/Icons.web.js +32 -0
- package/dist/esm/web/ImagesSkeleton.web.js +14 -0
- package/dist/esm/web/MediaGallery.web.js +144 -0
- package/dist/esm/web/MediaPopup.web.js +97 -0
- package/dist/esm/web/MediaTab.web.js +177 -0
- package/dist/esm/web/Pagination.web.js +134 -0
- package/dist/esm/web/VideosGallery.web.js +144 -0
- package/dist/index.js +2 -2
- package/dist/native/FileUpload.native.js +304 -0
- package/dist/native/Icons.native.js +59 -0
- package/dist/native/ImagesSkeleton.native.js +52 -0
- package/dist/native/MediaGallery.native.js +230 -0
- package/dist/native/MediaPopup.native.js +158 -0
- package/dist/native/MediaTab.native.js +184 -0
- package/dist/native/Pagination.native.js +193 -0
- package/dist/native/VideosGallery.native.js +241 -0
- package/dist/services/apiService.js +2 -372
- package/dist/web/FileUpload.web.js +259 -0
- package/dist/web/Icons.web.js +39 -0
- package/dist/web/ImagesSkeleton.web.js +21 -0
- package/dist/web/MediaGallery.web.js +153 -0
- package/dist/web/MediaPopup.web.js +104 -0
- package/dist/web/MediaTab.web.js +186 -0
- package/dist/web/Pagination.web.js +141 -0
- package/dist/web/VideosGallery.web.js +153 -0
- package/package.json +4 -3
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
4
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
5
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
6
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
7
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
8
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
9
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
15
|
+
import React, { useState, useEffect } from 'react';
|
|
16
|
+
import { View, FlatList, TouchableOpacity, StyleSheet, Dimensions, Text } from 'react-native';
|
|
17
|
+
import FileUpload from './FileUpload.native';
|
|
18
|
+
import ImagesSkeleton from './ImagesSkeleton.native';
|
|
19
|
+
import Pagination from './Pagination.native';
|
|
20
|
+
// Note: You'll need to install react-native-video for video playback
|
|
21
|
+
// import Video from 'react-native-video'
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
var _Dimensions$get = Dimensions.get('window'),
|
|
24
|
+
SCREEN_WIDTH = _Dimensions$get.width;
|
|
25
|
+
var NUM_COLUMNS = 3;
|
|
26
|
+
var ITEM_MARGIN = 8;
|
|
27
|
+
var ITEM_SIZE = (SCREEN_WIDTH - 40 - ITEM_MARGIN * (NUM_COLUMNS - 1) * 2) / NUM_COLUMNS;
|
|
28
|
+
var VIDEO_MIME_TYPES = ['video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/h265', 'video/hevc', 'video/webm'];
|
|
29
|
+
var VideosGallery = function VideosGallery(_ref) {
|
|
30
|
+
var update_data = _ref.update_data,
|
|
31
|
+
closePopup = _ref.closePopup,
|
|
32
|
+
apiService = _ref.apiService,
|
|
33
|
+
onError = _ref.onError,
|
|
34
|
+
picker = _ref.picker,
|
|
35
|
+
pickerOptions = _ref.pickerOptions,
|
|
36
|
+
containerStyle = _ref.containerStyle,
|
|
37
|
+
gridStyle = _ref.gridStyle,
|
|
38
|
+
videoItemStyle = _ref.videoItemStyle,
|
|
39
|
+
paginationContainerStyle = _ref.paginationContainerStyle;
|
|
40
|
+
var _useState = useState([]),
|
|
41
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
42
|
+
videos = _useState2[0],
|
|
43
|
+
setVideos = _useState2[1];
|
|
44
|
+
var _useState3 = useState(0),
|
|
45
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
46
|
+
total_count = _useState4[0],
|
|
47
|
+
setTotalCount = _useState4[1];
|
|
48
|
+
var _useState5 = useState(1),
|
|
49
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
50
|
+
currentPage = _useState6[0],
|
|
51
|
+
setCurrentPage = _useState6[1];
|
|
52
|
+
var _useState7 = useState(false),
|
|
53
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
54
|
+
isLoading = _useState8[0],
|
|
55
|
+
setISLoading = _useState8[1];
|
|
56
|
+
|
|
57
|
+
// Fetch videos
|
|
58
|
+
useEffect(function () {
|
|
59
|
+
loadMedia();
|
|
60
|
+
}, []);
|
|
61
|
+
var loadMedia = /*#__PURE__*/function () {
|
|
62
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
63
|
+
var page_number,
|
|
64
|
+
_response$data,
|
|
65
|
+
_response$data2,
|
|
66
|
+
response,
|
|
67
|
+
mediaData,
|
|
68
|
+
count,
|
|
69
|
+
_args = arguments,
|
|
70
|
+
_t;
|
|
71
|
+
return _regenerator().w(function (_context) {
|
|
72
|
+
while (1) switch (_context.p = _context.n) {
|
|
73
|
+
case 0:
|
|
74
|
+
page_number = _args.length > 0 && _args[0] !== undefined ? _args[0] : 1;
|
|
75
|
+
_context.p = 1;
|
|
76
|
+
_context.n = 2;
|
|
77
|
+
return apiService.fetchMedia({
|
|
78
|
+
mimeTypes: VIDEO_MIME_TYPES,
|
|
79
|
+
page: page_number,
|
|
80
|
+
setISLoading: setISLoading,
|
|
81
|
+
isLoading: isLoading
|
|
82
|
+
});
|
|
83
|
+
case 2:
|
|
84
|
+
response = _context.v;
|
|
85
|
+
// Handle different response formats
|
|
86
|
+
mediaData = (response === null || response === void 0 ? void 0 : response.media) || (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.media) || (response === null || response === void 0 ? void 0 : response.data) || response || [];
|
|
87
|
+
count = (response === null || response === void 0 ? void 0 : response.count) || (response === null || response === void 0 || (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.count) || (response === null || response === void 0 ? void 0 : response.total) || 0;
|
|
88
|
+
setVideos(Array.isArray(mediaData) ? mediaData : []);
|
|
89
|
+
setTotalCount(count);
|
|
90
|
+
setCurrentPage(page_number);
|
|
91
|
+
_context.n = 4;
|
|
92
|
+
break;
|
|
93
|
+
case 3:
|
|
94
|
+
_context.p = 3;
|
|
95
|
+
_t = _context.v;
|
|
96
|
+
console.error('Error loading videos:', _t);
|
|
97
|
+
if (onError) {
|
|
98
|
+
onError(_t);
|
|
99
|
+
}
|
|
100
|
+
case 4:
|
|
101
|
+
return _context.a(2);
|
|
102
|
+
}
|
|
103
|
+
}, _callee, null, [[1, 3]]);
|
|
104
|
+
}));
|
|
105
|
+
return function loadMedia() {
|
|
106
|
+
return _ref2.apply(this, arguments);
|
|
107
|
+
};
|
|
108
|
+
}();
|
|
109
|
+
var handleVideoClick = function handleVideoClick(video) {
|
|
110
|
+
if (update_data) {
|
|
111
|
+
update_data(video.url || video);
|
|
112
|
+
}
|
|
113
|
+
if (closePopup) {
|
|
114
|
+
closePopup();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var renderItem = function renderItem(_ref3) {
|
|
118
|
+
var item = _ref3.item,
|
|
119
|
+
index = _ref3.index;
|
|
120
|
+
// First item is the upload button
|
|
121
|
+
if (index === 0) {
|
|
122
|
+
return /*#__PURE__*/_jsx(View, {
|
|
123
|
+
style: [styles.uploadContainer, {
|
|
124
|
+
width: ITEM_SIZE,
|
|
125
|
+
height: ITEM_SIZE
|
|
126
|
+
}],
|
|
127
|
+
children: /*#__PURE__*/_jsx(FileUpload, {
|
|
128
|
+
loadMedia: loadMedia,
|
|
129
|
+
accept: "video/*",
|
|
130
|
+
title: "Add Video",
|
|
131
|
+
apiService: apiService,
|
|
132
|
+
onUploadError: onError,
|
|
133
|
+
picker: picker,
|
|
134
|
+
pickerOptions: pickerOptions
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
var video = videos[index - 1];
|
|
139
|
+
var videoUrl = typeof video === 'string' ? video : video.url;
|
|
140
|
+
var videoKey = video.id || video.url || index;
|
|
141
|
+
return /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
142
|
+
onPress: function onPress() {
|
|
143
|
+
return handleVideoClick(video);
|
|
144
|
+
},
|
|
145
|
+
style: [styles.videoItem, {
|
|
146
|
+
width: ITEM_SIZE,
|
|
147
|
+
height: ITEM_SIZE
|
|
148
|
+
}, videoItemStyle],
|
|
149
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
150
|
+
style: styles.videoPlaceholder,
|
|
151
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
152
|
+
style: styles.playIcon,
|
|
153
|
+
children: "\u25B6"
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
var data = isLoading ? [] : [{
|
|
159
|
+
type: 'upload'
|
|
160
|
+
}].concat(_toConsumableArray(videos));
|
|
161
|
+
return /*#__PURE__*/_jsx(View, {
|
|
162
|
+
style: [styles.container, containerStyle],
|
|
163
|
+
children: isLoading ? /*#__PURE__*/_jsx(ImagesSkeleton, {}) : /*#__PURE__*/_jsx(FlatList, {
|
|
164
|
+
data: data,
|
|
165
|
+
renderItem: renderItem,
|
|
166
|
+
keyExtractor: function keyExtractor(item, index) {
|
|
167
|
+
if (index === 0) return 'upload';
|
|
168
|
+
var video = videos[index - 1];
|
|
169
|
+
return video.id || video.url || "video-".concat(index);
|
|
170
|
+
},
|
|
171
|
+
numColumns: NUM_COLUMNS,
|
|
172
|
+
contentContainerStyle: [styles.grid, gridStyle],
|
|
173
|
+
showsVerticalScrollIndicator: false,
|
|
174
|
+
ListFooterComponent: total_count > 0 ? /*#__PURE__*/_jsx(View, {
|
|
175
|
+
style: [styles.paginationContainer, paginationContainerStyle],
|
|
176
|
+
children: /*#__PURE__*/_jsx(Pagination, {
|
|
177
|
+
nextPage: function nextPage(value) {
|
|
178
|
+
return loadMedia(value);
|
|
179
|
+
},
|
|
180
|
+
pageCount: Math.ceil(total_count / 30),
|
|
181
|
+
current_page: currentPage
|
|
182
|
+
})
|
|
183
|
+
}) : null
|
|
184
|
+
})
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
var styles = StyleSheet.create({
|
|
188
|
+
container: {
|
|
189
|
+
flex: 1
|
|
190
|
+
},
|
|
191
|
+
grid: {
|
|
192
|
+
padding: 4
|
|
193
|
+
},
|
|
194
|
+
uploadContainer: {
|
|
195
|
+
margin: ITEM_MARGIN
|
|
196
|
+
},
|
|
197
|
+
videoItem: {
|
|
198
|
+
margin: ITEM_MARGIN,
|
|
199
|
+
borderRadius: 8,
|
|
200
|
+
overflow: 'hidden',
|
|
201
|
+
backgroundColor: '#000000',
|
|
202
|
+
shadowColor: '#000',
|
|
203
|
+
shadowOffset: {
|
|
204
|
+
width: 0,
|
|
205
|
+
height: 2
|
|
206
|
+
},
|
|
207
|
+
shadowOpacity: 0.1,
|
|
208
|
+
shadowRadius: 3.84,
|
|
209
|
+
elevation: 5
|
|
210
|
+
},
|
|
211
|
+
videoPlaceholder: {
|
|
212
|
+
width: '100%',
|
|
213
|
+
height: '100%',
|
|
214
|
+
backgroundColor: '#1a1a1a',
|
|
215
|
+
justifyContent: 'center',
|
|
216
|
+
alignItems: 'center'
|
|
217
|
+
},
|
|
218
|
+
playIcon: {
|
|
219
|
+
fontSize: 32,
|
|
220
|
+
color: '#FFFFFF'
|
|
221
|
+
},
|
|
222
|
+
video: {
|
|
223
|
+
width: '100%',
|
|
224
|
+
height: '100%'
|
|
225
|
+
},
|
|
226
|
+
paginationContainer: {
|
|
227
|
+
paddingVertical: 16,
|
|
228
|
+
paddingHorizontal: 8,
|
|
229
|
+
backgroundColor: '#F5F5F5',
|
|
230
|
+
marginTop: 8
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
export default VideosGallery;
|
|
@@ -1,373 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
3
|
-
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
4
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
5
|
-
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
6
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
7
|
-
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
8
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
9
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
10
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
-
import axios from 'axios';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get the API base URL based on environment
|
|
15
|
-
* @returns {string} API base URL
|
|
16
|
-
*/
|
|
17
|
-
var getApiBaseUrl = function getApiBaseUrl(environment) {
|
|
18
|
-
// Check if environment includes 'dev' (case insensitive)
|
|
19
|
-
var isDev = environment && String(environment).toLowerCase().includes('dev');
|
|
20
|
-
return isDev ? 'https://api.dev.tradly.app' : 'https://api.tradly.app';
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* API Service for Media Gallery
|
|
25
|
-
* Handles all API calls with Tradly authentication
|
|
26
|
-
* Includes full upload logic using direct API call to S3 signed URL endpoint
|
|
27
|
-
*/
|
|
28
|
-
var MediaApiService = /*#__PURE__*/function () {
|
|
29
|
-
function MediaApiService() {
|
|
30
|
-
var _process$env;
|
|
31
|
-
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
|
-
_classCallCheck(this, MediaApiService);
|
|
33
|
-
this.authKey = config.authKey || '';
|
|
34
|
-
// Auto-detect API base URL from environment, or use provided one
|
|
35
|
-
var environment = config.environment || typeof process !== 'undefined' && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.ENVIRONMENT) || '';
|
|
36
|
-
this.apiBaseUrl = config.apiBaseUrl || getApiBaseUrl(environment);
|
|
37
|
-
this.bearerToken = config.bearerToken || ''; // Bearer token for Authorization header
|
|
38
|
-
this.onError = config.onError || null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Set authentication key
|
|
43
|
-
*/
|
|
44
|
-
return _createClass(MediaApiService, [{
|
|
45
|
-
key: "setAuthKey",
|
|
46
|
-
value: function setAuthKey(authKey) {
|
|
47
|
-
this.authKey = authKey;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Set API base URL (used for all API calls)
|
|
52
|
-
*/
|
|
53
|
-
}, {
|
|
54
|
-
key: "setApiBaseUrl",
|
|
55
|
-
value: function setApiBaseUrl(apiBaseUrl) {
|
|
56
|
-
this.apiBaseUrl = apiBaseUrl;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Set Bearer token for Authorization header
|
|
61
|
-
*/
|
|
62
|
-
}, {
|
|
63
|
-
key: "setBearerToken",
|
|
64
|
-
value: function setBearerToken(bearerToken) {
|
|
65
|
-
this.bearerToken = bearerToken;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Make API call with authentication to Tradly API
|
|
70
|
-
*/
|
|
71
|
-
}, {
|
|
72
|
-
key: "apiCall",
|
|
73
|
-
value: (function () {
|
|
74
|
-
var _apiCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
75
|
-
var method, path, data, params, setISLoading, isLoading, headers, response, _t;
|
|
76
|
-
return _regenerator().w(function (_context) {
|
|
77
|
-
while (1) switch (_context.p = _context.n) {
|
|
78
|
-
case 0:
|
|
79
|
-
method = _ref.method, path = _ref.path, data = _ref.data, params = _ref.params, setISLoading = _ref.setISLoading, isLoading = _ref.isLoading;
|
|
80
|
-
if (setISLoading) setISLoading(true);
|
|
81
|
-
_context.p = 1;
|
|
82
|
-
headers = {
|
|
83
|
-
'Content-Type': 'application/json'
|
|
84
|
-
}; // Add auth key to headers if provided (X-Auth-Key header)
|
|
85
|
-
if (this.authKey) {
|
|
86
|
-
headers['X-Auth-Key'] = this.authKey;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Add Bearer token if provided
|
|
90
|
-
if (this.bearerToken) {
|
|
91
|
-
headers['Authorization'] = "Bearer ".concat(this.bearerToken);
|
|
92
|
-
}
|
|
93
|
-
_context.n = 2;
|
|
94
|
-
return axios({
|
|
95
|
-
method: method,
|
|
96
|
-
url: "".concat(this.apiBaseUrl).concat(path),
|
|
97
|
-
headers: headers,
|
|
98
|
-
data: data,
|
|
99
|
-
params: params
|
|
100
|
-
});
|
|
101
|
-
case 2:
|
|
102
|
-
response = _context.v;
|
|
103
|
-
if (setISLoading) setISLoading(false);
|
|
104
|
-
return _context.a(2, response.data);
|
|
105
|
-
case 3:
|
|
106
|
-
_context.p = 3;
|
|
107
|
-
_t = _context.v;
|
|
108
|
-
if (setISLoading) setISLoading(false);
|
|
109
|
-
if (this.onError) {
|
|
110
|
-
this.onError(_t);
|
|
111
|
-
}
|
|
112
|
-
throw _t;
|
|
113
|
-
case 4:
|
|
114
|
-
return _context.a(2);
|
|
115
|
-
}
|
|
116
|
-
}, _callee, this, [[1, 3]]);
|
|
117
|
-
}));
|
|
118
|
-
function apiCall(_x) {
|
|
119
|
-
return _apiCall.apply(this, arguments);
|
|
120
|
-
}
|
|
121
|
-
return apiCall;
|
|
122
|
-
}()
|
|
123
|
-
/**
|
|
124
|
-
* Fetch media items from Tradly API
|
|
125
|
-
* GET /v1/media?page=1&parent=0&mime_type=...
|
|
126
|
-
*/
|
|
127
|
-
)
|
|
128
|
-
}, {
|
|
129
|
-
key: "fetchMedia",
|
|
130
|
-
value: (function () {
|
|
131
|
-
var _fetchMedia = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
|
|
132
|
-
var mimeTypes, _ref2$page, page, _ref2$parent, parent, setISLoading, isLoading, params, mimeTypeParam;
|
|
133
|
-
return _regenerator().w(function (_context2) {
|
|
134
|
-
while (1) switch (_context2.n) {
|
|
135
|
-
case 0:
|
|
136
|
-
mimeTypes = _ref2.mimeTypes, _ref2$page = _ref2.page, page = _ref2$page === void 0 ? 1 : _ref2$page, _ref2$parent = _ref2.parent, parent = _ref2$parent === void 0 ? 0 : _ref2$parent, setISLoading = _ref2.setISLoading, isLoading = _ref2.isLoading;
|
|
137
|
-
params = {
|
|
138
|
-
page: page,
|
|
139
|
-
parent: parent
|
|
140
|
-
}; // Add mime_type to params if provided
|
|
141
|
-
if (mimeTypes) {
|
|
142
|
-
mimeTypeParam = Array.isArray(mimeTypes) ? mimeTypes.join(',') : mimeTypes;
|
|
143
|
-
params.mime_type = mimeTypeParam;
|
|
144
|
-
}
|
|
145
|
-
return _context2.a(2, this.apiCall({
|
|
146
|
-
method: 'GET',
|
|
147
|
-
path: '/v1/media',
|
|
148
|
-
params: params,
|
|
149
|
-
setISLoading: setISLoading,
|
|
150
|
-
isLoading: isLoading
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
}, _callee2, this);
|
|
154
|
-
}));
|
|
155
|
-
function fetchMedia(_x2) {
|
|
156
|
-
return _fetchMedia.apply(this, arguments);
|
|
157
|
-
}
|
|
158
|
-
return fetchMedia;
|
|
159
|
-
}()
|
|
160
|
-
/**
|
|
161
|
-
* Get S3 signed upload URLs from API
|
|
162
|
-
*/
|
|
163
|
-
)
|
|
164
|
-
}, {
|
|
165
|
-
key: "getS3SignedUrls",
|
|
166
|
-
value: (function () {
|
|
167
|
-
var _getS3SignedUrls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(files, authKey) {
|
|
168
|
-
var auth_key, fileData, headers, _response$data$data, response, _t2;
|
|
169
|
-
return _regenerator().w(function (_context3) {
|
|
170
|
-
while (1) switch (_context3.p = _context3.n) {
|
|
171
|
-
case 0:
|
|
172
|
-
auth_key = authKey || this.authKey;
|
|
173
|
-
if (auth_key) {
|
|
174
|
-
_context3.n = 1;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
throw new Error('Authentication key is required for upload');
|
|
178
|
-
case 1:
|
|
179
|
-
if (this.apiBaseUrl) {
|
|
180
|
-
_context3.n = 2;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
throw new Error('API base URL is required. The package automatically detects it from ENVIRONMENT, or you can set apiBaseUrl in config: new MediaApiService({ apiBaseUrl: "https://api.tradly.app" })');
|
|
184
|
-
case 2:
|
|
185
|
-
// Prepare file data
|
|
186
|
-
fileData = files.map(function (file) {
|
|
187
|
-
return {
|
|
188
|
-
name: file.name.replace(/\s/g, '-'),
|
|
189
|
-
type: file.type
|
|
190
|
-
};
|
|
191
|
-
}); // Prepare headers
|
|
192
|
-
headers = {
|
|
193
|
-
'Content-Type': 'application/json',
|
|
194
|
-
'X-Auth-Key': auth_key // Capital X for Tradly API
|
|
195
|
-
}; // Add Bearer token if provided
|
|
196
|
-
|
|
197
|
-
if (this.bearerToken) {
|
|
198
|
-
headers['Authorization'] = "Bearer ".concat(this.bearerToken);
|
|
199
|
-
}
|
|
200
|
-
_context3.p = 3;
|
|
201
|
-
_context3.n = 4;
|
|
202
|
-
return axios({
|
|
203
|
-
method: 'POST',
|
|
204
|
-
url: "".concat(this.apiBaseUrl, "/v1/utils/S3signedUploadURL"),
|
|
205
|
-
headers: headers,
|
|
206
|
-
data: {
|
|
207
|
-
files: fileData
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
case 4:
|
|
211
|
-
response = _context3.v;
|
|
212
|
-
if (!response.data.error) {
|
|
213
|
-
_context3.n = 5;
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
throw new Error(response.data.error);
|
|
217
|
-
case 5:
|
|
218
|
-
return _context3.a(2, response.data.result || ((_response$data$data = response.data.data) === null || _response$data$data === void 0 ? void 0 : _response$data$data.result) || response.data);
|
|
219
|
-
case 6:
|
|
220
|
-
_context3.p = 6;
|
|
221
|
-
_t2 = _context3.v;
|
|
222
|
-
console.error('Error getting S3 signed URLs:', _t2);
|
|
223
|
-
if (this.onError) {
|
|
224
|
-
this.onError(_t2);
|
|
225
|
-
}
|
|
226
|
-
throw _t2;
|
|
227
|
-
case 7:
|
|
228
|
-
return _context3.a(2);
|
|
229
|
-
}
|
|
230
|
-
}, _callee3, this, [[3, 6]]);
|
|
231
|
-
}));
|
|
232
|
-
function getS3SignedUrls(_x3, _x4) {
|
|
233
|
-
return _getS3SignedUrls.apply(this, arguments);
|
|
234
|
-
}
|
|
235
|
-
return getS3SignedUrls;
|
|
236
|
-
}()
|
|
237
|
-
/**
|
|
238
|
-
* Upload media files using direct API call
|
|
239
|
-
* This includes the full upload logic: get S3 signed URLs -> upload to S3 -> save to media API
|
|
240
|
-
*/
|
|
241
|
-
)
|
|
242
|
-
}, {
|
|
243
|
-
key: "uploadMedia",
|
|
244
|
-
value: (function () {
|
|
245
|
-
var _uploadMedia = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(files, authKey) {
|
|
246
|
-
var auth_key, all_files_uri, upload_files, upload_full_files, i, element, file_data, responseFiles, index, path, fileURI, res, mediaData, _t3, _t4;
|
|
247
|
-
return _regenerator().w(function (_context4) {
|
|
248
|
-
while (1) switch (_context4.p = _context4.n) {
|
|
249
|
-
case 0:
|
|
250
|
-
auth_key = authKey || this.authKey;
|
|
251
|
-
if (auth_key) {
|
|
252
|
-
_context4.n = 1;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
throw new Error('Authentication key is required for upload');
|
|
256
|
-
case 1:
|
|
257
|
-
all_files_uri = [];
|
|
258
|
-
upload_files = [];
|
|
259
|
-
upload_full_files = []; // Process all files
|
|
260
|
-
i = 0;
|
|
261
|
-
case 2:
|
|
262
|
-
if (!(i < files.length)) {
|
|
263
|
-
_context4.n = 14;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
element = files[i]; // Check if file already has a path (from previous upload)
|
|
267
|
-
if (element.full_file === null && element.path) {
|
|
268
|
-
all_files_uri.push(element.path);
|
|
269
|
-
} else {
|
|
270
|
-
// Prepare file data for upload
|
|
271
|
-
file_data = {
|
|
272
|
-
name: element.name.replace(/\s/g, '-'),
|
|
273
|
-
type: element.type
|
|
274
|
-
};
|
|
275
|
-
upload_files.push(file_data);
|
|
276
|
-
upload_full_files.push(element);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Upload files when we've processed all files
|
|
280
|
-
if (!(files.length === i + 1 && upload_files.length > 0)) {
|
|
281
|
-
_context4.n = 13;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
_context4.p = 3;
|
|
285
|
-
_context4.n = 4;
|
|
286
|
-
return this.getS3SignedUrls(upload_full_files, auth_key);
|
|
287
|
-
case 4:
|
|
288
|
-
responseFiles = _context4.v;
|
|
289
|
-
index = 0;
|
|
290
|
-
case 5:
|
|
291
|
-
if (!(index < responseFiles.length)) {
|
|
292
|
-
_context4.n = 10;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
path = responseFiles[index].signedUrl;
|
|
296
|
-
fileURI = responseFiles[index].fileUri;
|
|
297
|
-
_context4.p = 6;
|
|
298
|
-
_context4.n = 7;
|
|
299
|
-
return fetch(path, {
|
|
300
|
-
method: 'PUT',
|
|
301
|
-
headers: {
|
|
302
|
-
ContentType: upload_files[index].type
|
|
303
|
-
},
|
|
304
|
-
body: upload_full_files[index]
|
|
305
|
-
});
|
|
306
|
-
case 7:
|
|
307
|
-
res = _context4.v;
|
|
308
|
-
if (res.ok) {
|
|
309
|
-
all_files_uri.push(fileURI);
|
|
310
|
-
} else {
|
|
311
|
-
console.error("Failed to upload file ".concat(index + 1));
|
|
312
|
-
}
|
|
313
|
-
_context4.n = 9;
|
|
314
|
-
break;
|
|
315
|
-
case 8:
|
|
316
|
-
_context4.p = 8;
|
|
317
|
-
_t3 = _context4.v;
|
|
318
|
-
console.error("Error uploading file ".concat(index + 1, ":"), _t3);
|
|
319
|
-
case 9:
|
|
320
|
-
index++;
|
|
321
|
-
_context4.n = 5;
|
|
322
|
-
break;
|
|
323
|
-
case 10:
|
|
324
|
-
if (!(all_files_uri.length > 0)) {
|
|
325
|
-
_context4.n = 11;
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
mediaData = all_files_uri.map(function (url, index) {
|
|
329
|
-
var originalFile = upload_full_files[index];
|
|
330
|
-
return {
|
|
331
|
-
type: 1,
|
|
332
|
-
parent: 0,
|
|
333
|
-
url: url,
|
|
334
|
-
name: originalFile.name.replace(/\s/g, '-'),
|
|
335
|
-
mime_type: originalFile.type
|
|
336
|
-
};
|
|
337
|
-
}); // Save to media API - POST /v1/media with { media: [...] }
|
|
338
|
-
_context4.n = 11;
|
|
339
|
-
return this.apiCall({
|
|
340
|
-
method: 'POST',
|
|
341
|
-
path: '/v1/media',
|
|
342
|
-
data: {
|
|
343
|
-
media: mediaData
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
case 11:
|
|
347
|
-
_context4.n = 13;
|
|
348
|
-
break;
|
|
349
|
-
case 12:
|
|
350
|
-
_context4.p = 12;
|
|
351
|
-
_t4 = _context4.v;
|
|
352
|
-
console.error('Upload error:', _t4);
|
|
353
|
-
if (this.onError) {
|
|
354
|
-
this.onError(_t4);
|
|
355
|
-
}
|
|
356
|
-
throw _t4;
|
|
357
|
-
case 13:
|
|
358
|
-
i++;
|
|
359
|
-
_context4.n = 2;
|
|
360
|
-
break;
|
|
361
|
-
case 14:
|
|
362
|
-
return _context4.a(2, all_files_uri);
|
|
363
|
-
}
|
|
364
|
-
}, _callee4, this, [[6, 8], [3, 12]]);
|
|
365
|
-
}));
|
|
366
|
-
function uploadMedia(_x5, _x6) {
|
|
367
|
-
return _uploadMedia.apply(this, arguments);
|
|
368
|
-
}
|
|
369
|
-
return uploadMedia;
|
|
370
|
-
}())
|
|
371
|
-
}]);
|
|
372
|
-
}();
|
|
1
|
+
import MediaApiService from '../core/MediaApiService';
|
|
373
2
|
export default MediaApiService;
|