mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
chore: remove getFileExtension and replace it with its code where used (#19762)
* chore: remove getFileExtension and replace it with its code where used * chore: create a getFileExtension util in upload with its test
This commit is contained in:
parent
d9f9c0cd21
commit
794f5522b5
@ -1,7 +1,7 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import { Avatar, AvatarGroup, Flex, Tooltip, Typography } from '@strapi/design-system';
|
||||
import { getFileExtension, prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
|
||||
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import type { Entity } from '@strapi/types';
|
||||
@ -26,6 +26,8 @@ interface MediaFile {
|
||||
|
||||
interface MediaSingleProps extends MediaFile {}
|
||||
|
||||
const getFileExtension = (ext: string) => (ext && ext[0] === '.' ? ext.substring(1) : ext);
|
||||
|
||||
const MediaSingle = ({ url, mime, alternativeText, name, ext, formats }: MediaSingleProps) => {
|
||||
const fileURL = prefixFileUrlWithBackendUrl(url)!;
|
||||
|
||||
|
||||
@ -437,6 +437,10 @@ This util has been removed and not replaced, use async / await with try / catch
|
||||
|
||||
This util has been removed and not replaced. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
|
||||
|
||||
### getFileExtension
|
||||
|
||||
This util has been removed and not replaced. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
|
||||
|
||||
### setHexOpacity
|
||||
|
||||
This util has been removed and not replaced, use the native CSS opacity property instead. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
|
||||
|
||||
@ -48,7 +48,6 @@ export * from './hooks/useSelectionState';
|
||||
export * from './utils/auth';
|
||||
export * from './utils/getAPIInnerErrors';
|
||||
export * from './utils/getFetchClient';
|
||||
export * from './utils/getFileExtension';
|
||||
export * from './utils/getYupInnerErrors';
|
||||
export * from './utils/hasPermissions';
|
||||
export * from './utils/normalizeAPIError';
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Get the file extension of value passed in.
|
||||
*
|
||||
* This hook is used to create URL aware of the backend. Practical to resolve assets.
|
||||
*/
|
||||
export const getFileExtension = (ext: string) => (ext && ext[0] === '.' ? ext.substr(1) : ext);
|
||||
@ -1,10 +1,10 @@
|
||||
import React from 'react';
|
||||
|
||||
import { getFileExtension, prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
|
||||
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { AssetDefinition, AssetType } from '../../constants';
|
||||
import { createAssetUrl } from '../../utils';
|
||||
import { createAssetUrl, getFileExtension } from '../../utils';
|
||||
|
||||
import { AudioAssetCard } from './AudioAssetCard';
|
||||
import { DocAssetCard } from './DocAssetCard';
|
||||
|
||||
@ -19,7 +19,7 @@ import {
|
||||
TextInput,
|
||||
VisuallyHidden,
|
||||
} from '@strapi/design-system';
|
||||
import { getFileExtension, pxToRem, useTracking } from '@strapi/helper-plugin';
|
||||
import { pxToRem, useTracking } from '@strapi/helper-plugin';
|
||||
import { Form, Formik } from 'formik';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import PropTypes from 'prop-types';
|
||||
@ -30,7 +30,7 @@ import * as yup from 'yup';
|
||||
import { AssetDefinition } from '../../constants';
|
||||
import { useEditAsset } from '../../hooks/useEditAsset';
|
||||
import { useFolderStructure } from '../../hooks/useFolderStructure';
|
||||
import { findRecursiveFolderByValue, getTrad } from '../../utils';
|
||||
import { findRecursiveFolderByValue, getTrad, getFileExtension } from '../../utils';
|
||||
import formatBytes from '../../utils/formatBytes';
|
||||
import { ContextInfo } from '../ContextInfo';
|
||||
import SelectTree from '../SelectTree';
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Typography } from '@strapi/design-system';
|
||||
import { getFileExtension } from '@strapi/helper-plugin';
|
||||
import parseISO from 'date-fns/parseISO';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { formatBytes } from '../../utils';
|
||||
import { formatBytes, getFileExtension } from '../../utils';
|
||||
|
||||
import { PreviewCell } from './PreviewCell';
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Avatar, Box, Icon, Initials } from '@strapi/design-system';
|
||||
import { getFileExtension, prefixFileUrlWithBackendUrl, pxToRem } from '@strapi/helper-plugin';
|
||||
import { prefixFileUrlWithBackendUrl, pxToRem } from '@strapi/helper-plugin';
|
||||
import { Folder } from '@strapi/icons';
|
||||
import PropTypes from 'prop-types';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { AssetType } from '../../constants';
|
||||
import { createAssetUrl } from '../../utils';
|
||||
import { createAssetUrl, getFileExtension } from '../../utils';
|
||||
import { VideoPreview } from '../AssetCard/VideoPreview';
|
||||
|
||||
const VideoPreviewWrapper = styled(Box)`
|
||||
|
||||
3
packages/core/upload/admin/src/utils/getFileExtension.js
Normal file
3
packages/core/upload/admin/src/utils/getFileExtension.js
Normal file
@ -0,0 +1,3 @@
|
||||
const getFileExtension = (ext) => (ext && ext[0] === '.' ? ext.substring(1) : ext);
|
||||
|
||||
export default getFileExtension;
|
||||
@ -11,3 +11,4 @@ export { default as getFolderParents } from './getFolderParents';
|
||||
export { default as getFolderURL } from './getFolderURL';
|
||||
export { default as getTrad } from './getTrad';
|
||||
export { default as toSingularTypes } from './toSingularTypes';
|
||||
export { default as getFileExtension } from './getFileExtension';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { getFileExtension } from '../getFileExtension';
|
||||
import getFileExtension from '../getFileExtension';
|
||||
|
||||
describe('HELPER PLUGIN | utils | getFileExtension', () => {
|
||||
describe('getFileExtension', () => {
|
||||
it('should return undefined if ext does not exits', () => {
|
||||
const ext = null;
|
||||
const expected = null;
|
||||
Loading…
x
Reference in New Issue
Block a user