@tradly/asset 1.0.13 → 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 -254
- 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 -253
- 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,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
|
+
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 }; })(); }
|
|
11
|
+
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); }
|
|
12
|
+
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); }
|
|
13
|
+
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); }); }; }
|
|
14
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
|
+
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); } }
|
|
16
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
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); }
|
|
19
|
+
/**
|
|
20
|
+
* Get the API base URL based on environment
|
|
21
|
+
* @returns {string} API base URL
|
|
22
|
+
*/
|
|
23
|
+
var getApiBaseUrl = function getApiBaseUrl(environment) {
|
|
24
|
+
// Check if environment includes 'dev' (case insensitive)
|
|
25
|
+
var isDev = environment && String(environment).toLowerCase().includes("dev");
|
|
26
|
+
return isDev ? "https://api.dev.tradly.app" : "https://api.tradly.app";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* API Service for Media Gallery
|
|
31
|
+
* Handles all API calls with Tradly authentication
|
|
32
|
+
* Includes full upload logic using direct API call to S3 signed URL endpoint
|
|
33
|
+
*/
|
|
34
|
+
var MediaApiService = /*#__PURE__*/function () {
|
|
35
|
+
function MediaApiService() {
|
|
36
|
+
var _process$env;
|
|
37
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
|
+
_classCallCheck(this, MediaApiService);
|
|
39
|
+
this.authKey = config.authKey || "";
|
|
40
|
+
// Auto-detect API base URL from environment, or use provided one
|
|
41
|
+
var environment = config.environment || typeof process !== "undefined" && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.ENVIRONMENT) || "";
|
|
42
|
+
this.apiBaseUrl = config.apiBaseUrl || getApiBaseUrl(environment);
|
|
43
|
+
this.bearerToken = config.bearerToken || ""; // Bearer token for Authorization header
|
|
44
|
+
this.onError = config.onError || null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Set authentication key
|
|
49
|
+
*/
|
|
50
|
+
return _createClass(MediaApiService, [{
|
|
51
|
+
key: "setAuthKey",
|
|
52
|
+
value: function setAuthKey(authKey) {
|
|
53
|
+
this.authKey = authKey;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Set API base URL (used for all API calls)
|
|
58
|
+
*/
|
|
59
|
+
}, {
|
|
60
|
+
key: "setApiBaseUrl",
|
|
61
|
+
value: function setApiBaseUrl(apiBaseUrl) {
|
|
62
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Set Bearer token for Authorization header
|
|
67
|
+
*/
|
|
68
|
+
}, {
|
|
69
|
+
key: "setBearerToken",
|
|
70
|
+
value: function setBearerToken(bearerToken) {
|
|
71
|
+
this.bearerToken = bearerToken;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Make API call with authentication to Tradly API
|
|
76
|
+
*/
|
|
77
|
+
}, {
|
|
78
|
+
key: "apiCall",
|
|
79
|
+
value: (function () {
|
|
80
|
+
var _apiCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
81
|
+
var method, path, data, params, setISLoading, isLoading, headers, response, _t;
|
|
82
|
+
return _regenerator().w(function (_context) {
|
|
83
|
+
while (1) switch (_context.p = _context.n) {
|
|
84
|
+
case 0:
|
|
85
|
+
method = _ref.method, path = _ref.path, data = _ref.data, params = _ref.params, setISLoading = _ref.setISLoading, isLoading = _ref.isLoading;
|
|
86
|
+
if (setISLoading) setISLoading(true);
|
|
87
|
+
_context.p = 1;
|
|
88
|
+
headers = {
|
|
89
|
+
"Content-Type": "application/json"
|
|
90
|
+
}; // Add auth key to headers if provided (X-Auth-Key header)
|
|
91
|
+
if (this.authKey) {
|
|
92
|
+
headers["X-Auth-Key"] = this.authKey;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Add Bearer token if provided
|
|
96
|
+
if (this.bearerToken) {
|
|
97
|
+
headers["Authorization"] = "Bearer ".concat(this.bearerToken);
|
|
98
|
+
}
|
|
99
|
+
_context.n = 2;
|
|
100
|
+
return (0, _axios.default)({
|
|
101
|
+
method: method,
|
|
102
|
+
url: "".concat(this.apiBaseUrl).concat(path),
|
|
103
|
+
headers: headers,
|
|
104
|
+
data: data,
|
|
105
|
+
params: params
|
|
106
|
+
});
|
|
107
|
+
case 2:
|
|
108
|
+
response = _context.v;
|
|
109
|
+
if (setISLoading) setISLoading(false);
|
|
110
|
+
return _context.a(2, response.data);
|
|
111
|
+
case 3:
|
|
112
|
+
_context.p = 3;
|
|
113
|
+
_t = _context.v;
|
|
114
|
+
if (setISLoading) setISLoading(false);
|
|
115
|
+
if (this.onError) {
|
|
116
|
+
this.onError(_t);
|
|
117
|
+
}
|
|
118
|
+
throw _t;
|
|
119
|
+
case 4:
|
|
120
|
+
return _context.a(2);
|
|
121
|
+
}
|
|
122
|
+
}, _callee, this, [[1, 3]]);
|
|
123
|
+
}));
|
|
124
|
+
function apiCall(_x) {
|
|
125
|
+
return _apiCall.apply(this, arguments);
|
|
126
|
+
}
|
|
127
|
+
return apiCall;
|
|
128
|
+
}()
|
|
129
|
+
/**
|
|
130
|
+
* Fetch media items from Tradly API
|
|
131
|
+
* GET /v1/media?page=1&parent=0&mime_type=...
|
|
132
|
+
*/
|
|
133
|
+
)
|
|
134
|
+
}, {
|
|
135
|
+
key: "fetchMedia",
|
|
136
|
+
value: (function () {
|
|
137
|
+
var _fetchMedia = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
|
|
138
|
+
var mimeTypes, _ref2$page, page, _ref2$parent, parent, setISLoading, isLoading, params, mimeTypeParam;
|
|
139
|
+
return _regenerator().w(function (_context2) {
|
|
140
|
+
while (1) switch (_context2.n) {
|
|
141
|
+
case 0:
|
|
142
|
+
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;
|
|
143
|
+
params = {
|
|
144
|
+
page: page,
|
|
145
|
+
parent: parent
|
|
146
|
+
}; // Add mime_type to params if provided
|
|
147
|
+
if (mimeTypes) {
|
|
148
|
+
mimeTypeParam = Array.isArray(mimeTypes) ? mimeTypes.join(",") : mimeTypes;
|
|
149
|
+
params.mime_type = mimeTypeParam;
|
|
150
|
+
}
|
|
151
|
+
return _context2.a(2, this.apiCall({
|
|
152
|
+
method: "GET",
|
|
153
|
+
path: "/v1/media",
|
|
154
|
+
params: params,
|
|
155
|
+
setISLoading: setISLoading,
|
|
156
|
+
isLoading: isLoading
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
}, _callee2, this);
|
|
160
|
+
}));
|
|
161
|
+
function fetchMedia(_x2) {
|
|
162
|
+
return _fetchMedia.apply(this, arguments);
|
|
163
|
+
}
|
|
164
|
+
return fetchMedia;
|
|
165
|
+
}()
|
|
166
|
+
/**
|
|
167
|
+
* Get S3 signed upload URLs from API
|
|
168
|
+
*/
|
|
169
|
+
)
|
|
170
|
+
}, {
|
|
171
|
+
key: "getS3SignedUrls",
|
|
172
|
+
value: (function () {
|
|
173
|
+
var _getS3SignedUrls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(files, authKey) {
|
|
174
|
+
var auth_key, fileData, headers, _response$data$data, response, _t2;
|
|
175
|
+
return _regenerator().w(function (_context3) {
|
|
176
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
177
|
+
case 0:
|
|
178
|
+
auth_key = authKey || this.authKey;
|
|
179
|
+
if (auth_key) {
|
|
180
|
+
_context3.n = 1;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
throw new Error("Authentication key is required for upload");
|
|
184
|
+
case 1:
|
|
185
|
+
if (this.apiBaseUrl) {
|
|
186
|
+
_context3.n = 2;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
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" })');
|
|
190
|
+
case 2:
|
|
191
|
+
// Prepare file data
|
|
192
|
+
fileData = files.map(function (file) {
|
|
193
|
+
return {
|
|
194
|
+
name: file.name.replace(/\s/g, "-"),
|
|
195
|
+
type: file.type
|
|
196
|
+
};
|
|
197
|
+
}); // Prepare headers
|
|
198
|
+
headers = {
|
|
199
|
+
"Content-Type": "application/json",
|
|
200
|
+
"X-Auth-Key": auth_key // Capital X for Tradly API
|
|
201
|
+
}; // Add Bearer token if provided
|
|
202
|
+
|
|
203
|
+
if (this.bearerToken) {
|
|
204
|
+
headers["Authorization"] = "Bearer ".concat(this.bearerToken);
|
|
205
|
+
}
|
|
206
|
+
_context3.p = 3;
|
|
207
|
+
_context3.n = 4;
|
|
208
|
+
return (0, _axios.default)({
|
|
209
|
+
method: "POST",
|
|
210
|
+
url: "".concat(this.apiBaseUrl, "/v1/utils/S3signedUploadURL"),
|
|
211
|
+
headers: headers,
|
|
212
|
+
data: {
|
|
213
|
+
files: fileData
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
case 4:
|
|
217
|
+
response = _context3.v;
|
|
218
|
+
if (!response.data.error) {
|
|
219
|
+
_context3.n = 5;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
throw new Error(response.data.error);
|
|
223
|
+
case 5:
|
|
224
|
+
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);
|
|
225
|
+
case 6:
|
|
226
|
+
_context3.p = 6;
|
|
227
|
+
_t2 = _context3.v;
|
|
228
|
+
console.error("Error getting S3 signed URLs:", _t2);
|
|
229
|
+
if (this.onError) {
|
|
230
|
+
this.onError(_t2);
|
|
231
|
+
}
|
|
232
|
+
throw _t2;
|
|
233
|
+
case 7:
|
|
234
|
+
return _context3.a(2);
|
|
235
|
+
}
|
|
236
|
+
}, _callee3, this, [[3, 6]]);
|
|
237
|
+
}));
|
|
238
|
+
function getS3SignedUrls(_x3, _x4) {
|
|
239
|
+
return _getS3SignedUrls.apply(this, arguments);
|
|
240
|
+
}
|
|
241
|
+
return getS3SignedUrls;
|
|
242
|
+
}()
|
|
243
|
+
/**
|
|
244
|
+
* Upload media files using direct API call
|
|
245
|
+
* This includes the full upload logic: get S3 signed URLs -> upload to S3 -> save to media API
|
|
246
|
+
*/
|
|
247
|
+
)
|
|
248
|
+
}, {
|
|
249
|
+
key: "uploadMedia",
|
|
250
|
+
value: (function () {
|
|
251
|
+
var _uploadMedia = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(files, authKey) {
|
|
252
|
+
var auth_key, all_files_uri, upload_files, upload_full_files, i, element, file_data, responseFiles, index, path, fileURI, originalFile, fileBody, fileResponse, blob, res, mediaData, _t3, _t4;
|
|
253
|
+
return _regenerator().w(function (_context4) {
|
|
254
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
255
|
+
case 0:
|
|
256
|
+
auth_key = authKey || this.authKey;
|
|
257
|
+
if (auth_key) {
|
|
258
|
+
_context4.n = 1;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
throw new Error("Authentication key is required for upload");
|
|
262
|
+
case 1:
|
|
263
|
+
all_files_uri = [];
|
|
264
|
+
upload_files = [];
|
|
265
|
+
upload_full_files = []; // Process all files
|
|
266
|
+
i = 0;
|
|
267
|
+
case 2:
|
|
268
|
+
if (!(i < files.length)) {
|
|
269
|
+
_context4.n = 17;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
element = files[i]; // Check if file already has a path (from previous upload)
|
|
273
|
+
if (element.full_file === null && element.path) {
|
|
274
|
+
all_files_uri.push(element.path);
|
|
275
|
+
} else {
|
|
276
|
+
// Prepare file data for upload
|
|
277
|
+
file_data = {
|
|
278
|
+
name: element.name.replace(/\s/g, "-"),
|
|
279
|
+
type: element.type
|
|
280
|
+
};
|
|
281
|
+
upload_files.push(file_data);
|
|
282
|
+
upload_full_files.push(element);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Upload files when we've processed all files
|
|
286
|
+
if (!(files.length === i + 1 && upload_files.length > 0)) {
|
|
287
|
+
_context4.n = 16;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
_context4.p = 3;
|
|
291
|
+
_context4.n = 4;
|
|
292
|
+
return this.getS3SignedUrls(upload_full_files, auth_key);
|
|
293
|
+
case 4:
|
|
294
|
+
responseFiles = _context4.v;
|
|
295
|
+
index = 0;
|
|
296
|
+
case 5:
|
|
297
|
+
if (!(index < responseFiles.length)) {
|
|
298
|
+
_context4.n = 13;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
path = responseFiles[index].signedUrl;
|
|
302
|
+
fileURI = responseFiles[index].fileUri;
|
|
303
|
+
originalFile = upload_full_files[index];
|
|
304
|
+
_context4.p = 6;
|
|
305
|
+
fileBody = originalFile; // Handle React Native file URIs
|
|
306
|
+
// If file has a uri property, it's from React Native - fetch it first
|
|
307
|
+
if (!(originalFile.uri && typeof originalFile.uri === "string")) {
|
|
308
|
+
_context4.n = 9;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
_context4.n = 7;
|
|
312
|
+
return fetch(originalFile.uri);
|
|
313
|
+
case 7:
|
|
314
|
+
fileResponse = _context4.v;
|
|
315
|
+
_context4.n = 8;
|
|
316
|
+
return fileResponse.blob();
|
|
317
|
+
case 8:
|
|
318
|
+
blob = _context4.v;
|
|
319
|
+
fileBody = blob;
|
|
320
|
+
case 9:
|
|
321
|
+
_context4.n = 10;
|
|
322
|
+
return fetch(path, {
|
|
323
|
+
method: "PUT",
|
|
324
|
+
headers: {
|
|
325
|
+
ContentType: upload_files[index].type
|
|
326
|
+
},
|
|
327
|
+
body: fileBody
|
|
328
|
+
});
|
|
329
|
+
case 10:
|
|
330
|
+
res = _context4.v;
|
|
331
|
+
if (res.ok) {
|
|
332
|
+
all_files_uri.push(fileURI);
|
|
333
|
+
} else {
|
|
334
|
+
console.error("Failed to upload file ".concat(index + 1));
|
|
335
|
+
}
|
|
336
|
+
_context4.n = 12;
|
|
337
|
+
break;
|
|
338
|
+
case 11:
|
|
339
|
+
_context4.p = 11;
|
|
340
|
+
_t3 = _context4.v;
|
|
341
|
+
console.error("Error uploading file ".concat(index + 1, ":"), _t3);
|
|
342
|
+
case 12:
|
|
343
|
+
index++;
|
|
344
|
+
_context4.n = 5;
|
|
345
|
+
break;
|
|
346
|
+
case 13:
|
|
347
|
+
if (!(all_files_uri.length > 0)) {
|
|
348
|
+
_context4.n = 14;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
mediaData = all_files_uri.map(function (url, index) {
|
|
352
|
+
var originalFile = upload_full_files[index];
|
|
353
|
+
return {
|
|
354
|
+
type: 1,
|
|
355
|
+
parent: 0,
|
|
356
|
+
url: url,
|
|
357
|
+
name: originalFile.name.replace(/\s/g, "-"),
|
|
358
|
+
mime_type: originalFile.type
|
|
359
|
+
};
|
|
360
|
+
}); // Save to media API - POST /v1/media with { media: [...] }
|
|
361
|
+
_context4.n = 14;
|
|
362
|
+
return this.apiCall({
|
|
363
|
+
method: "POST",
|
|
364
|
+
path: "/v1/media",
|
|
365
|
+
data: {
|
|
366
|
+
media: mediaData
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
case 14:
|
|
370
|
+
_context4.n = 16;
|
|
371
|
+
break;
|
|
372
|
+
case 15:
|
|
373
|
+
_context4.p = 15;
|
|
374
|
+
_t4 = _context4.v;
|
|
375
|
+
console.error("Upload error:", _t4);
|
|
376
|
+
if (this.onError) {
|
|
377
|
+
this.onError(_t4);
|
|
378
|
+
}
|
|
379
|
+
throw _t4;
|
|
380
|
+
case 16:
|
|
381
|
+
i++;
|
|
382
|
+
_context4.n = 2;
|
|
383
|
+
break;
|
|
384
|
+
case 17:
|
|
385
|
+
return _context4.a(2, all_files_uri);
|
|
386
|
+
}
|
|
387
|
+
}, _callee4, this, [[6, 11], [3, 15]]);
|
|
388
|
+
}));
|
|
389
|
+
function uploadMedia(_x5, _x6) {
|
|
390
|
+
return _uploadMedia.apply(this, arguments);
|
|
391
|
+
}
|
|
392
|
+
return uploadMedia;
|
|
393
|
+
}())
|
|
394
|
+
}]);
|
|
395
|
+
}();
|
|
396
|
+
var _default = exports.default = MediaApiService;
|
|
@@ -1,253 +1 @@
|
|
|
1
|
-
|
|
2
|
-
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); }
|
|
3
|
-
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); }
|
|
4
|
-
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); }); }; }
|
|
5
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
6
|
-
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."); }
|
|
7
|
-
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; } }
|
|
8
|
-
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; }
|
|
9
|
-
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; } }
|
|
10
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
11
|
-
import React, { useState } from "react";
|
|
12
|
-
import { CameraIcon } from "./Icons";
|
|
13
|
-
|
|
14
|
-
// Helper: compress image on the client before upload
|
|
15
|
-
// - Downscale to fit within maxWidth/maxHeight.
|
|
16
|
-
// - Convert raster images (JPEG/PNG, etc.) to WebP for better compression.
|
|
17
|
-
// - Skip SVG (vector) to avoid degradation.
|
|
18
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
19
|
-
var compressImage = function compressImage(file) {
|
|
20
|
-
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
21
|
-
_ref$maxWidth = _ref.maxWidth,
|
|
22
|
-
maxWidth = _ref$maxWidth === void 0 ? 1600 : _ref$maxWidth,
|
|
23
|
-
_ref$maxHeight = _ref.maxHeight,
|
|
24
|
-
maxHeight = _ref$maxHeight === void 0 ? 1600 : _ref$maxHeight,
|
|
25
|
-
_ref$quality = _ref.quality,
|
|
26
|
-
quality = _ref$quality === void 0 ? 1 : _ref$quality,
|
|
27
|
-
_ref$convertToWebp = _ref.convertToWebp,
|
|
28
|
-
convertToWebp = _ref$convertToWebp === void 0 ? true : _ref$convertToWebp;
|
|
29
|
-
return new Promise(function (resolve) {
|
|
30
|
-
// Non-image or SVG: skip compression to avoid losing vector quality
|
|
31
|
-
if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
|
|
32
|
-
resolve(file);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
var img = new Image();
|
|
36
|
-
img.onload = function () {
|
|
37
|
-
var width = img.width,
|
|
38
|
-
height = img.height;
|
|
39
|
-
|
|
40
|
-
// If the image is already small, keep it as-is
|
|
41
|
-
if (width <= maxWidth && height <= maxHeight) {
|
|
42
|
-
resolve(file);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
var scale = Math.min(maxWidth / width, maxHeight / height);
|
|
46
|
-
var targetWidth = Math.round(width * scale);
|
|
47
|
-
var targetHeight = Math.round(height * scale);
|
|
48
|
-
var canvas = document.createElement("canvas");
|
|
49
|
-
canvas.width = targetWidth;
|
|
50
|
-
canvas.height = targetHeight;
|
|
51
|
-
var ctx = canvas.getContext("2d");
|
|
52
|
-
if (!ctx) {
|
|
53
|
-
resolve(file);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
|
|
57
|
-
|
|
58
|
-
// Prefer WebP for raster images to reduce size (where supported)
|
|
59
|
-
// Keep original type for GIF to avoid breaking animation.
|
|
60
|
-
var isRaster = file.type === "image/jpeg" || file.type === "image/jpg" || file.type === "image/png" || file.type === "image/webp" || file.type === "image/heic" || file.type === "image/heif";
|
|
61
|
-
var targetType = convertToWebp && isRaster && file.type !== "image/gif" ? "image/webp" : file.type;
|
|
62
|
-
canvas.toBlob(function (blob) {
|
|
63
|
-
if (!blob) {
|
|
64
|
-
resolve(file);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// If we converted to WebP, normalize extension in the file name
|
|
69
|
-
var newName = file.name;
|
|
70
|
-
if (targetType === "image/webp") {
|
|
71
|
-
var dotIndex = file.name.lastIndexOf(".");
|
|
72
|
-
newName = dotIndex > 0 ? "".concat(file.name.slice(0, dotIndex), ".webp") : "".concat(file.name, ".webp");
|
|
73
|
-
}
|
|
74
|
-
var compressedFile = new File([blob], newName, {
|
|
75
|
-
type: targetType,
|
|
76
|
-
lastModified: Date.now()
|
|
77
|
-
});
|
|
78
|
-
resolve(compressedFile);
|
|
79
|
-
}, targetType, quality);
|
|
80
|
-
};
|
|
81
|
-
img.onerror = function () {
|
|
82
|
-
resolve(file);
|
|
83
|
-
};
|
|
84
|
-
var reader = new FileReader();
|
|
85
|
-
reader.onload = function (event) {
|
|
86
|
-
var _event$target;
|
|
87
|
-
img.src = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result;
|
|
88
|
-
};
|
|
89
|
-
reader.onerror = function () {
|
|
90
|
-
return resolve(file);
|
|
91
|
-
};
|
|
92
|
-
reader.readAsDataURL(file);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
var FileUpload = function FileUpload(_ref2) {
|
|
96
|
-
var loadMedia = _ref2.loadMedia,
|
|
97
|
-
accept = _ref2.accept,
|
|
98
|
-
title = _ref2.title,
|
|
99
|
-
apiService = _ref2.apiService,
|
|
100
|
-
onUploadStart = _ref2.onUploadStart,
|
|
101
|
-
onUploadComplete = _ref2.onUploadComplete,
|
|
102
|
-
onUploadError = _ref2.onUploadError,
|
|
103
|
-
className = _ref2.className,
|
|
104
|
-
buttonClassName = _ref2.buttonClassName,
|
|
105
|
-
iconContainerClassName = _ref2.iconContainerClassName,
|
|
106
|
-
titleClassName = _ref2.titleClassName,
|
|
107
|
-
loadingClassName = _ref2.loadingClassName;
|
|
108
|
-
var _useState = useState([]),
|
|
109
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
110
|
-
files = _useState2[0],
|
|
111
|
-
setFiles = _useState2[1];
|
|
112
|
-
var _useState3 = useState(false),
|
|
113
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
114
|
-
isLoading = _useState4[0],
|
|
115
|
-
setISLoading = _useState4[1];
|
|
116
|
-
var _useState5 = useState(0),
|
|
117
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
118
|
-
length = _useState6[0],
|
|
119
|
-
setLength = _useState6[1];
|
|
120
|
-
|
|
121
|
-
// Upload files
|
|
122
|
-
var uploadFiles = /*#__PURE__*/function () {
|
|
123
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fileList) {
|
|
124
|
-
var filesToUpload, uploadedUrls, _t;
|
|
125
|
-
return _regenerator().w(function (_context) {
|
|
126
|
-
while (1) switch (_context.p = _context.n) {
|
|
127
|
-
case 0:
|
|
128
|
-
if (onUploadStart) {
|
|
129
|
-
onUploadStart(fileList);
|
|
130
|
-
}
|
|
131
|
-
setISLoading(true);
|
|
132
|
-
setLength(fileList.length);
|
|
133
|
-
_context.p = 1;
|
|
134
|
-
filesToUpload = fileList; // For image uploads, compress on the client before sending
|
|
135
|
-
if (!(accept && accept.includes("image"))) {
|
|
136
|
-
_context.n = 3;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
_context.n = 2;
|
|
140
|
-
return Promise.all(fileList.map(function (file) {
|
|
141
|
-
return compressImage(file, {
|
|
142
|
-
maxWidth: 1600,
|
|
143
|
-
maxHeight: 1600,
|
|
144
|
-
quality: 0.95,
|
|
145
|
-
convertToWebp: true
|
|
146
|
-
});
|
|
147
|
-
}));
|
|
148
|
-
case 2:
|
|
149
|
-
filesToUpload = _context.v;
|
|
150
|
-
case 3:
|
|
151
|
-
_context.n = 4;
|
|
152
|
-
return apiService.uploadMedia(filesToUpload, apiService.authKey);
|
|
153
|
-
case 4:
|
|
154
|
-
uploadedUrls = _context.v;
|
|
155
|
-
if (onUploadComplete) {
|
|
156
|
-
onUploadComplete(uploadedUrls);
|
|
157
|
-
}
|
|
158
|
-
setLength(0);
|
|
159
|
-
if (loadMedia) {
|
|
160
|
-
loadMedia();
|
|
161
|
-
}
|
|
162
|
-
_context.n = 6;
|
|
163
|
-
break;
|
|
164
|
-
case 5:
|
|
165
|
-
_context.p = 5;
|
|
166
|
-
_t = _context.v;
|
|
167
|
-
console.error("Upload error:", _t);
|
|
168
|
-
if (onUploadError) {
|
|
169
|
-
onUploadError(_t);
|
|
170
|
-
}
|
|
171
|
-
case 6:
|
|
172
|
-
_context.p = 6;
|
|
173
|
-
setISLoading(false);
|
|
174
|
-
return _context.f(6);
|
|
175
|
-
case 7:
|
|
176
|
-
return _context.a(2);
|
|
177
|
-
}
|
|
178
|
-
}, _callee, null, [[1, 5, 6, 7]]);
|
|
179
|
-
}));
|
|
180
|
-
return function uploadFiles(_x) {
|
|
181
|
-
return _ref3.apply(this, arguments);
|
|
182
|
-
};
|
|
183
|
-
}();
|
|
184
|
-
|
|
185
|
-
// Default classes with customization support
|
|
186
|
-
var defaultContainerClass = "min-w-40 h-40";
|
|
187
|
-
var defaultButtonClass = "w-full h-full flex flex-col justify-center items-center text-sm border border-primary border-dashed rounded-lg hover:bg-gray-50 transition-colors";
|
|
188
|
-
var defaultIconContainerClass = "p-[10px] bg-primary rounded-full";
|
|
189
|
-
var defaultTitleClass = "mt-2";
|
|
190
|
-
var defaultLoadingClass = "flex items-center justify-center h-40 bg-gray-200 rounded-lg shadow-md animate-pulse";
|
|
191
|
-
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
192
|
-
children: [/*#__PURE__*/_jsxs("div", {
|
|
193
|
-
className: className || defaultContainerClass,
|
|
194
|
-
children: [/*#__PURE__*/_jsx("input", {
|
|
195
|
-
required: true,
|
|
196
|
-
id: "media_select_".concat(files === null || files === void 0 ? void 0 : files.length),
|
|
197
|
-
type: "file",
|
|
198
|
-
className: "hidden",
|
|
199
|
-
accept: accept,
|
|
200
|
-
placeholder: "",
|
|
201
|
-
onChange: (/*#__PURE__*/function () {
|
|
202
|
-
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
|
|
203
|
-
var all_files;
|
|
204
|
-
return _regenerator().w(function (_context2) {
|
|
205
|
-
while (1) switch (_context2.n) {
|
|
206
|
-
case 0:
|
|
207
|
-
e.stopPropagation();
|
|
208
|
-
all_files = Array.from(e.target.files || []);
|
|
209
|
-
if (!((all_files === null || all_files === void 0 ? void 0 : all_files.length) > 0)) {
|
|
210
|
-
_context2.n = 1;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
_context2.n = 1;
|
|
214
|
-
return uploadFiles(all_files);
|
|
215
|
-
case 1:
|
|
216
|
-
// Reset input
|
|
217
|
-
e.target.value = "";
|
|
218
|
-
case 2:
|
|
219
|
-
return _context2.a(2);
|
|
220
|
-
}
|
|
221
|
-
}, _callee2);
|
|
222
|
-
}));
|
|
223
|
-
return function (_x2) {
|
|
224
|
-
return _ref4.apply(this, arguments);
|
|
225
|
-
};
|
|
226
|
-
}()),
|
|
227
|
-
multiple: true
|
|
228
|
-
}), /*#__PURE__*/_jsxs("button", {
|
|
229
|
-
type: "button",
|
|
230
|
-
className: buttonClassName || defaultButtonClass,
|
|
231
|
-
onClick: function onClick() {
|
|
232
|
-
return document.getElementById("media_select_".concat(files === null || files === void 0 ? void 0 : files.length)).click();
|
|
233
|
-
},
|
|
234
|
-
disabled: isLoading,
|
|
235
|
-
children: [/*#__PURE__*/_jsx("span", {
|
|
236
|
-
className: iconContainerClassName || defaultIconContainerClass,
|
|
237
|
-
children: /*#__PURE__*/_jsx(CameraIcon, {})
|
|
238
|
-
}), /*#__PURE__*/_jsx("span", {
|
|
239
|
-
className: titleClassName || defaultTitleClass,
|
|
240
|
-
children: title
|
|
241
|
-
})]
|
|
242
|
-
})]
|
|
243
|
-
}), isLoading && Array.from({
|
|
244
|
-
length: length
|
|
245
|
-
}).map(function (_, index) {
|
|
246
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
247
|
-
className: loadingClassName || defaultLoadingClass,
|
|
248
|
-
children: ["File Uploading... ", index + 1, "/", length]
|
|
249
|
-
}, index);
|
|
250
|
-
})]
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
export default FileUpload;
|
|
1
|
+
export { default } from "../web/FileUpload.web";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../native/FileUpload.native';
|