@strapi/upload 5.0.5 → 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-C7Nj9ETW.js → index-4dDBcT2s.js} +298 -372
- package/dist/_chunks/index-4dDBcT2s.js.map +1 -0
- package/dist/_chunks/{index-DIjfjBzf.js → index-BWoTIP6T.js} +2 -5
- package/dist/_chunks/index-BWoTIP6T.js.map +1 -0
- package/dist/_chunks/{index-BJfZXhbz.mjs → index-CZ3rXZbR.mjs} +2 -5
- package/dist/_chunks/index-CZ3rXZbR.mjs.map +1 -0
- package/dist/_chunks/{index-moi5JZRr.mjs → index-D0UI77ZE.mjs} +2 -2
- package/dist/_chunks/{index-moi5JZRr.mjs.map → index-D0UI77ZE.mjs.map} +1 -1
- package/dist/_chunks/{index-CuzWuOXx.mjs → index-DKKpjnQN.mjs} +299 -373
- package/dist/_chunks/index-DKKpjnQN.mjs.map +1 -0
- package/dist/_chunks/{index-boOjOtd3.js → index-DPWou2fL.js} +2 -2
- package/dist/_chunks/{index-boOjOtd3.js.map → index-DPWou2fL.js.map} +1 -1
- package/dist/_chunks/{index-Dztfplsk.js → index-POwhla6y.js} +9 -12
- package/dist/_chunks/index-POwhla6y.js.map +1 -0
- package/dist/_chunks/{index-uOSk9F1z.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-BJfZXhbz.mjs.map +0 -1
- package/dist/_chunks/index-C7Nj9ETW.js.map +0 -1
- package/dist/_chunks/index-CuzWuOXx.mjs.map +0 -1
- package/dist/_chunks/index-DIjfjBzf.js.map +0 -1
- package/dist/_chunks/index-Dztfplsk.js.map +0 -1
- package/dist/_chunks/index-uOSk9F1z.mjs.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
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { ChevronUp, ChevronDown, Cross, CaretDown, Link, FilePdf, File as File$1, Check, Trash, Download, Crop, Pencil, Folder, Eye, CaretUp, Plus, Filter, ChevronLeft, ChevronRight, Search, List, GridFour, PlusCircle, Images } from "@strapi/icons";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { useEffect, useState, useMemo, useRef, useCallback, forwardRef, createElement, createContext, useContext, useLayoutEffect } from "react";
|
|
5
5
|
import PropTypes from "prop-types";
|
|
6
|
-
import {
|
|
6
|
+
import { useNotification, useFetchClient, useRBAC, useTracking, ConfirmDialog, useQueryParams, Layouts, Page, translatedErrors, useField } from "@strapi/admin/strapi-admin";
|
|
7
7
|
import { useNotifyAT, Box, Grid, Flex, Typography, Modal, IconButton, ProgressBar, Dialog, Badge, Menu, FocusTrap, Button, VisuallyHidden, Loader, Field, TextInput, CardAction, Card as Card$1, CardHeader, CardCheckbox, CardBody, CardContent, CardTitle, CardSubtitle, CardBadge, CardAsset as CardAsset$2, CardTimer, KeyboardNavigable, CrumbSimpleMenu, MenuItem, Breadcrumbs as Breadcrumbs$1, CrumbLink, Crumb, SingleSelect, SingleSelectOption, Avatar, Tbody, Tr, Td, Checkbox, Table, Thead, Th, Tooltip, Tag, DateTimePicker, Popover, SearchForm, Searchbar, Divider, Tabs, Textarea, CarouselActions, CarouselInput, CarouselSlide } from "@strapi/design-system";
|
|
8
8
|
import { useIntl } from "react-intl";
|
|
9
9
|
import { styled, useTheme } from "styled-components";
|
|
10
10
|
import byteSize from "byte-size";
|
|
11
11
|
import { intervalToDuration } from "date-fns";
|
|
12
12
|
import { stringify } from "qs";
|
|
13
|
-
import * as yup from "yup";
|
|
14
13
|
import { useQuery, useMutation, useQueryClient } from "react-query";
|
|
15
14
|
import { Formik, Form } from "formik";
|
|
16
15
|
import isEqual from "lodash/isEqual";
|
|
16
|
+
import * as yup from "yup";
|
|
17
17
|
import ReactSelect, { components } from "react-select";
|
|
18
18
|
import Cropper from "cropperjs";
|
|
19
19
|
import "cropperjs/dist/cropper.css";
|
|
@@ -32,7 +32,7 @@ const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
const name$1 = "@strapi/upload";
|
|
35
|
-
const version = "5.0.
|
|
35
|
+
const version = "5.0.0";
|
|
36
36
|
const description = "Makes it easy to upload images and files to your Strapi Application.";
|
|
37
37
|
const license = "SEE LICENSE IN LICENSE";
|
|
38
38
|
const author = {
|
|
@@ -119,7 +119,6 @@ const devDependencies = {
|
|
|
119
119
|
"@testing-library/dom": "10.1.0",
|
|
120
120
|
"@testing-library/react": "15.0.7",
|
|
121
121
|
"@testing-library/user-event": "14.5.2",
|
|
122
|
-
"@types/byte-size": "8.1.2",
|
|
123
122
|
"@types/fs-extra": "11.0.4",
|
|
124
123
|
"@types/koa": "2.13.4",
|
|
125
124
|
"@types/koa-range": "0.3.5",
|
|
@@ -141,7 +140,7 @@ const peerDependencies = {
|
|
|
141
140
|
"styled-components": "^6.0.0"
|
|
142
141
|
};
|
|
143
142
|
const engines = {
|
|
144
|
-
node: ">=18.0.0 <=
|
|
143
|
+
node: ">=18.0.0 <=20.x.x",
|
|
145
144
|
npm: ">=6.0.0"
|
|
146
145
|
};
|
|
147
146
|
const strapi = {
|
|
@@ -173,7 +172,7 @@ const appendSearchParamsToUrl = ({ url, params }) => {
|
|
|
173
172
|
}
|
|
174
173
|
const urlObj = new URL(url, window.strapi.backendURL);
|
|
175
174
|
Object.entries(params).forEach(([key, value]) => {
|
|
176
|
-
if (value !== void 0
|
|
175
|
+
if (value !== void 0) {
|
|
177
176
|
urlObj.searchParams.append(key, value);
|
|
178
177
|
}
|
|
179
178
|
});
|
|
@@ -202,43 +201,6 @@ const createAssetUrl = (asset, forThumbnail = true) => {
|
|
|
202
201
|
const assetUrl = forThumbnail ? asset?.formats?.thumbnail?.url || asset.url : asset.url;
|
|
203
202
|
return prefixFileUrlWithBackendUrl(assetUrl);
|
|
204
203
|
};
|
|
205
|
-
const displayedFilters = [
|
|
206
|
-
{
|
|
207
|
-
name: "createdAt",
|
|
208
|
-
fieldSchema: {
|
|
209
|
-
type: "date"
|
|
210
|
-
},
|
|
211
|
-
metadatas: { label: "createdAt" }
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
name: "updatedAt",
|
|
215
|
-
fieldSchema: {
|
|
216
|
-
type: "date"
|
|
217
|
-
},
|
|
218
|
-
metadatas: { label: "updatedAt" }
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
name: "mime",
|
|
222
|
-
fieldSchema: {
|
|
223
|
-
type: "enumeration",
|
|
224
|
-
options: [
|
|
225
|
-
{ label: "audio", value: "audio" },
|
|
226
|
-
{ label: "file", value: "file" },
|
|
227
|
-
{ label: "image", value: "image" },
|
|
228
|
-
{ label: "video", value: "video" }
|
|
229
|
-
]
|
|
230
|
-
},
|
|
231
|
-
metadatas: { label: "type" }
|
|
232
|
-
}
|
|
233
|
-
];
|
|
234
|
-
const downloadFile = async (url, fileName) => {
|
|
235
|
-
const fileBlob = await fetch(url).then((res) => res.blob());
|
|
236
|
-
const urlDownload = window.URL.createObjectURL(fileBlob);
|
|
237
|
-
const link = document.createElement("a");
|
|
238
|
-
link.href = urlDownload;
|
|
239
|
-
link.setAttribute("download", fileName);
|
|
240
|
-
link.click();
|
|
241
|
-
};
|
|
242
204
|
function findRecursiveFolderByValue(data, value) {
|
|
243
205
|
let result;
|
|
244
206
|
function iter(a) {
|
|
@@ -252,8 +214,7 @@ function findRecursiveFolderByValue(data, value) {
|
|
|
252
214
|
return result;
|
|
253
215
|
}
|
|
254
216
|
function formatBytes(receivedBytes, decimals = 0) {
|
|
255
|
-
const
|
|
256
|
-
const { value, unit } = byteSize(realBytes * 1e3, { precision: decimals });
|
|
217
|
+
const { value, unit } = byteSize(receivedBytes * 1e3, { precision: decimals });
|
|
257
218
|
if (!unit) {
|
|
258
219
|
return "0B";
|
|
259
220
|
}
|
|
@@ -264,81 +225,9 @@ const formatDuration = (durationInSecond) => {
|
|
|
264
225
|
const duration = intervalToDuration({ start: 0, end: durationInSecond * 1e3 });
|
|
265
226
|
return `${zeroPad(duration.hours)}:${zeroPad(duration.minutes)}:${zeroPad(duration.seconds)}`;
|
|
266
227
|
};
|
|
267
|
-
const toSingularTypes = (types) => {
|
|
268
|
-
if (!types) {
|
|
269
|
-
return [];
|
|
270
|
-
}
|
|
271
|
-
return types.map((type) => type.substring(0, type.length - 1));
|
|
272
|
-
};
|
|
273
|
-
const getAllowedFiles = (pluralTypes, files2) => {
|
|
274
|
-
const singularTypes = toSingularTypes(pluralTypes);
|
|
275
|
-
const allowedFiles = files2.filter((file) => {
|
|
276
|
-
const fileType = file?.mime?.split("/")[0];
|
|
277
|
-
if (!fileType) {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
if (singularTypes.includes("file") && !["video", "image", "audio"].includes(fileType)) {
|
|
281
|
-
return true;
|
|
282
|
-
}
|
|
283
|
-
return singularTypes.includes(fileType);
|
|
284
|
-
});
|
|
285
|
-
return allowedFiles;
|
|
286
|
-
};
|
|
287
|
-
function getPrefixedId(message, callback) {
|
|
288
|
-
const prefixedMessage = `apiError.${message}`;
|
|
289
|
-
if (typeof callback === "function") {
|
|
290
|
-
return callback(prefixedMessage);
|
|
291
|
-
}
|
|
292
|
-
return prefixedMessage;
|
|
293
|
-
}
|
|
294
|
-
function normalizeError(error, { name: name2, intlMessagePrefixCallback }) {
|
|
295
|
-
const { message } = error;
|
|
296
|
-
const normalizedError = {
|
|
297
|
-
id: getPrefixedId(message, intlMessagePrefixCallback),
|
|
298
|
-
defaultMessage: message,
|
|
299
|
-
name: error.name ?? name2,
|
|
300
|
-
values: {}
|
|
301
|
-
};
|
|
302
|
-
if ("path" in error) {
|
|
303
|
-
normalizedError.values = { path: error.path.join(".") };
|
|
304
|
-
}
|
|
305
|
-
return normalizedError;
|
|
306
|
-
}
|
|
307
|
-
const validateErrorIsYupValidationError = (err) => typeof err.details === "object" && err.details !== null && "errors" in err.details;
|
|
308
|
-
function normalizeAPIError(apiError, intlMessagePrefixCallback) {
|
|
309
|
-
const error = apiError.response?.data.error;
|
|
310
|
-
if (error) {
|
|
311
|
-
if (validateErrorIsYupValidationError(error)) {
|
|
312
|
-
return {
|
|
313
|
-
name: error.name,
|
|
314
|
-
message: error?.message || null,
|
|
315
|
-
errors: error.details.errors.map(
|
|
316
|
-
(err) => normalizeError(err, { name: error.name, intlMessagePrefixCallback })
|
|
317
|
-
)
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
return normalizeError(error, { intlMessagePrefixCallback });
|
|
321
|
-
}
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
function getAPIInnerErrors(error, { getTrad: getTrad2 }) {
|
|
325
|
-
const normalizedError = normalizeAPIError(error, getTrad2);
|
|
326
|
-
if (normalizedError && "errors" in normalizedError) {
|
|
327
|
-
return normalizedError.errors.reduce((acc, error2) => {
|
|
328
|
-
if ("path" in error2.values) {
|
|
329
|
-
acc[error2.values.path] = {
|
|
330
|
-
id: error2.id,
|
|
331
|
-
defaultMessage: error2.defaultMessage
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
return acc;
|
|
335
|
-
}, {});
|
|
336
|
-
}
|
|
337
|
-
return normalizedError?.defaultMessage;
|
|
338
|
-
}
|
|
339
228
|
const pluginId = pluginPkg.name.replace(/^@strapi\//i, "");
|
|
340
229
|
const getTrad = (id2) => `${pluginId}.${id2}`;
|
|
341
|
-
const
|
|
230
|
+
const getBreadcrumbDataML = (folder) => {
|
|
342
231
|
let data = [
|
|
343
232
|
{
|
|
344
233
|
id: null,
|
|
@@ -376,8 +265,7 @@ const getFolderURL = (pathname, currentQuery, { folder, folderPath } = {}) => {
|
|
|
376
265
|
);
|
|
377
266
|
return `${pathname}${queryParamsString ? `?${queryParamsString}` : ""}`;
|
|
378
267
|
};
|
|
379
|
-
|
|
380
|
-
function flattenTree(tree, parent = null, depth = 0) {
|
|
268
|
+
function flattenTree(tree, parent, depth = 0) {
|
|
381
269
|
return tree.flatMap(
|
|
382
270
|
(item) => item.children ? [{ ...item, parent: parent?.value, depth }, ...flattenTree(item.children, item, depth + 1)] : { ...item, depth, parent: parent?.value }
|
|
383
271
|
);
|
|
@@ -392,178 +280,70 @@ const getFolderParents = (folders, currentFolderId) => {
|
|
|
392
280
|
let { parent } = currentFolder;
|
|
393
281
|
while (parent !== void 0) {
|
|
394
282
|
let parentToStore = flatFolders.find(({ value }) => value === parent);
|
|
395
|
-
parents.push({ id: parentToStore
|
|
396
|
-
parent = parentToStore
|
|
283
|
+
parents.push({ id: parentToStore.value, label: parentToStore.label });
|
|
284
|
+
parent = parentToStore.parent;
|
|
397
285
|
}
|
|
398
286
|
return parents.reverse();
|
|
399
287
|
};
|
|
400
|
-
const
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
405
|
-
return array;
|
|
406
|
-
};
|
|
407
|
-
const moveElement = (array, index2, offset) => {
|
|
408
|
-
const newIndex = index2 + offset;
|
|
409
|
-
return move(array, index2, newIndex);
|
|
410
|
-
};
|
|
411
|
-
const prefixPluginTranslations = (trad, pluginId2) => {
|
|
412
|
-
if (!pluginId2) {
|
|
413
|
-
throw new TypeError("pluginId can't be empty");
|
|
288
|
+
const toSingularTypes = (types) => {
|
|
289
|
+
if (!types) {
|
|
290
|
+
return [];
|
|
414
291
|
}
|
|
415
|
-
return
|
|
416
|
-
acc[`${pluginId2}.${current}`] = trad[current];
|
|
417
|
-
return acc;
|
|
418
|
-
}, {});
|
|
419
|
-
};
|
|
420
|
-
var AssetType$1 = /* @__PURE__ */ ((AssetType2) => {
|
|
421
|
-
AssetType2["Video"] = "video";
|
|
422
|
-
AssetType2["Image"] = "image";
|
|
423
|
-
AssetType2["Document"] = "doc";
|
|
424
|
-
AssetType2["Audio"] = "audio";
|
|
425
|
-
return AssetType2;
|
|
426
|
-
})(AssetType$1 || {});
|
|
427
|
-
var AssetSource$1 = /* @__PURE__ */ ((AssetSource2) => {
|
|
428
|
-
AssetSource2["Url"] = "url";
|
|
429
|
-
AssetSource2["Computer"] = "computer";
|
|
430
|
-
return AssetSource2;
|
|
431
|
-
})(AssetSource$1 || {});
|
|
432
|
-
const PERMISSIONS$1 = {
|
|
433
|
-
// This permission regards the main component (App) and is used to tell
|
|
434
|
-
// If the plugin link should be displayed in the menu
|
|
435
|
-
// And also if the plugin is accessible. This use case is found when a user types the url of the
|
|
436
|
-
// plugin directly in the browser
|
|
437
|
-
main: [
|
|
438
|
-
{ action: "plugin::upload.read", subject: null },
|
|
439
|
-
{
|
|
440
|
-
action: "plugin::upload.assets.create",
|
|
441
|
-
subject: null
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
action: "plugin::upload.assets.update",
|
|
445
|
-
subject: null
|
|
446
|
-
}
|
|
447
|
-
],
|
|
448
|
-
copyLink: [
|
|
449
|
-
{
|
|
450
|
-
action: "plugin::upload.assets.copy-link",
|
|
451
|
-
subject: null
|
|
452
|
-
}
|
|
453
|
-
],
|
|
454
|
-
create: [
|
|
455
|
-
{
|
|
456
|
-
action: "plugin::upload.assets.create",
|
|
457
|
-
subject: null
|
|
458
|
-
}
|
|
459
|
-
],
|
|
460
|
-
download: [
|
|
461
|
-
{
|
|
462
|
-
action: "plugin::upload.assets.download",
|
|
463
|
-
subject: null
|
|
464
|
-
}
|
|
465
|
-
],
|
|
466
|
-
read: [{ action: "plugin::upload.read", subject: null }],
|
|
467
|
-
configureView: [{ action: "plugin::upload.configure-view", subject: null }],
|
|
468
|
-
settings: [{ action: "plugin::upload.settings.read", subject: null }],
|
|
469
|
-
update: [{ action: "plugin::upload.assets.update", subject: null, fields: null }]
|
|
292
|
+
return types.map((type) => type.substring(0, type.length - 1));
|
|
470
293
|
};
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
return AssetType$1.Video;
|
|
477
|
-
}
|
|
478
|
-
if (mime.includes(AssetType$1.Audio)) {
|
|
479
|
-
return AssetType$1.Audio;
|
|
294
|
+
const getFileExtension = (ext) => ext && ext[0] === "." ? ext.substring(1) : ext;
|
|
295
|
+
function getPrefixedId(message, callback) {
|
|
296
|
+
const prefixedMessage = `apiError.${message}`;
|
|
297
|
+
if (typeof callback === "function") {
|
|
298
|
+
return callback(prefixedMessage);
|
|
480
299
|
}
|
|
481
|
-
return
|
|
482
|
-
};
|
|
483
|
-
const rawFileToAsset = (rawFile, assetSource) => {
|
|
484
|
-
return {
|
|
485
|
-
size: rawFile.size / 1e3,
|
|
486
|
-
createdAt: new Date(rawFile.lastModified).toISOString(),
|
|
487
|
-
name: rawFile.name,
|
|
488
|
-
source: assetSource,
|
|
489
|
-
type: typeFromMime(rawFile.type),
|
|
490
|
-
url: URL.createObjectURL(rawFile),
|
|
491
|
-
ext: rawFile.name.split(".").pop(),
|
|
492
|
-
mime: rawFile.type,
|
|
493
|
-
rawFile,
|
|
494
|
-
isLocal: true
|
|
495
|
-
};
|
|
496
|
-
};
|
|
497
|
-
function getFilenameFromURL(url) {
|
|
498
|
-
return new URL(url).pathname.split("/").pop();
|
|
300
|
+
return prefixedMessage;
|
|
499
301
|
}
|
|
500
|
-
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return assets;
|
|
526
|
-
};
|
|
527
|
-
const urlSchema = yup.object().shape({
|
|
528
|
-
urls: yup.string().test({
|
|
529
|
-
name: "isUrlValid",
|
|
530
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
531
|
-
message: "${path}",
|
|
532
|
-
test(values = "") {
|
|
533
|
-
const urls = values.split(/\r?\n/);
|
|
534
|
-
if (urls.length === 0) {
|
|
535
|
-
return this.createError({
|
|
536
|
-
path: this.path,
|
|
537
|
-
message: translatedErrors.min.id
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
if (urls.length > 20) {
|
|
541
|
-
return this.createError({
|
|
542
|
-
path: this.path,
|
|
543
|
-
message: translatedErrors.max.id
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
const filtered = urls.filter((val) => {
|
|
547
|
-
try {
|
|
548
|
-
new URL(val);
|
|
549
|
-
return false;
|
|
550
|
-
} catch (err) {
|
|
551
|
-
return true;
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
const filteredLength = filtered.length;
|
|
555
|
-
if (filteredLength === 0) {
|
|
556
|
-
return true;
|
|
557
|
-
}
|
|
558
|
-
const errorMessage = filteredLength > 1 ? "form.upload-url.error.url.invalids" : "form.upload-url.error.url.invalid";
|
|
559
|
-
return this.createError({
|
|
560
|
-
path: this.path,
|
|
561
|
-
message: getTrad(errorMessage),
|
|
562
|
-
params: { number: filtered.length }
|
|
563
|
-
});
|
|
302
|
+
function normalizeError(error, { name: name2, intlMessagePrefixCallback }) {
|
|
303
|
+
const { message } = error;
|
|
304
|
+
const normalizedError = {
|
|
305
|
+
id: getPrefixedId(message, intlMessagePrefixCallback),
|
|
306
|
+
defaultMessage: message,
|
|
307
|
+
name: error.name ?? name2,
|
|
308
|
+
values: {}
|
|
309
|
+
};
|
|
310
|
+
if ("path" in error) {
|
|
311
|
+
normalizedError.values = { path: error.path.join(".") };
|
|
312
|
+
}
|
|
313
|
+
return normalizedError;
|
|
314
|
+
}
|
|
315
|
+
const validateErrorIsYupValidationError = (err) => typeof err.details === "object" && err.details !== null && "errors" in err.details;
|
|
316
|
+
function normalizeAPIError(apiError, intlMessagePrefixCallback) {
|
|
317
|
+
const error = apiError.response?.data.error;
|
|
318
|
+
if (error) {
|
|
319
|
+
if (validateErrorIsYupValidationError(error)) {
|
|
320
|
+
return {
|
|
321
|
+
name: error.name,
|
|
322
|
+
message: error?.message || null,
|
|
323
|
+
errors: error.details.errors.map(
|
|
324
|
+
(err) => normalizeError(err, { name: error.name, intlMessagePrefixCallback })
|
|
325
|
+
)
|
|
326
|
+
};
|
|
564
327
|
}
|
|
565
|
-
|
|
566
|
-
}
|
|
328
|
+
return normalizeError(error, { intlMessagePrefixCallback });
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function getAPIInnerErrors(error, { getTrad: getTrad2 }) {
|
|
333
|
+
const normalizedError = normalizeAPIError(error, getTrad2);
|
|
334
|
+
if (normalizedError && "errors" in normalizedError) {
|
|
335
|
+
return normalizedError.errors.reduce((acc, error2) => {
|
|
336
|
+
if ("path" in error2.values) {
|
|
337
|
+
acc[error2.values.path] = {
|
|
338
|
+
id: error2.id,
|
|
339
|
+
defaultMessage: error2.defaultMessage
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return acc;
|
|
343
|
+
}, {});
|
|
344
|
+
}
|
|
345
|
+
return normalizedError?.defaultMessage;
|
|
346
|
+
}
|
|
567
347
|
const AssetType = {
|
|
568
348
|
Video: "video",
|
|
569
349
|
Image: "image",
|
|
@@ -812,7 +592,7 @@ const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
|
|
812
592
|
}
|
|
813
593
|
}
|
|
814
594
|
);
|
|
815
|
-
|
|
595
|
+
useEffect(() => {
|
|
816
596
|
if (data) {
|
|
817
597
|
notifyStatus(
|
|
818
598
|
formatMessage({
|
|
@@ -822,7 +602,7 @@ const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
|
|
822
602
|
);
|
|
823
603
|
}
|
|
824
604
|
}, [data, formatMessage, notifyStatus]);
|
|
825
|
-
|
|
605
|
+
useEffect(() => {
|
|
826
606
|
if (error) {
|
|
827
607
|
toggleNotification({
|
|
828
608
|
type: "danger",
|
|
@@ -899,7 +679,7 @@ const useFolders = ({ enabled = true, query = {} } = {}) => {
|
|
|
899
679
|
}, [data, formatMessage, notifyStatus]);
|
|
900
680
|
return { data, error, isLoading };
|
|
901
681
|
};
|
|
902
|
-
const { main, ...restPermissions } = PERMISSIONS
|
|
682
|
+
const { main, ...restPermissions } = PERMISSIONS;
|
|
903
683
|
const useMediaLibraryPermissions = () => {
|
|
904
684
|
const { allowedActions, isLoading } = useRBAC(restPermissions);
|
|
905
685
|
return { ...allowedActions, isLoading };
|
|
@@ -927,7 +707,7 @@ const useConfig = () => {
|
|
|
927
707
|
/**
|
|
928
708
|
* We're cementing that we always expect an object to be returned.
|
|
929
709
|
*/
|
|
930
|
-
select: (data) => data
|
|
710
|
+
select: (data) => !data ? {} : data
|
|
931
711
|
}
|
|
932
712
|
);
|
|
933
713
|
const putMutation = useMutation(
|
|
@@ -957,7 +737,7 @@ const useModalQueryParams = (initialState) => {
|
|
|
957
737
|
const {
|
|
958
738
|
config: { data: config }
|
|
959
739
|
} = useConfig();
|
|
960
|
-
const [queryObject, setQueryObject] =
|
|
740
|
+
const [queryObject, setQueryObject] = useState({
|
|
961
741
|
page: 1,
|
|
962
742
|
sort: "updatedAt:DESC",
|
|
963
743
|
pageSize: 10,
|
|
@@ -966,8 +746,8 @@ const useModalQueryParams = (initialState) => {
|
|
|
966
746
|
},
|
|
967
747
|
...initialState
|
|
968
748
|
});
|
|
969
|
-
|
|
970
|
-
if (config
|
|
749
|
+
useEffect(() => {
|
|
750
|
+
if (config) {
|
|
971
751
|
setQueryObject((prevQuery) => ({
|
|
972
752
|
...prevQuery,
|
|
973
753
|
sort: config.sort,
|
|
@@ -976,32 +756,24 @@ const useModalQueryParams = (initialState) => {
|
|
|
976
756
|
}
|
|
977
757
|
}, [config]);
|
|
978
758
|
const handleChangeFilters = (nextFilters) => {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
setQueryObject((prev) => ({ ...prev, page: 1, filters: { $and: nextFilters } }));
|
|
985
|
-
}
|
|
759
|
+
trackUsage("didFilterMediaLibraryElements", {
|
|
760
|
+
location: "content-manager",
|
|
761
|
+
filter: Object.keys(nextFilters[nextFilters.length - 1])[0]
|
|
762
|
+
});
|
|
763
|
+
setQueryObject((prev) => ({ ...prev, page: 1, filters: { $and: nextFilters } }));
|
|
986
764
|
};
|
|
987
765
|
const handleChangePageSize = (pageSize) => {
|
|
988
|
-
setQueryObject((prev) => ({
|
|
989
|
-
...prev,
|
|
990
|
-
pageSize: typeof pageSize === "string" ? parseInt(pageSize, 10) : pageSize,
|
|
991
|
-
page: 1
|
|
992
|
-
}));
|
|
766
|
+
setQueryObject((prev) => ({ ...prev, pageSize: parseInt(pageSize, 10), page: 1 }));
|
|
993
767
|
};
|
|
994
768
|
const handeChangePage = (page) => {
|
|
995
769
|
setQueryObject((prev) => ({ ...prev, page }));
|
|
996
770
|
};
|
|
997
771
|
const handleChangeSort = (sort) => {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
setQueryObject((prev) => ({ ...prev, sort }));
|
|
1004
|
-
}
|
|
772
|
+
trackUsage("didSortMediaLibraryElements", {
|
|
773
|
+
location: "content-manager",
|
|
774
|
+
sort
|
|
775
|
+
});
|
|
776
|
+
setQueryObject((prev) => ({ ...prev, sort }));
|
|
1005
777
|
};
|
|
1006
778
|
const handleChangeSearch = (_q) => {
|
|
1007
779
|
if (_q) {
|
|
@@ -1090,6 +862,28 @@ const useSelectionState = (keys, initialValue) => {
|
|
|
1090
862
|
{ selectOne, selectAll, selectOnly, selectMultiple, deselectMultiple, setSelections }
|
|
1091
863
|
];
|
|
1092
864
|
};
|
|
865
|
+
const getAllowedFiles = (pluralTypes, files2) => {
|
|
866
|
+
const singularTypes = toSingularTypes(pluralTypes);
|
|
867
|
+
const allowedFiles = files2.filter((file) => {
|
|
868
|
+
const fileType = file.mime.split("/")[0];
|
|
869
|
+
if (singularTypes.includes("file") && !["video", "image", "audio"].includes(fileType)) {
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
return singularTypes.includes(fileType);
|
|
873
|
+
});
|
|
874
|
+
return allowedFiles;
|
|
875
|
+
};
|
|
876
|
+
const move = (array, oldIndex, newIndex) => {
|
|
877
|
+
if (newIndex >= array.length) {
|
|
878
|
+
newIndex = array.length - 1;
|
|
879
|
+
}
|
|
880
|
+
array.splice(newIndex, 0, array.splice(oldIndex, 1)[0]);
|
|
881
|
+
return array;
|
|
882
|
+
};
|
|
883
|
+
const moveElement = (array, index2, offset) => {
|
|
884
|
+
const newIndex = index2 + offset;
|
|
885
|
+
return move(array, index2, newIndex);
|
|
886
|
+
};
|
|
1093
887
|
const editAssetRequest = (asset, file, signal, onProgress, post) => {
|
|
1094
888
|
const endpoint2 = `/${pluginId}?id=${asset.id}`;
|
|
1095
889
|
const formData = new FormData();
|
|
@@ -1110,30 +904,33 @@ const editAssetRequest = (asset, file, signal, onProgress, post) => {
|
|
|
1110
904
|
}).then((res) => res.data);
|
|
1111
905
|
};
|
|
1112
906
|
const useEditAsset = () => {
|
|
1113
|
-
const [progress, setProgress] =
|
|
907
|
+
const [progress, setProgress] = useState(0);
|
|
1114
908
|
const { formatMessage } = useIntl();
|
|
1115
909
|
const { toggleNotification } = useNotification();
|
|
1116
910
|
const queryClient = useQueryClient();
|
|
1117
911
|
const abortController = new AbortController();
|
|
1118
912
|
const signal = abortController.signal;
|
|
1119
913
|
const { post } = useFetchClient();
|
|
1120
|
-
const mutation = useMutation(
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
914
|
+
const mutation = useMutation(
|
|
915
|
+
({ asset, file }) => editAssetRequest(asset, file, signal, setProgress, post),
|
|
916
|
+
{
|
|
917
|
+
onSuccess() {
|
|
918
|
+
queryClient.refetchQueries([pluginId, "assets"], { active: true });
|
|
919
|
+
queryClient.refetchQueries([pluginId, "asset-count"], { active: true });
|
|
920
|
+
queryClient.refetchQueries([pluginId, "folders"], { active: true });
|
|
921
|
+
},
|
|
922
|
+
onError(reason) {
|
|
923
|
+
if (reason.response.status === 403) {
|
|
924
|
+
toggleNotification({
|
|
925
|
+
type: "info",
|
|
926
|
+
message: formatMessage({ id: getTrad("permissions.not-allowed.update") })
|
|
927
|
+
});
|
|
928
|
+
} else {
|
|
929
|
+
toggleNotification({ type: "danger", message: reason.message });
|
|
930
|
+
}
|
|
1134
931
|
}
|
|
1135
932
|
}
|
|
1136
|
-
|
|
933
|
+
);
|
|
1137
934
|
const editAsset = (asset, file) => mutation.mutateAsync({ asset, file });
|
|
1138
935
|
const cancel = () => abortController.abort();
|
|
1139
936
|
return { ...mutation, cancel, editAsset, progress, status: mutation.status };
|
|
@@ -1155,9 +952,7 @@ const useFolderStructure = ({ enabled = true } = {}) => {
|
|
|
1155
952
|
const {
|
|
1156
953
|
data: { data: data2 }
|
|
1157
954
|
} = await get("/upload/folder-structure");
|
|
1158
|
-
const children = data2.map(
|
|
1159
|
-
(f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key)
|
|
1160
|
-
);
|
|
955
|
+
const children = data2.map((f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key));
|
|
1161
956
|
return [
|
|
1162
957
|
{
|
|
1163
958
|
value: null,
|
|
@@ -1527,10 +1322,10 @@ const DialogHeader = () => {
|
|
|
1527
1322
|
};
|
|
1528
1323
|
const QUALITY = 1;
|
|
1529
1324
|
const useCropImg = () => {
|
|
1530
|
-
const cropperRef =
|
|
1531
|
-
const [isCropping, setIsCropping] =
|
|
1532
|
-
const [size, setSize] =
|
|
1533
|
-
|
|
1325
|
+
const cropperRef = useRef();
|
|
1326
|
+
const [isCropping, setIsCropping] = useState(false);
|
|
1327
|
+
const [size, setSize] = useState({ width: void 0, height: void 0 });
|
|
1328
|
+
useEffect(() => {
|
|
1534
1329
|
return () => {
|
|
1535
1330
|
if (cropperRef.current) {
|
|
1536
1331
|
cropperRef.current.destroy();
|
|
@@ -1577,7 +1372,7 @@ const useCropImg = () => {
|
|
|
1577
1372
|
resolve(
|
|
1578
1373
|
new File([blob], name2, {
|
|
1579
1374
|
type: mimeType,
|
|
1580
|
-
|
|
1375
|
+
lastModifiedDate
|
|
1581
1376
|
})
|
|
1582
1377
|
);
|
|
1583
1378
|
},
|
|
@@ -1614,7 +1409,7 @@ const uploadAsset = (asset, folderId, signal, onProgress, post) => {
|
|
|
1614
1409
|
}).then((res) => res.data);
|
|
1615
1410
|
};
|
|
1616
1411
|
const useUpload = () => {
|
|
1617
|
-
const [progress, setProgress] =
|
|
1412
|
+
const [progress, setProgress] = useState(0);
|
|
1618
1413
|
const queryClient = useQueryClient();
|
|
1619
1414
|
const abortController = new AbortController();
|
|
1620
1415
|
const signal = abortController.signal;
|
|
@@ -1640,6 +1435,14 @@ const useUpload = () => {
|
|
|
1640
1435
|
status: mutation.status
|
|
1641
1436
|
};
|
|
1642
1437
|
};
|
|
1438
|
+
const downloadFile = async (url, fileName) => {
|
|
1439
|
+
const fileBlob = await fetch(url).then((res) => res.blob());
|
|
1440
|
+
const urlDownload = window.URL.createObjectURL(fileBlob);
|
|
1441
|
+
const link = document.createElement("a");
|
|
1442
|
+
link.href = urlDownload;
|
|
1443
|
+
link.setAttribute("download", fileName);
|
|
1444
|
+
link.click();
|
|
1445
|
+
};
|
|
1643
1446
|
const useClipboard = () => {
|
|
1644
1447
|
const copy = useCallback(async (value) => {
|
|
1645
1448
|
try {
|
|
@@ -1751,26 +1554,23 @@ const useRemoveAsset = (onSuccess) => {
|
|
|
1751
1554
|
const { formatMessage } = useIntl();
|
|
1752
1555
|
const queryClient = useQueryClient();
|
|
1753
1556
|
const { del } = useFetchClient();
|
|
1754
|
-
const mutation = useMutation(
|
|
1755
|
-
(
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
}
|
|
1769
|
-
onError(error) {
|
|
1770
|
-
toggleNotification({ type: "danger", message: error.message });
|
|
1771
|
-
}
|
|
1557
|
+
const mutation = useMutation((assetId) => del(`/upload/files/${assetId}`), {
|
|
1558
|
+
onSuccess() {
|
|
1559
|
+
queryClient.refetchQueries([pluginId, "assets"], { active: true });
|
|
1560
|
+
queryClient.refetchQueries([pluginId, "asset-count"], { active: true });
|
|
1561
|
+
toggleNotification({
|
|
1562
|
+
type: "success",
|
|
1563
|
+
message: formatMessage({
|
|
1564
|
+
id: "modal.remove.success-label",
|
|
1565
|
+
defaultMessage: "Elements have been successfully deleted."
|
|
1566
|
+
})
|
|
1567
|
+
});
|
|
1568
|
+
onSuccess();
|
|
1569
|
+
},
|
|
1570
|
+
onError(error) {
|
|
1571
|
+
toggleNotification({ type: "danger", message: error.message });
|
|
1772
1572
|
}
|
|
1773
|
-
);
|
|
1573
|
+
});
|
|
1774
1574
|
const removeAsset = async (assetId) => {
|
|
1775
1575
|
await mutation.mutateAsync(assetId);
|
|
1776
1576
|
};
|
|
@@ -2565,7 +2365,7 @@ const useBulkRemove = () => {
|
|
|
2565
2365
|
});
|
|
2566
2366
|
},
|
|
2567
2367
|
onError(error) {
|
|
2568
|
-
toggleNotification({ type: "danger", message: error
|
|
2368
|
+
toggleNotification({ type: "danger", message: error.message });
|
|
2569
2369
|
}
|
|
2570
2370
|
});
|
|
2571
2371
|
const remove = (...args) => mutation.mutateAsync(...args);
|
|
@@ -4009,6 +3809,35 @@ TableList.propTypes = {
|
|
|
4009
3809
|
shouldDisableBulkSelect: PropTypes.bool,
|
|
4010
3810
|
sortQuery: PropTypes.string
|
|
4011
3811
|
};
|
|
3812
|
+
const displayedFilters = [
|
|
3813
|
+
{
|
|
3814
|
+
name: "createdAt",
|
|
3815
|
+
fieldSchema: {
|
|
3816
|
+
type: "date"
|
|
3817
|
+
},
|
|
3818
|
+
metadatas: { label: "createdAt" }
|
|
3819
|
+
},
|
|
3820
|
+
{
|
|
3821
|
+
name: "updatedAt",
|
|
3822
|
+
fieldSchema: {
|
|
3823
|
+
type: "date"
|
|
3824
|
+
},
|
|
3825
|
+
metadatas: { label: "updatedAt" }
|
|
3826
|
+
},
|
|
3827
|
+
{
|
|
3828
|
+
name: "mime",
|
|
3829
|
+
fieldSchema: {
|
|
3830
|
+
type: "enumeration",
|
|
3831
|
+
options: [
|
|
3832
|
+
{ label: "audio", value: "audio" },
|
|
3833
|
+
{ label: "file", value: "file" },
|
|
3834
|
+
{ label: "image", value: "image" },
|
|
3835
|
+
{ label: "video", value: "video" }
|
|
3836
|
+
]
|
|
3837
|
+
},
|
|
3838
|
+
metadatas: { label: "type" }
|
|
3839
|
+
}
|
|
3840
|
+
];
|
|
4012
3841
|
const FilterTag = ({ attribute, filter, onClick, operator, value }) => {
|
|
4013
3842
|
const { formatMessage, formatDate, formatTime } = useIntl();
|
|
4014
3843
|
const handleClick = () => {
|
|
@@ -4055,7 +3884,7 @@ const FilterList = ({ appliedFilters, filtersSchema, onRemoveFilter }) => {
|
|
|
4055
3884
|
const nextFilters = appliedFilters.filter((prevFilter) => {
|
|
4056
3885
|
const name2 = Object.keys(filter)[0];
|
|
4057
3886
|
const filterType = Object.keys(filter[name2])[0];
|
|
4058
|
-
const value =
|
|
3887
|
+
const value = filter[name2][filterType];
|
|
4059
3888
|
return prevFilter[name2]?.[filterType] !== value;
|
|
4060
3889
|
});
|
|
4061
3890
|
onRemoveFilter(nextFilters);
|
|
@@ -4066,13 +3895,6 @@ const FilterList = ({ appliedFilters, filtersSchema, onRemoveFilter }) => {
|
|
|
4066
3895
|
const filterObj = filter[attributeName];
|
|
4067
3896
|
const operator = Object.keys(filterObj)[0];
|
|
4068
3897
|
let value = filterObj[operator];
|
|
4069
|
-
if (Array.isArray(value)) {
|
|
4070
|
-
value = value.join(", ");
|
|
4071
|
-
} else if (typeof value === "object") {
|
|
4072
|
-
value = Object.values(value).join(", ");
|
|
4073
|
-
} else {
|
|
4074
|
-
value = Array.isArray(value) || typeof value === "object" ? Object.values(value).join(", ") : decodeURIComponent(value);
|
|
4075
|
-
}
|
|
4076
3898
|
let displayedOperator = operator;
|
|
4077
3899
|
if (attribute.name === "mime") {
|
|
4078
3900
|
displayedOperator = operator === "$contains" ? "$eq" : "$ne";
|
|
@@ -4280,8 +4102,7 @@ const FilterPopover = ({ displayedFilters: displayedFilters2, filters, onSubmit,
|
|
|
4280
4102
|
const handleSubmit = (e) => {
|
|
4281
4103
|
e.preventDefault();
|
|
4282
4104
|
e.stopPropagation();
|
|
4283
|
-
|
|
4284
|
-
if (encodedValue) {
|
|
4105
|
+
if (modifiedData.value) {
|
|
4285
4106
|
if (modifiedData.name === "mime") {
|
|
4286
4107
|
const alreadyAppliedFilters = filters.filter((filter) => {
|
|
4287
4108
|
return Object.keys(filter)[0] === "mime";
|
|
@@ -4363,10 +4184,10 @@ const FilterPopover = ({ displayedFilters: displayedFilters2, filters, onSubmit,
|
|
|
4363
4184
|
return;
|
|
4364
4185
|
}
|
|
4365
4186
|
const hasFilter = filters.find((filter) => {
|
|
4366
|
-
return filter[modifiedData.name] && filter[modifiedData.name]?.[modifiedData.filter] ===
|
|
4187
|
+
return filter[modifiedData.name] && filter[modifiedData.name]?.[modifiedData.filter] === modifiedData.value;
|
|
4367
4188
|
}) !== void 0;
|
|
4368
4189
|
if (!hasFilter) {
|
|
4369
|
-
let filterToAdd = { [modifiedData.name]: { [modifiedData.filter]:
|
|
4190
|
+
let filterToAdd = { [modifiedData.name]: { [modifiedData.filter]: modifiedData.value } };
|
|
4370
4191
|
const nextFilters = [...filters, filterToAdd];
|
|
4371
4192
|
onSubmit(nextFilters);
|
|
4372
4193
|
}
|
|
@@ -4868,7 +4689,7 @@ const BrowseStep = ({
|
|
|
4868
4689
|
isSelectable: isSelectable(singularTypes, asset?.mime),
|
|
4869
4690
|
type: "asset"
|
|
4870
4691
|
}));
|
|
4871
|
-
const breadcrumbs = !isCurrentFolderLoading &&
|
|
4692
|
+
const breadcrumbs = !isCurrentFolderLoading && getBreadcrumbDataML(currentFolder);
|
|
4872
4693
|
const allAllowedAsset = getAllowedFiles(allowedTypes, assets);
|
|
4873
4694
|
const areAllAssetSelected = allAllowedAsset.length > 0 && selectedAssets.length > 0 && allAllowedAsset.every(
|
|
4874
4695
|
(asset) => selectedAssets.findIndex((currAsset) => currAsset.id === asset.id) !== -1
|
|
@@ -4919,7 +4740,7 @@ const BrowseStep = ({
|
|
|
4919
4740
|
}
|
|
4920
4741
|
)
|
|
4921
4742
|
] }),
|
|
4922
|
-
(assetCount > 0 || folderCount > 0 || isSearching) && /* @__PURE__ */ jsxs(Flex, { marginLeft: "auto", shrink: 0,
|
|
4743
|
+
(assetCount > 0 || folderCount > 0 || isSearching) && /* @__PURE__ */ jsxs(Flex, { marginLeft: "auto", shrink: 0, children: [
|
|
4923
4744
|
/* @__PURE__ */ jsx(ActionContainer, { paddingTop: 1, paddingBottom: 1, children: /* @__PURE__ */ jsx(
|
|
4924
4745
|
IconButton,
|
|
4925
4746
|
{
|
|
@@ -5462,6 +5283,32 @@ const TabsRoot = styled(Tabs.Root)`
|
|
|
5462
5283
|
flex-direction: column;
|
|
5463
5284
|
overflow: hidden;
|
|
5464
5285
|
`;
|
|
5286
|
+
const typeFromMime = (mime) => {
|
|
5287
|
+
if (mime.includes(AssetType.Image)) {
|
|
5288
|
+
return AssetType.Image;
|
|
5289
|
+
}
|
|
5290
|
+
if (mime.includes(AssetType.Video)) {
|
|
5291
|
+
return AssetType.Video;
|
|
5292
|
+
}
|
|
5293
|
+
if (mime.includes(AssetType.Audio)) {
|
|
5294
|
+
return AssetType.Audio;
|
|
5295
|
+
}
|
|
5296
|
+
return AssetType.Document;
|
|
5297
|
+
};
|
|
5298
|
+
const rawFileToAsset = (rawFile, assetSource) => {
|
|
5299
|
+
return {
|
|
5300
|
+
size: rawFile.size / 1e3,
|
|
5301
|
+
createdAt: new Date(rawFile.lastModified).toISOString(),
|
|
5302
|
+
name: rawFile.name,
|
|
5303
|
+
source: assetSource,
|
|
5304
|
+
type: typeFromMime(rawFile.type),
|
|
5305
|
+
url: URL.createObjectURL(rawFile),
|
|
5306
|
+
ext: rawFile.name.split(".").pop(),
|
|
5307
|
+
mime: rawFile.type,
|
|
5308
|
+
rawFile,
|
|
5309
|
+
isLocal: true
|
|
5310
|
+
};
|
|
5311
|
+
};
|
|
5465
5312
|
const Wrapper = styled(Flex)`
|
|
5466
5313
|
flex-direction: column;
|
|
5467
5314
|
`;
|
|
@@ -5584,6 +5431,76 @@ FromComputerForm.propTypes = {
|
|
|
5584
5431
|
onAddAssets: PropTypes.func.isRequired,
|
|
5585
5432
|
trackedLocation: PropTypes.string
|
|
5586
5433
|
};
|
|
5434
|
+
function getFilenameFromURL(url) {
|
|
5435
|
+
return new URL(url).pathname.split("/").pop();
|
|
5436
|
+
}
|
|
5437
|
+
const urlsToAssets = async (urls) => {
|
|
5438
|
+
const assetPromises = urls.map(
|
|
5439
|
+
(url) => fetch(url).then(async (res) => {
|
|
5440
|
+
const blob = await res.blob();
|
|
5441
|
+
const loadedFile = new File([blob], getFilenameFromURL(res.url), {
|
|
5442
|
+
type: res.headers.get("content-type")
|
|
5443
|
+
});
|
|
5444
|
+
return {
|
|
5445
|
+
name: loadedFile.name,
|
|
5446
|
+
url: res.url,
|
|
5447
|
+
mime: res.headers.get("content-type"),
|
|
5448
|
+
rawFile: loadedFile
|
|
5449
|
+
};
|
|
5450
|
+
})
|
|
5451
|
+
);
|
|
5452
|
+
const assetsResults = await Promise.all(assetPromises);
|
|
5453
|
+
const assets = assetsResults.map((fullFilledAsset) => ({
|
|
5454
|
+
source: AssetSource.Url,
|
|
5455
|
+
name: fullFilledAsset.name,
|
|
5456
|
+
type: typeFromMime(fullFilledAsset.mime),
|
|
5457
|
+
url: fullFilledAsset.url,
|
|
5458
|
+
ext: fullFilledAsset.url.split(".").pop(),
|
|
5459
|
+
mime: fullFilledAsset.mime,
|
|
5460
|
+
rawFile: fullFilledAsset.rawFile
|
|
5461
|
+
}));
|
|
5462
|
+
return assets;
|
|
5463
|
+
};
|
|
5464
|
+
const urlSchema = yup.object().shape({
|
|
5465
|
+
urls: yup.string().test({
|
|
5466
|
+
name: "isUrlValid",
|
|
5467
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
5468
|
+
message: "${path}",
|
|
5469
|
+
test(values = "") {
|
|
5470
|
+
const urls = values.split(/\r?\n/);
|
|
5471
|
+
if (urls.length === 0) {
|
|
5472
|
+
return this.createError({
|
|
5473
|
+
path: this.path,
|
|
5474
|
+
message: translatedErrors.min.id
|
|
5475
|
+
});
|
|
5476
|
+
}
|
|
5477
|
+
if (urls.length > 20) {
|
|
5478
|
+
return this.createError({
|
|
5479
|
+
path: this.path,
|
|
5480
|
+
message: translatedErrors.max.id
|
|
5481
|
+
});
|
|
5482
|
+
}
|
|
5483
|
+
const filtered = urls.filter((val) => {
|
|
5484
|
+
try {
|
|
5485
|
+
new URL(val);
|
|
5486
|
+
return false;
|
|
5487
|
+
} catch (err) {
|
|
5488
|
+
return true;
|
|
5489
|
+
}
|
|
5490
|
+
});
|
|
5491
|
+
const filteredLength = filtered.length;
|
|
5492
|
+
if (filteredLength === 0) {
|
|
5493
|
+
return true;
|
|
5494
|
+
}
|
|
5495
|
+
const errorMessage = filteredLength > 1 ? "form.upload-url.error.url.invalids" : "form.upload-url.error.url.invalid";
|
|
5496
|
+
return this.createError({
|
|
5497
|
+
path: this.path,
|
|
5498
|
+
message: getTrad(errorMessage),
|
|
5499
|
+
params: { number: filtered.length }
|
|
5500
|
+
});
|
|
5501
|
+
}
|
|
5502
|
+
})
|
|
5503
|
+
});
|
|
5587
5504
|
const FromUrlForm = ({ onClose, onAddAsset, trackedLocation }) => {
|
|
5588
5505
|
const [loading, setLoading] = useState(false);
|
|
5589
5506
|
const [error, setError] = useState(void 0);
|
|
@@ -6616,6 +6533,15 @@ MediaLibraryInput.propTypes = {
|
|
|
6616
6533
|
name: PropTypes.string.isRequired,
|
|
6617
6534
|
required: PropTypes.bool
|
|
6618
6535
|
};
|
|
6536
|
+
const prefixPluginTranslations = (trad, pluginId2) => {
|
|
6537
|
+
if (!pluginId2) {
|
|
6538
|
+
throw new TypeError("pluginId can't be empty");
|
|
6539
|
+
}
|
|
6540
|
+
return Object.keys(trad).reduce((acc, current) => {
|
|
6541
|
+
acc[`${pluginId2}.${current}`] = trad[current];
|
|
6542
|
+
return acc;
|
|
6543
|
+
}, {});
|
|
6544
|
+
};
|
|
6619
6545
|
const name = pluginPkg.strapi.name;
|
|
6620
6546
|
const index = {
|
|
6621
6547
|
register(app) {
|
|
@@ -6627,7 +6553,7 @@ const index = {
|
|
|
6627
6553
|
defaultMessage: "Media Library"
|
|
6628
6554
|
},
|
|
6629
6555
|
permissions: PERMISSIONS.main,
|
|
6630
|
-
Component: () => import("./index-
|
|
6556
|
+
Component: () => import("./index-p2ufusDD.mjs"),
|
|
6631
6557
|
position: 4
|
|
6632
6558
|
});
|
|
6633
6559
|
app.addSettingsLink("global", {
|
|
@@ -6637,7 +6563,7 @@ const index = {
|
|
|
6637
6563
|
defaultMessage: "Media Library"
|
|
6638
6564
|
},
|
|
6639
6565
|
to: "media-library",
|
|
6640
|
-
Component: () => import("./index-
|
|
6566
|
+
Component: () => import("./index-D0UI77ZE.mjs"),
|
|
6641
6567
|
permissions: PERMISSIONS.settings
|
|
6642
6568
|
});
|
|
6643
6569
|
app.addFields({ type: "media", Component: MediaLibraryInput });
|
|
@@ -6708,4 +6634,4 @@ export {
|
|
|
6708
6634
|
FolderCardBodyAction as y,
|
|
6709
6635
|
AssetGridList as z
|
|
6710
6636
|
};
|
|
6711
|
-
//# sourceMappingURL=index-
|
|
6637
|
+
//# sourceMappingURL=index-DKKpjnQN.mjs.map
|