mirror of
https://github.com/strapi/strapi.git
synced 2025-08-02 05:48:39 +00:00
extension
Signed-off-by: Ky <virginie.ky@gmail.com>
This commit is contained in:
parent
7f7958ba3f
commit
e4e54c49d5
@ -1,3 +1,3 @@
|
|||||||
const getFileExtension = mime => (mime ? mime.split(/[\s/]+/)[1] : 'undefined');
|
const getFileExtension = ext => (ext ? ext.substr(1) : null);
|
||||||
|
|
||||||
export default getFileExtension;
|
export default getFileExtension;
|
||||||
|
@ -33,8 +33,8 @@ function MediaPreviewList({ hoverable, files }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderFile = file => {
|
const renderFile = file => {
|
||||||
const { mime, name } = file;
|
const { ext, name } = file;
|
||||||
const fileExtension = getFileExtension(mime);
|
const fileExtension = getFileExtension(ext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MediaPreviewFile className={hoverable ? 'hoverable' : ''}>
|
<MediaPreviewFile className={hoverable ? 'hoverable' : ''}>
|
||||||
|
@ -20,6 +20,7 @@ const Card = ({
|
|||||||
checked,
|
checked,
|
||||||
children,
|
children,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
ext,
|
||||||
hasError,
|
hasError,
|
||||||
height,
|
height,
|
||||||
mime,
|
mime,
|
||||||
@ -37,6 +38,7 @@ const Card = ({
|
|||||||
const { formatMessage } = useGlobalContext();
|
const { formatMessage } = useGlobalContext();
|
||||||
const fileSize = formatBytes(size, 0);
|
const fileSize = formatBytes(size, 0);
|
||||||
const fileType = mime || type;
|
const fileType = mime || type;
|
||||||
|
const extension = getFileExtension(ext) || name.split('.').slice(-1)[0] || null;
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (!isDisabled) {
|
if (!isDisabled) {
|
||||||
@ -51,6 +53,7 @@ const Card = ({
|
|||||||
>
|
>
|
||||||
<CardImgWrapper checked={checked} small={small}>
|
<CardImgWrapper checked={checked} small={small}>
|
||||||
<CardPreview
|
<CardPreview
|
||||||
|
extension={extension}
|
||||||
hasError={hasError}
|
hasError={hasError}
|
||||||
previewUrl={previewUrl}
|
previewUrl={previewUrl}
|
||||||
url={url}
|
url={url}
|
||||||
@ -68,12 +71,7 @@ const Card = ({
|
|||||||
<Tag label={getType(fileType)} />
|
<Tag label={getType(fileType)} />
|
||||||
</Flex>
|
</Flex>
|
||||||
{!withoutFileInfo && (
|
{!withoutFileInfo && (
|
||||||
<FileInfos
|
<FileInfos extension={extension} size={fileSize} width={width} height={height} />
|
||||||
extension={getFileExtension(fileType)}
|
|
||||||
size={fileSize}
|
|
||||||
width={width}
|
|
||||||
height={height}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
@ -89,6 +87,7 @@ Card.defaultProps = {
|
|||||||
checked: false,
|
checked: false,
|
||||||
children: null,
|
children: null,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
|
ext: null,
|
||||||
id: null,
|
id: null,
|
||||||
isDisabled: false,
|
isDisabled: false,
|
||||||
hasError: false,
|
hasError: false,
|
||||||
@ -112,6 +111,7 @@ Card.propTypes = {
|
|||||||
checked: PropTypes.bool,
|
checked: PropTypes.bool,
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
errorMessage: PropTypes.string,
|
errorMessage: PropTypes.string,
|
||||||
|
ext: PropTypes.string,
|
||||||
hasError: PropTypes.bool,
|
hasError: PropTypes.bool,
|
||||||
height: PropTypes.number,
|
height: PropTypes.number,
|
||||||
mime: PropTypes.string,
|
mime: PropTypes.string,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import React, { memo, useRef } from 'react';
|
import React, { memo, useRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { getFileExtension } from 'strapi-helper-plugin';
|
|
||||||
|
|
||||||
import { getType } from '../../utils';
|
import { getType } from '../../utils';
|
||||||
|
|
||||||
@ -10,7 +9,7 @@ import VideoPreview from '../VideoPreview';
|
|||||||
import Wrapper from './Wrapper';
|
import Wrapper from './Wrapper';
|
||||||
import Image from './Image';
|
import Image from './Image';
|
||||||
|
|
||||||
const CardPreview = ({ hasError, hasIcon, url, previewUrl, type, withFileCaching }) => {
|
const CardPreview = ({ extension, hasError, hasIcon, url, previewUrl, type, withFileCaching }) => {
|
||||||
const isFile = getType(type) === 'file';
|
const isFile = getType(type) === 'file';
|
||||||
const isVideo = getType(type) === 'video';
|
const isVideo = getType(type) === 'video';
|
||||||
const cacheRef = useRef(performance.now());
|
const cacheRef = useRef(performance.now());
|
||||||
@ -26,7 +25,7 @@ const CardPreview = ({ hasError, hasIcon, url, previewUrl, type, withFileCaching
|
|||||||
if (isFile) {
|
if (isFile) {
|
||||||
return (
|
return (
|
||||||
<Wrapper isFile>
|
<Wrapper isFile>
|
||||||
<FileIcon ext={getFileExtension(type)} />
|
<FileIcon ext={extension} />
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -45,6 +44,7 @@ const CardPreview = ({ hasError, hasIcon, url, previewUrl, type, withFileCaching
|
|||||||
};
|
};
|
||||||
|
|
||||||
CardPreview.defaultProps = {
|
CardPreview.defaultProps = {
|
||||||
|
extension: null,
|
||||||
hasError: false,
|
hasError: false,
|
||||||
hasIcon: false,
|
hasIcon: false,
|
||||||
previewUrl: null,
|
previewUrl: null,
|
||||||
@ -54,6 +54,7 @@ CardPreview.defaultProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CardPreview.propTypes = {
|
CardPreview.propTypes = {
|
||||||
|
extension: PropTypes.string,
|
||||||
hasError: PropTypes.bool,
|
hasError: PropTypes.bool,
|
||||||
hasIcon: PropTypes.bool,
|
hasIcon: PropTypes.bool,
|
||||||
previewUrl: PropTypes.string,
|
previewUrl: PropTypes.string,
|
||||||
|
@ -20,6 +20,7 @@ const DraggableCard = ({
|
|||||||
checked,
|
checked,
|
||||||
children,
|
children,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
ext,
|
||||||
hasError,
|
hasError,
|
||||||
index,
|
index,
|
||||||
isDraggable,
|
isDraggable,
|
||||||
@ -88,6 +89,7 @@ const DraggableCard = ({
|
|||||||
<Wrapper onClick={handleClick} isDraggable={isDraggable} ref={ref} style={{ opacity }}>
|
<Wrapper onClick={handleClick} isDraggable={isDraggable} ref={ref} style={{ opacity }}>
|
||||||
<CardImgWrapper checked={checked} small>
|
<CardImgWrapper checked={checked} small>
|
||||||
<CardPreview
|
<CardPreview
|
||||||
|
extension={getFileExtension(ext)}
|
||||||
hasError={hasError}
|
hasError={hasError}
|
||||||
url={url}
|
url={url}
|
||||||
type={fileType}
|
type={fileType}
|
||||||
@ -100,7 +102,7 @@ const DraggableCard = ({
|
|||||||
<Title>{name}</Title>
|
<Title>{name}</Title>
|
||||||
<Tag label={getType(fileType)} />
|
<Tag label={getType(fileType)} />
|
||||||
</Flex>
|
</Flex>
|
||||||
<FileInfos extension={getFileExtension(fileType)} size={fileSize} />
|
<FileInfos extension={getFileExtension(ext)} size={fileSize} />
|
||||||
{hasError && <ErrorMessage>{errorMessage}</ErrorMessage>}
|
{hasError && <ErrorMessage>{errorMessage}</ErrorMessage>}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
@ -110,6 +112,7 @@ DraggableCard.defaultProps = {
|
|||||||
checked: false,
|
checked: false,
|
||||||
children: null,
|
children: null,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
|
ext: null,
|
||||||
id: null,
|
id: null,
|
||||||
index: 0,
|
index: 0,
|
||||||
isDraggable: false,
|
isDraggable: false,
|
||||||
@ -129,6 +132,7 @@ DraggableCard.propTypes = {
|
|||||||
checked: PropTypes.bool,
|
checked: PropTypes.bool,
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
errorMessage: PropTypes.string,
|
errorMessage: PropTypes.string,
|
||||||
|
ext: PropTypes.string,
|
||||||
hasError: PropTypes.bool,
|
hasError: PropTypes.bool,
|
||||||
index: PropTypes.number,
|
index: PropTypes.number,
|
||||||
isDraggable: PropTypes.bool,
|
isDraggable: PropTypes.bool,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user