@strapi/upload 5.0.4 → 5.0.6
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/_chunks/{index-CiMn3eDX.js → index-4dDBcT2s.js} +298 -372
- package/dist/_chunks/index-4dDBcT2s.js.map +1 -0
- package/dist/_chunks/{index-DA78j7Pv.js → index-BWoTIP6T.js} +2 -5
- package/dist/_chunks/index-BWoTIP6T.js.map +1 -0
- package/dist/_chunks/{index-8KH4JCz1.mjs → index-CZ3rXZbR.mjs} +2 -5
- package/dist/_chunks/index-CZ3rXZbR.mjs.map +1 -0
- package/dist/_chunks/{index-CIZ1_7yU.mjs → index-D0UI77ZE.mjs} +2 -2
- package/dist/_chunks/{index-CIZ1_7yU.mjs.map → index-D0UI77ZE.mjs.map} +1 -1
- package/dist/_chunks/{index-Bg-hWXGc.mjs → index-DKKpjnQN.mjs} +299 -373
- package/dist/_chunks/index-DKKpjnQN.mjs.map +1 -0
- package/dist/_chunks/{index-aHR0r3CO.js → index-DPWou2fL.js} +2 -2
- package/dist/_chunks/{index-aHR0r3CO.js.map → index-DPWou2fL.js.map} +1 -1
- package/dist/_chunks/{index-DVLnDTxs.js → index-POwhla6y.js} +9 -12
- package/dist/_chunks/index-POwhla6y.js.map +1 -0
- package/dist/_chunks/{index-CgbGZ1U3.mjs → index-p2ufusDD.mjs} +9 -12
- package/dist/_chunks/index-p2ufusDD.mjs.map +1 -0
- package/dist/admin/index.js +1 -4
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +1 -4
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/src/hooks/usePersistentState.d.ts +0 -1
- package/package.json +6 -6
- package/dist/_chunks/index-8KH4JCz1.mjs.map +0 -1
- package/dist/_chunks/index-Bg-hWXGc.mjs.map +0 -1
- package/dist/_chunks/index-CgbGZ1U3.mjs.map +0 -1
- package/dist/_chunks/index-CiMn3eDX.js.map +0 -1
- package/dist/_chunks/index-DA78j7Pv.js.map +0 -1
- package/dist/_chunks/index-DVLnDTxs.js.map +0 -1
- package/dist/admin/src/components/SelectTree/utils/flattenTree.d.ts +0 -14
- package/dist/admin/src/hooks/useAssets.d.ts +0 -14
- package/dist/admin/src/hooks/useBulkMove.d.ts +0 -78
- package/dist/admin/src/hooks/useBulkRemove.d.ts +0 -73
- package/dist/admin/src/hooks/useConfig.d.ts +0 -5
- package/dist/admin/src/hooks/useCropImg.d.ts +0 -9
- package/dist/admin/src/hooks/useEditAsset.d.ts +0 -119
- package/dist/admin/src/hooks/useEditFolder.d.ts +0 -71
- package/dist/admin/src/hooks/useFolder.d.ts +0 -7
- package/dist/admin/src/hooks/useFolderStructure.d.ts +0 -12
- package/dist/admin/src/hooks/useFolders.d.ts +0 -11
- package/dist/admin/src/hooks/useMediaLibraryPermissions.d.ts +0 -3
- package/dist/admin/src/hooks/useModalQueryParams.d.ts +0 -21
- package/dist/admin/src/hooks/useRemoveAsset.d.ts +0 -66
- package/dist/admin/src/hooks/useUpload.d.ts +0 -12
- package/dist/admin/src/hooks/utils/rename-keys.d.ts +0 -6
- package/dist/admin/src/newConstants.d.ts +0 -45
- package/dist/admin/src/pluginId.d.ts +0 -2
- package/dist/admin/src/utils/appendSearchParamsToUrl.d.ts +0 -6
- package/dist/admin/src/utils/containsAssetFilter.d.ts +0 -2
- package/dist/admin/src/utils/createAssetUrl.d.ts +0 -2
- package/dist/admin/src/utils/displayedFilters.d.ts +0 -22
- package/dist/admin/src/utils/downloadFile.d.ts +0 -1
- package/dist/admin/src/utils/findRecursiveFolderByValue.d.ts +0 -10
- package/dist/admin/src/utils/formatBytes.d.ts +0 -1
- package/dist/admin/src/utils/formatDuration.d.ts +0 -1
- package/dist/admin/src/utils/getAPIInnerErrors.d.ts +0 -14
- package/dist/admin/src/utils/getAllowedFiles.d.ts +0 -15
- package/dist/admin/src/utils/getBreadcrumbDataCM.d.ts +0 -19
- package/dist/admin/src/utils/getBreadcrumbDataML.d.ts +0 -18
- package/dist/admin/src/utils/getFileExtension.d.ts +0 -1
- package/dist/admin/src/utils/getFolderParents.d.ts +0 -10
- package/dist/admin/src/utils/getFolderURL.d.ts +0 -5
- package/dist/admin/src/utils/getTrad.d.ts +0 -1
- package/dist/admin/src/utils/index.d.ts +0 -25
- package/dist/admin/src/utils/moveElement.d.ts +0 -1
- package/dist/admin/src/utils/normalizeAPIError.d.ts +0 -22
- package/dist/admin/src/utils/prefixFileUrlWithBackendUrl.d.ts +0 -1
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +0 -5
- package/dist/admin/src/utils/rawFileToAsset.d.ts +0 -14
- package/dist/admin/src/utils/toSingularTypes.d.ts +0 -2
- package/dist/admin/src/utils/typeFromMime.d.ts +0 -2
- package/dist/admin/src/utils/urlYupSchema.d.ts +0 -8
- package/dist/admin/src/utils/urlsToAssets.d.ts +0 -10
- package/dist/shared/contracts/configuration.d.ts +0 -44
- package/dist/shared/contracts/files.d.ts +0 -207
- package/dist/shared/contracts/folders.d.ts +0 -140
- package/dist/shared/contracts/settings.d.ts +0 -41
|
@@ -10,10 +10,10 @@ const styledComponents = require("styled-components");
|
|
|
10
10
|
const byteSize = require("byte-size");
|
|
11
11
|
const dateFns = require("date-fns");
|
|
12
12
|
const qs = require("qs");
|
|
13
|
-
const yup = require("yup");
|
|
14
13
|
const reactQuery = require("react-query");
|
|
15
14
|
const formik = require("formik");
|
|
16
15
|
const isEqual = require("lodash/isEqual");
|
|
16
|
+
const yup = require("yup");
|
|
17
17
|
const ReactSelect = require("react-select");
|
|
18
18
|
const Cropper = require("cropperjs");
|
|
19
19
|
require("cropperjs/dist/cropper.css");
|
|
@@ -44,8 +44,8 @@ function _interopNamespace(e) {
|
|
|
44
44
|
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
45
45
|
const PropTypes__default = /* @__PURE__ */ _interopDefault(PropTypes);
|
|
46
46
|
const byteSize__default = /* @__PURE__ */ _interopDefault(byteSize);
|
|
47
|
-
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
48
47
|
const isEqual__default = /* @__PURE__ */ _interopDefault(isEqual);
|
|
48
|
+
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
|
49
49
|
const ReactSelect__default = /* @__PURE__ */ _interopDefault(ReactSelect);
|
|
50
50
|
const Cropper__default = /* @__PURE__ */ _interopDefault(Cropper);
|
|
51
51
|
const isEmpty__default = /* @__PURE__ */ _interopDefault(isEmpty);
|
|
@@ -60,7 +60,7 @@ const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
62
|
const name$1 = "@strapi/upload";
|
|
63
|
-
const version = "5.0.
|
|
63
|
+
const version = "5.0.0";
|
|
64
64
|
const description = "Makes it easy to upload images and files to your Strapi Application.";
|
|
65
65
|
const license = "SEE LICENSE IN LICENSE";
|
|
66
66
|
const author = {
|
|
@@ -147,7 +147,6 @@ const devDependencies = {
|
|
|
147
147
|
"@testing-library/dom": "10.1.0",
|
|
148
148
|
"@testing-library/react": "15.0.7",
|
|
149
149
|
"@testing-library/user-event": "14.5.2",
|
|
150
|
-
"@types/byte-size": "8.1.2",
|
|
151
150
|
"@types/fs-extra": "11.0.4",
|
|
152
151
|
"@types/koa": "2.13.4",
|
|
153
152
|
"@types/koa-range": "0.3.5",
|
|
@@ -169,7 +168,7 @@ const peerDependencies = {
|
|
|
169
168
|
"styled-components": "^6.0.0"
|
|
170
169
|
};
|
|
171
170
|
const engines = {
|
|
172
|
-
node: ">=18.0.0 <=
|
|
171
|
+
node: ">=18.0.0 <=20.x.x",
|
|
173
172
|
npm: ">=6.0.0"
|
|
174
173
|
};
|
|
175
174
|
const strapi = {
|
|
@@ -201,7 +200,7 @@ const appendSearchParamsToUrl = ({ url, params }) => {
|
|
|
201
200
|
}
|
|
202
201
|
const urlObj = new URL(url, window.strapi.backendURL);
|
|
203
202
|
Object.entries(params).forEach(([key, value]) => {
|
|
204
|
-
if (value !== void 0
|
|
203
|
+
if (value !== void 0) {
|
|
205
204
|
urlObj.searchParams.append(key, value);
|
|
206
205
|
}
|
|
207
206
|
});
|
|
@@ -230,43 +229,6 @@ const createAssetUrl = (asset, forThumbnail = true) => {
|
|
|
230
229
|
const assetUrl = forThumbnail ? asset?.formats?.thumbnail?.url || asset.url : asset.url;
|
|
231
230
|
return prefixFileUrlWithBackendUrl(assetUrl);
|
|
232
231
|
};
|
|
233
|
-
const displayedFilters = [
|
|
234
|
-
{
|
|
235
|
-
name: "createdAt",
|
|
236
|
-
fieldSchema: {
|
|
237
|
-
type: "date"
|
|
238
|
-
},
|
|
239
|
-
metadatas: { label: "createdAt" }
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
name: "updatedAt",
|
|
243
|
-
fieldSchema: {
|
|
244
|
-
type: "date"
|
|
245
|
-
},
|
|
246
|
-
metadatas: { label: "updatedAt" }
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
name: "mime",
|
|
250
|
-
fieldSchema: {
|
|
251
|
-
type: "enumeration",
|
|
252
|
-
options: [
|
|
253
|
-
{ label: "audio", value: "audio" },
|
|
254
|
-
{ label: "file", value: "file" },
|
|
255
|
-
{ label: "image", value: "image" },
|
|
256
|
-
{ label: "video", value: "video" }
|
|
257
|
-
]
|
|
258
|
-
},
|
|
259
|
-
metadatas: { label: "type" }
|
|
260
|
-
}
|
|
261
|
-
];
|
|
262
|
-
const downloadFile = async (url, fileName) => {
|
|
263
|
-
const fileBlob = await fetch(url).then((res) => res.blob());
|
|
264
|
-
const urlDownload = window.URL.createObjectURL(fileBlob);
|
|
265
|
-
const link = document.createElement("a");
|
|
266
|
-
link.href = urlDownload;
|
|
267
|
-
link.setAttribute("download", fileName);
|
|
268
|
-
link.click();
|
|
269
|
-
};
|
|
270
232
|
function findRecursiveFolderByValue(data, value) {
|
|
271
233
|
let result;
|
|
272
234
|
function iter(a) {
|
|
@@ -280,8 +242,7 @@ function findRecursiveFolderByValue(data, value) {
|
|
|
280
242
|
return result;
|
|
281
243
|
}
|
|
282
244
|
function formatBytes(receivedBytes, decimals = 0) {
|
|
283
|
-
const
|
|
284
|
-
const { value, unit } = byteSize__default.default(realBytes * 1e3, { precision: decimals });
|
|
245
|
+
const { value, unit } = byteSize__default.default(receivedBytes * 1e3, { precision: decimals });
|
|
285
246
|
if (!unit) {
|
|
286
247
|
return "0B";
|
|
287
248
|
}
|
|
@@ -292,81 +253,9 @@ const formatDuration = (durationInSecond) => {
|
|
|
292
253
|
const duration = dateFns.intervalToDuration({ start: 0, end: durationInSecond * 1e3 });
|
|
293
254
|
return `${zeroPad(duration.hours)}:${zeroPad(duration.minutes)}:${zeroPad(duration.seconds)}`;
|
|
294
255
|
};
|
|
295
|
-
const toSingularTypes = (types) => {
|
|
296
|
-
if (!types) {
|
|
297
|
-
return [];
|
|
298
|
-
}
|
|
299
|
-
return types.map((type) => type.substring(0, type.length - 1));
|
|
300
|
-
};
|
|
301
|
-
const getAllowedFiles = (pluralTypes, files2) => {
|
|
302
|
-
const singularTypes = toSingularTypes(pluralTypes);
|
|
303
|
-
const allowedFiles = files2.filter((file) => {
|
|
304
|
-
const fileType = file?.mime?.split("/")[0];
|
|
305
|
-
if (!fileType) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (singularTypes.includes("file") && !["video", "image", "audio"].includes(fileType)) {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
return singularTypes.includes(fileType);
|
|
312
|
-
});
|
|
313
|
-
return allowedFiles;
|
|
314
|
-
};
|
|
315
|
-
function getPrefixedId(message, callback) {
|
|
316
|
-
const prefixedMessage = `apiError.${message}`;
|
|
317
|
-
if (typeof callback === "function") {
|
|
318
|
-
return callback(prefixedMessage);
|
|
319
|
-
}
|
|
320
|
-
return prefixedMessage;
|
|
321
|
-
}
|
|
322
|
-
function normalizeError(error, { name: name2, intlMessagePrefixCallback }) {
|
|
323
|
-
const { message } = error;
|
|
324
|
-
const normalizedError = {
|
|
325
|
-
id: getPrefixedId(message, intlMessagePrefixCallback),
|
|
326
|
-
defaultMessage: message,
|
|
327
|
-
name: error.name ?? name2,
|
|
328
|
-
values: {}
|
|
329
|
-
};
|
|
330
|
-
if ("path" in error) {
|
|
331
|
-
normalizedError.values = { path: error.path.join(".") };
|
|
332
|
-
}
|
|
333
|
-
return normalizedError;
|
|
334
|
-
}
|
|
335
|
-
const validateErrorIsYupValidationError = (err) => typeof err.details === "object" && err.details !== null && "errors" in err.details;
|
|
336
|
-
function normalizeAPIError(apiError, intlMessagePrefixCallback) {
|
|
337
|
-
const error = apiError.response?.data.error;
|
|
338
|
-
if (error) {
|
|
339
|
-
if (validateErrorIsYupValidationError(error)) {
|
|
340
|
-
return {
|
|
341
|
-
name: error.name,
|
|
342
|
-
message: error?.message || null,
|
|
343
|
-
errors: error.details.errors.map(
|
|
344
|
-
(err) => normalizeError(err, { name: error.name, intlMessagePrefixCallback })
|
|
345
|
-
)
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
return normalizeError(error, { intlMessagePrefixCallback });
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
function getAPIInnerErrors(error, { getTrad: getTrad2 }) {
|
|
353
|
-
const normalizedError = normalizeAPIError(error, getTrad2);
|
|
354
|
-
if (normalizedError && "errors" in normalizedError) {
|
|
355
|
-
return normalizedError.errors.reduce((acc, error2) => {
|
|
356
|
-
if ("path" in error2.values) {
|
|
357
|
-
acc[error2.values.path] = {
|
|
358
|
-
id: error2.id,
|
|
359
|
-
defaultMessage: error2.defaultMessage
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
return acc;
|
|
363
|
-
}, {});
|
|
364
|
-
}
|
|
365
|
-
return normalizedError?.defaultMessage;
|
|
366
|
-
}
|
|
367
256
|
const pluginId = pluginPkg.name.replace(/^@strapi\//i, "");
|
|
368
257
|
const getTrad = (id2) => `${pluginId}.${id2}`;
|
|
369
|
-
const
|
|
258
|
+
const getBreadcrumbDataML = (folder) => {
|
|
370
259
|
let data = [
|
|
371
260
|
{
|
|
372
261
|
id: null,
|
|
@@ -404,8 +293,7 @@ const getFolderURL = (pathname, currentQuery, { folder, folderPath } = {}) => {
|
|
|
404
293
|
);
|
|
405
294
|
return `${pathname}${queryParamsString ? `?${queryParamsString}` : ""}`;
|
|
406
295
|
};
|
|
407
|
-
|
|
408
|
-
function flattenTree(tree, parent = null, depth = 0) {
|
|
296
|
+
function flattenTree(tree, parent, depth = 0) {
|
|
409
297
|
return tree.flatMap(
|
|
410
298
|
(item) => item.children ? [{ ...item, parent: parent?.value, depth }, ...flattenTree(item.children, item, depth + 1)] : { ...item, depth, parent: parent?.value }
|
|
411
299
|
);
|
|
@@ -420,178 +308,70 @@ const getFolderParents = (folders, currentFolderId) => {
|
|
|
420
308
|
let { parent } = currentFolder;
|
|
421
309
|
while (parent !== void 0) {
|
|
422
310
|
let parentToStore = flatFolders.find(({ value }) => value === parent);
|
|
423
|
-
parents.push({ id: parentToStore
|
|
424
|
-
parent = parentToStore
|
|
311
|
+
parents.push({ id: parentToStore.value, label: parentToStore.label });
|
|
312
|
+
parent = parentToStore.parent;
|
|
425
313
|
}
|
|
426
314
|
return parents.reverse();
|
|
427
315
|
};
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
433
|
-
return array;
|
|
434
|
-
};
|
|
435
|
-
const moveElement = (array, index2, offset) => {
|
|
436
|
-
const newIndex = index2 + offset;
|
|
437
|
-
return move(array, index2, newIndex);
|
|
438
|
-
};
|
|
439
|
-
const prefixPluginTranslations = (trad, pluginId2) => {
|
|
440
|
-
if (!pluginId2) {
|
|
441
|
-
throw new TypeError("pluginId can't be empty");
|
|
316
|
+
const toSingularTypes = (types) => {
|
|
317
|
+
if (!types) {
|
|
318
|
+
return [];
|
|
442
319
|
}
|
|
443
|
-
return
|
|
444
|
-
acc[`${pluginId2}.${current}`] = trad[current];
|
|
445
|
-
return acc;
|
|
446
|
-
}, {});
|
|
447
|
-
};
|
|
448
|
-
var AssetType$1 = /* @__PURE__ */ ((AssetType2) => {
|
|
449
|
-
AssetType2["Video"] = "video";
|
|
450
|
-
AssetType2["Image"] = "image";
|
|
451
|
-
AssetType2["Document"] = "doc";
|
|
452
|
-
AssetType2["Audio"] = "audio";
|
|
453
|
-
return AssetType2;
|
|
454
|
-
})(AssetType$1 || {});
|
|
455
|
-
var AssetSource$1 = /* @__PURE__ */ ((AssetSource2) => {
|
|
456
|
-
AssetSource2["Url"] = "url";
|
|
457
|
-
AssetSource2["Computer"] = "computer";
|
|
458
|
-
return AssetSource2;
|
|
459
|
-
})(AssetSource$1 || {});
|
|
460
|
-
const PERMISSIONS$1 = {
|
|
461
|
-
// This permission regards the main component (App) and is used to tell
|
|
462
|
-
// If the plugin link should be displayed in the menu
|
|
463
|
-
// And also if the plugin is accessible. This use case is found when a user types the url of the
|
|
464
|
-
// plugin directly in the browser
|
|
465
|
-
main: [
|
|
466
|
-
{ action: "plugin::upload.read", subject: null },
|
|
467
|
-
{
|
|
468
|
-
action: "plugin::upload.assets.create",
|
|
469
|
-
subject: null
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
action: "plugin::upload.assets.update",
|
|
473
|
-
subject: null
|
|
474
|
-
}
|
|
475
|
-
],
|
|
476
|
-
copyLink: [
|
|
477
|
-
{
|
|
478
|
-
action: "plugin::upload.assets.copy-link",
|
|
479
|
-
subject: null
|
|
480
|
-
}
|
|
481
|
-
],
|
|
482
|
-
create: [
|
|
483
|
-
{
|
|
484
|
-
action: "plugin::upload.assets.create",
|
|
485
|
-
subject: null
|
|
486
|
-
}
|
|
487
|
-
],
|
|
488
|
-
download: [
|
|
489
|
-
{
|
|
490
|
-
action: "plugin::upload.assets.download",
|
|
491
|
-
subject: null
|
|
492
|
-
}
|
|
493
|
-
],
|
|
494
|
-
read: [{ action: "plugin::upload.read", subject: null }],
|
|
495
|
-
configureView: [{ action: "plugin::upload.configure-view", subject: null }],
|
|
496
|
-
settings: [{ action: "plugin::upload.settings.read", subject: null }],
|
|
497
|
-
update: [{ action: "plugin::upload.assets.update", subject: null, fields: null }]
|
|
320
|
+
return types.map((type) => type.substring(0, type.length - 1));
|
|
498
321
|
};
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return AssetType$1.Video;
|
|
505
|
-
}
|
|
506
|
-
if (mime.includes(AssetType$1.Audio)) {
|
|
507
|
-
return AssetType$1.Audio;
|
|
322
|
+
const getFileExtension = (ext) => ext && ext[0] === "." ? ext.substring(1) : ext;
|
|
323
|
+
function getPrefixedId(message, callback) {
|
|
324
|
+
const prefixedMessage = `apiError.${message}`;
|
|
325
|
+
if (typeof callback === "function") {
|
|
326
|
+
return callback(prefixedMessage);
|
|
508
327
|
}
|
|
509
|
-
return
|
|
510
|
-
};
|
|
511
|
-
const rawFileToAsset = (rawFile, assetSource) => {
|
|
512
|
-
return {
|
|
513
|
-
size: rawFile.size / 1e3,
|
|
514
|
-
createdAt: new Date(rawFile.lastModified).toISOString(),
|
|
515
|
-
name: rawFile.name,
|
|
516
|
-
source: assetSource,
|
|
517
|
-
type: typeFromMime(rawFile.type),
|
|
518
|
-
url: URL.createObjectURL(rawFile),
|
|
519
|
-
ext: rawFile.name.split(".").pop(),
|
|
520
|
-
mime: rawFile.type,
|
|
521
|
-
rawFile,
|
|
522
|
-
isLocal: true
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
function getFilenameFromURL(url) {
|
|
526
|
-
return new URL(url).pathname.split("/").pop();
|
|
328
|
+
return prefixedMessage;
|
|
527
329
|
}
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
return assets;
|
|
554
|
-
};
|
|
555
|
-
const urlSchema = yup__namespace.object().shape({
|
|
556
|
-
urls: yup__namespace.string().test({
|
|
557
|
-
name: "isUrlValid",
|
|
558
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
559
|
-
message: "${path}",
|
|
560
|
-
test(values = "") {
|
|
561
|
-
const urls = values.split(/\r?\n/);
|
|
562
|
-
if (urls.length === 0) {
|
|
563
|
-
return this.createError({
|
|
564
|
-
path: this.path,
|
|
565
|
-
message: strapiAdmin.translatedErrors.min.id
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
if (urls.length > 20) {
|
|
569
|
-
return this.createError({
|
|
570
|
-
path: this.path,
|
|
571
|
-
message: strapiAdmin.translatedErrors.max.id
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
const filtered = urls.filter((val) => {
|
|
575
|
-
try {
|
|
576
|
-
new URL(val);
|
|
577
|
-
return false;
|
|
578
|
-
} catch (err) {
|
|
579
|
-
return true;
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
const filteredLength = filtered.length;
|
|
583
|
-
if (filteredLength === 0) {
|
|
584
|
-
return true;
|
|
585
|
-
}
|
|
586
|
-
const errorMessage = filteredLength > 1 ? "form.upload-url.error.url.invalids" : "form.upload-url.error.url.invalid";
|
|
587
|
-
return this.createError({
|
|
588
|
-
path: this.path,
|
|
589
|
-
message: getTrad(errorMessage),
|
|
590
|
-
params: { number: filtered.length }
|
|
591
|
-
});
|
|
330
|
+
function normalizeError(error, { name: name2, intlMessagePrefixCallback }) {
|
|
331
|
+
const { message } = error;
|
|
332
|
+
const normalizedError = {
|
|
333
|
+
id: getPrefixedId(message, intlMessagePrefixCallback),
|
|
334
|
+
defaultMessage: message,
|
|
335
|
+
name: error.name ?? name2,
|
|
336
|
+
values: {}
|
|
337
|
+
};
|
|
338
|
+
if ("path" in error) {
|
|
339
|
+
normalizedError.values = { path: error.path.join(".") };
|
|
340
|
+
}
|
|
341
|
+
return normalizedError;
|
|
342
|
+
}
|
|
343
|
+
const validateErrorIsYupValidationError = (err) => typeof err.details === "object" && err.details !== null && "errors" in err.details;
|
|
344
|
+
function normalizeAPIError(apiError, intlMessagePrefixCallback) {
|
|
345
|
+
const error = apiError.response?.data.error;
|
|
346
|
+
if (error) {
|
|
347
|
+
if (validateErrorIsYupValidationError(error)) {
|
|
348
|
+
return {
|
|
349
|
+
name: error.name,
|
|
350
|
+
message: error?.message || null,
|
|
351
|
+
errors: error.details.errors.map(
|
|
352
|
+
(err) => normalizeError(err, { name: error.name, intlMessagePrefixCallback })
|
|
353
|
+
)
|
|
354
|
+
};
|
|
592
355
|
}
|
|
593
|
-
|
|
594
|
-
}
|
|
356
|
+
return normalizeError(error, { intlMessagePrefixCallback });
|
|
357
|
+
}
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
function getAPIInnerErrors(error, { getTrad: getTrad2 }) {
|
|
361
|
+
const normalizedError = normalizeAPIError(error, getTrad2);
|
|
362
|
+
if (normalizedError && "errors" in normalizedError) {
|
|
363
|
+
return normalizedError.errors.reduce((acc, error2) => {
|
|
364
|
+
if ("path" in error2.values) {
|
|
365
|
+
acc[error2.values.path] = {
|
|
366
|
+
id: error2.id,
|
|
367
|
+
defaultMessage: error2.defaultMessage
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return acc;
|
|
371
|
+
}, {});
|
|
372
|
+
}
|
|
373
|
+
return normalizedError?.defaultMessage;
|
|
374
|
+
}
|
|
595
375
|
const AssetType = {
|
|
596
376
|
Video: "video",
|
|
597
377
|
Image: "image",
|
|
@@ -840,7 +620,7 @@ const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
|
|
840
620
|
}
|
|
841
621
|
}
|
|
842
622
|
);
|
|
843
|
-
|
|
623
|
+
React.useEffect(() => {
|
|
844
624
|
if (data) {
|
|
845
625
|
notifyStatus(
|
|
846
626
|
formatMessage({
|
|
@@ -850,7 +630,7 @@ const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
|
|
850
630
|
);
|
|
851
631
|
}
|
|
852
632
|
}, [data, formatMessage, notifyStatus]);
|
|
853
|
-
|
|
633
|
+
React.useEffect(() => {
|
|
854
634
|
if (error) {
|
|
855
635
|
toggleNotification({
|
|
856
636
|
type: "danger",
|
|
@@ -927,7 +707,7 @@ const useFolders = ({ enabled = true, query = {} } = {}) => {
|
|
|
927
707
|
}, [data, formatMessage, notifyStatus]);
|
|
928
708
|
return { data, error, isLoading };
|
|
929
709
|
};
|
|
930
|
-
const { main, ...restPermissions } = PERMISSIONS
|
|
710
|
+
const { main, ...restPermissions } = PERMISSIONS;
|
|
931
711
|
const useMediaLibraryPermissions = () => {
|
|
932
712
|
const { allowedActions, isLoading } = strapiAdmin.useRBAC(restPermissions);
|
|
933
713
|
return { ...allowedActions, isLoading };
|
|
@@ -955,7 +735,7 @@ const useConfig = () => {
|
|
|
955
735
|
/**
|
|
956
736
|
* We're cementing that we always expect an object to be returned.
|
|
957
737
|
*/
|
|
958
|
-
select: (data) => data
|
|
738
|
+
select: (data) => !data ? {} : data
|
|
959
739
|
}
|
|
960
740
|
);
|
|
961
741
|
const putMutation = reactQuery.useMutation(
|
|
@@ -985,7 +765,7 @@ const useModalQueryParams = (initialState) => {
|
|
|
985
765
|
const {
|
|
986
766
|
config: { data: config }
|
|
987
767
|
} = useConfig();
|
|
988
|
-
const [queryObject, setQueryObject] =
|
|
768
|
+
const [queryObject, setQueryObject] = React.useState({
|
|
989
769
|
page: 1,
|
|
990
770
|
sort: "updatedAt:DESC",
|
|
991
771
|
pageSize: 10,
|
|
@@ -994,8 +774,8 @@ const useModalQueryParams = (initialState) => {
|
|
|
994
774
|
},
|
|
995
775
|
...initialState
|
|
996
776
|
});
|
|
997
|
-
|
|
998
|
-
if (config
|
|
777
|
+
React.useEffect(() => {
|
|
778
|
+
if (config) {
|
|
999
779
|
setQueryObject((prevQuery) => ({
|
|
1000
780
|
...prevQuery,
|
|
1001
781
|
sort: config.sort,
|
|
@@ -1004,32 +784,24 @@ const useModalQueryParams = (initialState) => {
|
|
|
1004
784
|
}
|
|
1005
785
|
}, [config]);
|
|
1006
786
|
const handleChangeFilters = (nextFilters) => {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
setQueryObject((prev) => ({ ...prev, page: 1, filters: { $and: nextFilters } }));
|
|
1013
|
-
}
|
|
787
|
+
trackUsage("didFilterMediaLibraryElements", {
|
|
788
|
+
location: "content-manager",
|
|
789
|
+
filter: Object.keys(nextFilters[nextFilters.length - 1])[0]
|
|
790
|
+
});
|
|
791
|
+
setQueryObject((prev) => ({ ...prev, page: 1, filters: { $and: nextFilters } }));
|
|
1014
792
|
};
|
|
1015
793
|
const handleChangePageSize = (pageSize) => {
|
|
1016
|
-
setQueryObject((prev) => ({
|
|
1017
|
-
...prev,
|
|
1018
|
-
pageSize: typeof pageSize === "string" ? parseInt(pageSize, 10) : pageSize,
|
|
1019
|
-
page: 1
|
|
1020
|
-
}));
|
|
794
|
+
setQueryObject((prev) => ({ ...prev, pageSize: parseInt(pageSize, 10), page: 1 }));
|
|
1021
795
|
};
|
|
1022
796
|
const handeChangePage = (page) => {
|
|
1023
797
|
setQueryObject((prev) => ({ ...prev, page }));
|
|
1024
798
|
};
|
|
1025
799
|
const handleChangeSort = (sort) => {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
setQueryObject((prev) => ({ ...prev, sort }));
|
|
1032
|
-
}
|
|
800
|
+
trackUsage("didSortMediaLibraryElements", {
|
|
801
|
+
location: "content-manager",
|
|
802
|
+
sort
|
|
803
|
+
});
|
|
804
|
+
setQueryObject((prev) => ({ ...prev, sort }));
|
|
1033
805
|
};
|
|
1034
806
|
const handleChangeSearch = (_q) => {
|
|
1035
807
|
if (_q) {
|
|
@@ -1118,6 +890,28 @@ const useSelectionState = (keys, initialValue) => {
|
|
|
1118
890
|
{ selectOne, selectAll, selectOnly, selectMultiple, deselectMultiple, setSelections }
|
|
1119
891
|
];
|
|
1120
892
|
};
|
|
893
|
+
const getAllowedFiles = (pluralTypes, files2) => {
|
|
894
|
+
const singularTypes = toSingularTypes(pluralTypes);
|
|
895
|
+
const allowedFiles = files2.filter((file) => {
|
|
896
|
+
const fileType = file.mime.split("/")[0];
|
|
897
|
+
if (singularTypes.includes("file") && !["video", "image", "audio"].includes(fileType)) {
|
|
898
|
+
return true;
|
|
899
|
+
}
|
|
900
|
+
return singularTypes.includes(fileType);
|
|
901
|
+
});
|
|
902
|
+
return allowedFiles;
|
|
903
|
+
};
|
|
904
|
+
const move = (array, oldIndex, newIndex) => {
|
|
905
|
+
if (newIndex >= array.length) {
|
|
906
|
+
newIndex = array.length - 1;
|
|
907
|
+
}
|
|
908
|
+
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
909
|
+
return array;
|
|
910
|
+
};
|
|
911
|
+
const moveElement = (array, index2, offset) => {
|
|
912
|
+
const newIndex = index2 + offset;
|
|
913
|
+
return move(array, index2, newIndex);
|
|
914
|
+
};
|
|
1121
915
|
const editAssetRequest = (asset, file, signal, onProgress, post) => {
|
|
1122
916
|
const endpoint2 = `/${pluginId}?id=${asset.id}`;
|
|
1123
917
|
const formData = new FormData();
|
|
@@ -1138,30 +932,33 @@ const editAssetRequest = (asset, file, signal, onProgress, post) => {
|
|
|
1138
932
|
}).then((res) => res.data);
|
|
1139
933
|
};
|
|
1140
934
|
const useEditAsset = () => {
|
|
1141
|
-
const [progress, setProgress] =
|
|
935
|
+
const [progress, setProgress] = React.useState(0);
|
|
1142
936
|
const { formatMessage } = reactIntl.useIntl();
|
|
1143
937
|
const { toggleNotification } = strapiAdmin.useNotification();
|
|
1144
938
|
const queryClient = reactQuery.useQueryClient();
|
|
1145
939
|
const abortController = new AbortController();
|
|
1146
940
|
const signal = abortController.signal;
|
|
1147
941
|
const { post } = strapiAdmin.useFetchClient();
|
|
1148
|
-
const mutation = reactQuery.useMutation(
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
942
|
+
const mutation = reactQuery.useMutation(
|
|
943
|
+
({ asset, file }) => editAssetRequest(asset, file, signal, setProgress, post),
|
|
944
|
+
{
|
|
945
|
+
onSuccess() {
|
|
946
|
+
queryClient.refetchQueries([pluginId, "assets"], { active: true });
|
|
947
|
+
queryClient.refetchQueries([pluginId, "asset-count"], { active: true });
|
|
948
|
+
queryClient.refetchQueries([pluginId, "folders"], { active: true });
|
|
949
|
+
},
|
|
950
|
+
onError(reason) {
|
|
951
|
+
if (reason.response.status === 403) {
|
|
952
|
+
toggleNotification({
|
|
953
|
+
type: "info",
|
|
954
|
+
message: formatMessage({ id: getTrad("permissions.not-allowed.update") })
|
|
955
|
+
});
|
|
956
|
+
} else {
|
|
957
|
+
toggleNotification({ type: "danger", message: reason.message });
|
|
958
|
+
}
|
|
1162
959
|
}
|
|
1163
960
|
}
|
|
1164
|
-
|
|
961
|
+
);
|
|
1165
962
|
const editAsset = (asset, file) => mutation.mutateAsync({ asset, file });
|
|
1166
963
|
const cancel = () => abortController.abort();
|
|
1167
964
|
return { ...mutation, cancel, editAsset, progress, status: mutation.status };
|
|
@@ -1183,9 +980,7 @@ const useFolderStructure = ({ enabled = true } = {}) => {
|
|
|
1183
980
|
const {
|
|
1184
981
|
data: { data: data2 }
|
|
1185
982
|
} = await get("/upload/folder-structure");
|
|
1186
|
-
const children = data2.map(
|
|
1187
|
-
(f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key)
|
|
1188
|
-
);
|
|
983
|
+
const children = data2.map((f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key));
|
|
1189
984
|
return [
|
|
1190
985
|
{
|
|
1191
986
|
value: null,
|
|
@@ -1555,10 +1350,10 @@ const DialogHeader = () => {
|
|
|
1555
1350
|
};
|
|
1556
1351
|
const QUALITY = 1;
|
|
1557
1352
|
const useCropImg = () => {
|
|
1558
|
-
const cropperRef =
|
|
1559
|
-
const [isCropping, setIsCropping] =
|
|
1560
|
-
const [size, setSize] =
|
|
1561
|
-
|
|
1353
|
+
const cropperRef = React.useRef();
|
|
1354
|
+
const [isCropping, setIsCropping] = React.useState(false);
|
|
1355
|
+
const [size, setSize] = React.useState({ width: void 0, height: void 0 });
|
|
1356
|
+
React.useEffect(() => {
|
|
1562
1357
|
return () => {
|
|
1563
1358
|
if (cropperRef.current) {
|
|
1564
1359
|
cropperRef.current.destroy();
|
|
@@ -1605,7 +1400,7 @@ const useCropImg = () => {
|
|
|
1605
1400
|
resolve(
|
|
1606
1401
|
new File([blob], name2, {
|
|
1607
1402
|
type: mimeType,
|
|
1608
|
-
|
|
1403
|
+
lastModifiedDate
|
|
1609
1404
|
})
|
|
1610
1405
|
);
|
|
1611
1406
|
},
|
|
@@ -1642,7 +1437,7 @@ const uploadAsset = (asset, folderId, signal, onProgress, post) => {
|
|
|
1642
1437
|
}).then((res) => res.data);
|
|
1643
1438
|
};
|
|
1644
1439
|
const useUpload = () => {
|
|
1645
|
-
const [progress, setProgress] =
|
|
1440
|
+
const [progress, setProgress] = React.useState(0);
|
|
1646
1441
|
const queryClient = reactQuery.useQueryClient();
|
|
1647
1442
|
const abortController = new AbortController();
|
|
1648
1443
|
const signal = abortController.signal;
|
|
@@ -1668,6 +1463,14 @@ const useUpload = () => {
|
|
|
1668
1463
|
status: mutation.status
|
|
1669
1464
|
};
|
|
1670
1465
|
};
|
|
1466
|
+
const downloadFile = async (url, fileName) => {
|
|
1467
|
+
const fileBlob = await fetch(url).then((res) => res.blob());
|
|
1468
|
+
const urlDownload = window.URL.createObjectURL(fileBlob);
|
|
1469
|
+
const link = document.createElement("a");
|
|
1470
|
+
link.href = urlDownload;
|
|
1471
|
+
link.setAttribute("download", fileName);
|
|
1472
|
+
link.click();
|
|
1473
|
+
};
|
|
1671
1474
|
const useClipboard = () => {
|
|
1672
1475
|
const copy = React.useCallback(async (value) => {
|
|
1673
1476
|
try {
|
|
@@ -1779,26 +1582,23 @@ const useRemoveAsset = (onSuccess) => {
|
|
|
1779
1582
|
const { formatMessage } = reactIntl.useIntl();
|
|
1780
1583
|
const queryClient = reactQuery.useQueryClient();
|
|
1781
1584
|
const { del } = strapiAdmin.useFetchClient();
|
|
1782
|
-
const mutation = reactQuery.useMutation(
|
|
1783
|
-
(
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
}
|
|
1797
|
-
onError(error) {
|
|
1798
|
-
toggleNotification({ type: "danger", message: error.message });
|
|
1799
|
-
}
|
|
1585
|
+
const mutation = reactQuery.useMutation((assetId) => del(`/upload/files/${assetId}`), {
|
|
1586
|
+
onSuccess() {
|
|
1587
|
+
queryClient.refetchQueries([pluginId, "assets"], { active: true });
|
|
1588
|
+
queryClient.refetchQueries([pluginId, "asset-count"], { active: true });
|
|
1589
|
+
toggleNotification({
|
|
1590
|
+
type: "success",
|
|
1591
|
+
message: formatMessage({
|
|
1592
|
+
id: "modal.remove.success-label",
|
|
1593
|
+
defaultMessage: "Elements have been successfully deleted."
|
|
1594
|
+
})
|
|
1595
|
+
});
|
|
1596
|
+
onSuccess();
|
|
1597
|
+
},
|
|
1598
|
+
onError(error) {
|
|
1599
|
+
toggleNotification({ type: "danger", message: error.message });
|
|
1800
1600
|
}
|
|
1801
|
-
);
|
|
1601
|
+
});
|
|
1802
1602
|
const removeAsset = async (assetId) => {
|
|
1803
1603
|
await mutation.mutateAsync(assetId);
|
|
1804
1604
|
};
|
|
@@ -2593,7 +2393,7 @@ const useBulkRemove = () => {
|
|
|
2593
2393
|
});
|
|
2594
2394
|
},
|
|
2595
2395
|
onError(error) {
|
|
2596
|
-
toggleNotification({ type: "danger", message: error
|
|
2396
|
+
toggleNotification({ type: "danger", message: error.message });
|
|
2597
2397
|
}
|
|
2598
2398
|
});
|
|
2599
2399
|
const remove = (...args) => mutation.mutateAsync(...args);
|
|
@@ -4037,6 +3837,35 @@ TableList.propTypes = {
|
|
|
4037
3837
|
shouldDisableBulkSelect: PropTypes__default.default.bool,
|
|
4038
3838
|
sortQuery: PropTypes__default.default.string
|
|
4039
3839
|
};
|
|
3840
|
+
const displayedFilters = [
|
|
3841
|
+
{
|
|
3842
|
+
name: "createdAt",
|
|
3843
|
+
fieldSchema: {
|
|
3844
|
+
type: "date"
|
|
3845
|
+
},
|
|
3846
|
+
metadatas: { label: "createdAt" }
|
|
3847
|
+
},
|
|
3848
|
+
{
|
|
3849
|
+
name: "updatedAt",
|
|
3850
|
+
fieldSchema: {
|
|
3851
|
+
type: "date"
|
|
3852
|
+
},
|
|
3853
|
+
metadatas: { label: "updatedAt" }
|
|
3854
|
+
},
|
|
3855
|
+
{
|
|
3856
|
+
name: "mime",
|
|
3857
|
+
fieldSchema: {
|
|
3858
|
+
type: "enumeration",
|
|
3859
|
+
options: [
|
|
3860
|
+
{ label: "audio", value: "audio" },
|
|
3861
|
+
{ label: "file", value: "file" },
|
|
3862
|
+
{ label: "image", value: "image" },
|
|
3863
|
+
{ label: "video", value: "video" }
|
|
3864
|
+
]
|
|
3865
|
+
},
|
|
3866
|
+
metadatas: { label: "type" }
|
|
3867
|
+
}
|
|
3868
|
+
];
|
|
4040
3869
|
const FilterTag = ({ attribute, filter, onClick, operator, value }) => {
|
|
4041
3870
|
const { formatMessage, formatDate, formatTime } = reactIntl.useIntl();
|
|
4042
3871
|
const handleClick = () => {
|
|
@@ -4083,7 +3912,7 @@ const FilterList = ({ appliedFilters, filtersSchema, onRemoveFilter }) => {
|
|
|
4083
3912
|
const nextFilters = appliedFilters.filter((prevFilter) => {
|
|
4084
3913
|
const name2 = Object.keys(filter)[0];
|
|
4085
3914
|
const filterType = Object.keys(filter[name2])[0];
|
|
4086
|
-
const value =
|
|
3915
|
+
const value = filter[name2][filterType];
|
|
4087
3916
|
return prevFilter[name2]?.[filterType] !== value;
|
|
4088
3917
|
});
|
|
4089
3918
|
onRemoveFilter(nextFilters);
|
|
@@ -4094,13 +3923,6 @@ const FilterList = ({ appliedFilters, filtersSchema, onRemoveFilter }) => {
|
|
|
4094
3923
|
const filterObj = filter[attributeName];
|
|
4095
3924
|
const operator = Object.keys(filterObj)[0];
|
|
4096
3925
|
let value = filterObj[operator];
|
|
4097
|
-
if (Array.isArray(value)) {
|
|
4098
|
-
value = value.join(", ");
|
|
4099
|
-
} else if (typeof value === "object") {
|
|
4100
|
-
value = Object.values(value).join(", ");
|
|
4101
|
-
} else {
|
|
4102
|
-
value = Array.isArray(value) || typeof value === "object" ? Object.values(value).join(", ") : decodeURIComponent(value);
|
|
4103
|
-
}
|
|
4104
3926
|
let displayedOperator = operator;
|
|
4105
3927
|
if (attribute.name === "mime") {
|
|
4106
3928
|
displayedOperator = operator === "$contains" ? "$eq" : "$ne";
|
|
@@ -4308,8 +4130,7 @@ const FilterPopover = ({ displayedFilters: displayedFilters2, filters, onSubmit,
|
|
|
4308
4130
|
const handleSubmit = (e) => {
|
|
4309
4131
|
e.preventDefault();
|
|
4310
4132
|
e.stopPropagation();
|
|
4311
|
-
|
|
4312
|
-
if (encodedValue) {
|
|
4133
|
+
if (modifiedData.value) {
|
|
4313
4134
|
if (modifiedData.name === "mime") {
|
|
4314
4135
|
const alreadyAppliedFilters = filters.filter((filter) => {
|
|
4315
4136
|
return Object.keys(filter)[0] === "mime";
|
|
@@ -4391,10 +4212,10 @@ const FilterPopover = ({ displayedFilters: displayedFilters2, filters, onSubmit,
|
|
|
4391
4212
|
return;
|
|
4392
4213
|
}
|
|
4393
4214
|
const hasFilter = filters.find((filter) => {
|
|
4394
|
-
return filter[modifiedData.name] && filter[modifiedData.name]?.[modifiedData.filter] ===
|
|
4215
|
+
return filter[modifiedData.name] && filter[modifiedData.name]?.[modifiedData.filter] === modifiedData.value;
|
|
4395
4216
|
}) !== void 0;
|
|
4396
4217
|
if (!hasFilter) {
|
|
4397
|
-
let filterToAdd = { [modifiedData.name]: { [modifiedData.filter]:
|
|
4218
|
+
let filterToAdd = { [modifiedData.name]: { [modifiedData.filter]: modifiedData.value } };
|
|
4398
4219
|
const nextFilters = [...filters, filterToAdd];
|
|
4399
4220
|
onSubmit(nextFilters);
|
|
4400
4221
|
}
|
|
@@ -4896,7 +4717,7 @@ const BrowseStep = ({
|
|
|
4896
4717
|
isSelectable: isSelectable(singularTypes, asset?.mime),
|
|
4897
4718
|
type: "asset"
|
|
4898
4719
|
}));
|
|
4899
|
-
const breadcrumbs = !isCurrentFolderLoading &&
|
|
4720
|
+
const breadcrumbs = !isCurrentFolderLoading && getBreadcrumbDataML(currentFolder);
|
|
4900
4721
|
const allAllowedAsset = getAllowedFiles(allowedTypes, assets);
|
|
4901
4722
|
const areAllAssetSelected = allAllowedAsset.length > 0 && selectedAssets.length > 0 && allAllowedAsset.every(
|
|
4902
4723
|
(asset) => selectedAssets.findIndex((currAsset) => currAsset.id === asset.id) !== -1
|
|
@@ -4947,7 +4768,7 @@ const BrowseStep = ({
|
|
|
4947
4768
|
}
|
|
4948
4769
|
)
|
|
4949
4770
|
] }),
|
|
4950
|
-
(assetCount > 0 || folderCount > 0 || isSearching) && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { marginLeft: "auto", shrink: 0,
|
|
4771
|
+
(assetCount > 0 || folderCount > 0 || isSearching) && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { marginLeft: "auto", shrink: 0, children: [
|
|
4951
4772
|
/* @__PURE__ */ jsxRuntime.jsx(ActionContainer, { paddingTop: 1, paddingBottom: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4952
4773
|
designSystem.IconButton,
|
|
4953
4774
|
{
|
|
@@ -5490,6 +5311,32 @@ const TabsRoot = styledComponents.styled(designSystem.Tabs.Root)`
|
|
|
5490
5311
|
flex-direction: column;
|
|
5491
5312
|
overflow: hidden;
|
|
5492
5313
|
`;
|
|
5314
|
+
const typeFromMime = (mime) => {
|
|
5315
|
+
if (mime.includes(AssetType.Image)) {
|
|
5316
|
+
return AssetType.Image;
|
|
5317
|
+
}
|
|
5318
|
+
if (mime.includes(AssetType.Video)) {
|
|
5319
|
+
return AssetType.Video;
|
|
5320
|
+
}
|
|
5321
|
+
if (mime.includes(AssetType.Audio)) {
|
|
5322
|
+
return AssetType.Audio;
|
|
5323
|
+
}
|
|
5324
|
+
return AssetType.Document;
|
|
5325
|
+
};
|
|
5326
|
+
const rawFileToAsset = (rawFile, assetSource) => {
|
|
5327
|
+
return {
|
|
5328
|
+
size: rawFile.size / 1e3,
|
|
5329
|
+
createdAt: new Date(rawFile.lastModified).toISOString(),
|
|
5330
|
+
name: rawFile.name,
|
|
5331
|
+
source: assetSource,
|
|
5332
|
+
type: typeFromMime(rawFile.type),
|
|
5333
|
+
url: URL.createObjectURL(rawFile),
|
|
5334
|
+
ext: rawFile.name.split(".").pop(),
|
|
5335
|
+
mime: rawFile.type,
|
|
5336
|
+
rawFile,
|
|
5337
|
+
isLocal: true
|
|
5338
|
+
};
|
|
5339
|
+
};
|
|
5493
5340
|
const Wrapper = styledComponents.styled(designSystem.Flex)`
|
|
5494
5341
|
flex-direction: column;
|
|
5495
5342
|
`;
|
|
@@ -5612,6 +5459,76 @@ FromComputerForm.propTypes = {
|
|
|
5612
5459
|
onAddAssets: PropTypes__default.default.func.isRequired,
|
|
5613
5460
|
trackedLocation: PropTypes__default.default.string
|
|
5614
5461
|
};
|
|
5462
|
+
function getFilenameFromURL(url) {
|
|
5463
|
+
return new URL(url).pathname.split("/").pop();
|
|
5464
|
+
}
|
|
5465
|
+
const urlsToAssets = async (urls) => {
|
|
5466
|
+
const assetPromises = urls.map(
|
|
5467
|
+
(url) => fetch(url).then(async (res) => {
|
|
5468
|
+
const blob = await res.blob();
|
|
5469
|
+
const loadedFile = new File([blob], getFilenameFromURL(res.url), {
|
|
5470
|
+
type: res.headers.get("content-type")
|
|
5471
|
+
});
|
|
5472
|
+
return {
|
|
5473
|
+
name: loadedFile.name,
|
|
5474
|
+
url: res.url,
|
|
5475
|
+
mime: res.headers.get("content-type"),
|
|
5476
|
+
rawFile: loadedFile
|
|
5477
|
+
};
|
|
5478
|
+
})
|
|
5479
|
+
);
|
|
5480
|
+
const assetsResults = await Promise.all(assetPromises);
|
|
5481
|
+
const assets = assetsResults.map((fullFilledAsset) => ({
|
|
5482
|
+
source: AssetSource.Url,
|
|
5483
|
+
name: fullFilledAsset.name,
|
|
5484
|
+
type: typeFromMime(fullFilledAsset.mime),
|
|
5485
|
+
url: fullFilledAsset.url,
|
|
5486
|
+
ext: fullFilledAsset.url.split(".").pop(),
|
|
5487
|
+
mime: fullFilledAsset.mime,
|
|
5488
|
+
rawFile: fullFilledAsset.rawFile
|
|
5489
|
+
}));
|
|
5490
|
+
return assets;
|
|
5491
|
+
};
|
|
5492
|
+
const urlSchema = yup__namespace.object().shape({
|
|
5493
|
+
urls: yup__namespace.string().test({
|
|
5494
|
+
name: "isUrlValid",
|
|
5495
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
5496
|
+
message: "${path}",
|
|
5497
|
+
test(values = "") {
|
|
5498
|
+
const urls = values.split(/\r?\n/);
|
|
5499
|
+
if (urls.length === 0) {
|
|
5500
|
+
return this.createError({
|
|
5501
|
+
path: this.path,
|
|
5502
|
+
message: strapiAdmin.translatedErrors.min.id
|
|
5503
|
+
});
|
|
5504
|
+
}
|
|
5505
|
+
if (urls.length > 20) {
|
|
5506
|
+
return this.createError({
|
|
5507
|
+
path: this.path,
|
|
5508
|
+
message: strapiAdmin.translatedErrors.max.id
|
|
5509
|
+
});
|
|
5510
|
+
}
|
|
5511
|
+
const filtered = urls.filter((val) => {
|
|
5512
|
+
try {
|
|
5513
|
+
new URL(val);
|
|
5514
|
+
return false;
|
|
5515
|
+
} catch (err) {
|
|
5516
|
+
return true;
|
|
5517
|
+
}
|
|
5518
|
+
});
|
|
5519
|
+
const filteredLength = filtered.length;
|
|
5520
|
+
if (filteredLength === 0) {
|
|
5521
|
+
return true;
|
|
5522
|
+
}
|
|
5523
|
+
const errorMessage = filteredLength > 1 ? "form.upload-url.error.url.invalids" : "form.upload-url.error.url.invalid";
|
|
5524
|
+
return this.createError({
|
|
5525
|
+
path: this.path,
|
|
5526
|
+
message: getTrad(errorMessage),
|
|
5527
|
+
params: { number: filtered.length }
|
|
5528
|
+
});
|
|
5529
|
+
}
|
|
5530
|
+
})
|
|
5531
|
+
});
|
|
5615
5532
|
const FromUrlForm = ({ onClose, onAddAsset, trackedLocation }) => {
|
|
5616
5533
|
const [loading, setLoading] = React.useState(false);
|
|
5617
5534
|
const [error, setError] = React.useState(void 0);
|
|
@@ -6644,6 +6561,15 @@ MediaLibraryInput.propTypes = {
|
|
|
6644
6561
|
name: PropTypes__default.default.string.isRequired,
|
|
6645
6562
|
required: PropTypes__default.default.bool
|
|
6646
6563
|
};
|
|
6564
|
+
const prefixPluginTranslations = (trad, pluginId2) => {
|
|
6565
|
+
if (!pluginId2) {
|
|
6566
|
+
throw new TypeError("pluginId can't be empty");
|
|
6567
|
+
}
|
|
6568
|
+
return Object.keys(trad).reduce((acc, current) => {
|
|
6569
|
+
acc[`${pluginId2}.${current}`] = trad[current];
|
|
6570
|
+
return acc;
|
|
6571
|
+
}, {});
|
|
6572
|
+
};
|
|
6647
6573
|
const name = pluginPkg.strapi.name;
|
|
6648
6574
|
const index = {
|
|
6649
6575
|
register(app) {
|
|
@@ -6655,7 +6581,7 @@ const index = {
|
|
|
6655
6581
|
defaultMessage: "Media Library"
|
|
6656
6582
|
},
|
|
6657
6583
|
permissions: PERMISSIONS.main,
|
|
6658
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
6584
|
+
Component: () => Promise.resolve().then(() => require("./index-POwhla6y.js")),
|
|
6659
6585
|
position: 4
|
|
6660
6586
|
});
|
|
6661
6587
|
app.addSettingsLink("global", {
|
|
@@ -6665,7 +6591,7 @@ const index = {
|
|
|
6665
6591
|
defaultMessage: "Media Library"
|
|
6666
6592
|
},
|
|
6667
6593
|
to: "media-library",
|
|
6668
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
6594
|
+
Component: () => Promise.resolve().then(() => require("./index-DPWou2fL.js")),
|
|
6669
6595
|
permissions: PERMISSIONS.settings
|
|
6670
6596
|
});
|
|
6671
6597
|
app.addFields({ type: "media", Component: MediaLibraryInput });
|
|
@@ -6734,4 +6660,4 @@ exports.useMediaLibraryPermissions = useMediaLibraryPermissions;
|
|
|
6734
6660
|
exports.usePersistentState = usePersistentState;
|
|
6735
6661
|
exports.useSelectionState = useSelectionState;
|
|
6736
6662
|
exports.viewOptions = viewOptions;
|
|
6737
|
-
//# sourceMappingURL=index-
|
|
6663
|
+
//# sourceMappingURL=index-4dDBcT2s.js.map
|