chore: helper-plugin remove prefixFileUrlWithBackendUrl (#19764)

* chore: remove prefixFileUrlWithBackendUrl from the helper plugin

* chore: move the prefixFileUrlWithBackend in an util inside the admin

* chore: remove commented code
This commit is contained in:
Simone 2024-03-14 15:26:13 +01:00 committed by GitHub
parent 400683a72c
commit 85f4bdc214
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 30 additions and 14 deletions

View File

@ -1,13 +1,14 @@
import * as React from 'react';
import { Box, Flex } from '@strapi/design-system';
import { prefixFileUrlWithBackendUrl, useLibrary } from '@strapi/helper-plugin';
import { useLibrary } from '@strapi/helper-plugin';
import { Picture } from '@strapi/icons';
import { type Attribute } from '@strapi/types';
import { type Element, Transforms, Editor } from 'slate';
import { useFocused, type RenderElementProps, useSelected } from 'slate-react';
import styled, { css } from 'styled-components';
import { prefixFileUrlWithBackendUrl } from '../../../../../../../utils/urls';
import { useBlocksEditorContext, type BlocksStore } from '../BlocksEditor';
import { type Block } from '../utils/types';

View File

@ -1,10 +1,11 @@
import * as React from 'react';
import { Field, FieldError, FieldHint, FieldLabel, Flex } from '@strapi/design-system';
import { prefixFileUrlWithBackendUrl, useLibrary } from '@strapi/helper-plugin';
import { useLibrary } from '@strapi/helper-plugin';
import { EditorFromTextArea } from 'codemirror5';
import { useField } from '../../../../../../components/Form';
import { prefixFileUrlWithBackendUrl } from '../../../../../../utils/urls';
import { Editor, EditorApi } from './Editor';
import { EditorLayout } from './EditorLayout';

View File

@ -1,9 +1,10 @@
import * as React from 'react';
import { Avatar, AvatarGroup, Flex, Tooltip, Typography } from '@strapi/design-system';
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import styled from 'styled-components';
import { prefixFileUrlWithBackendUrl } from '../../../../../utils/urls';
import type { Entity } from '@strapi/types';
interface MediaFile {

View File

@ -1,5 +1,3 @@
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import {
type TelemetryProperties,
type Init,
@ -9,6 +7,7 @@ import {
type Plugins,
type GetLicenseLimitInformation,
} from '../../../shared/contracts/admin';
import { prefixFileUrlWithBackendUrl } from '../utils/urls';
import { adminApi } from './api';

View File

@ -482,6 +482,10 @@ This util has been removed and not replaced. If you feel like you need this util
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.
### prefixFileUrlWithBackendUrl
This util has been removed and not replaced. Use the strapi backendUrl to prefix the relative url if you need. If you feel like you need this util, please open an issue on the Strapi repository to discuss your usecase.
### pxToRem
This util has been removed and not replaced. You should use directly this code in place of the pxToRem:

View File

@ -49,7 +49,6 @@ export * from './utils/getFetchClient';
export * from './utils/getYupInnerErrors';
export * from './utils/hasPermissions';
export * from './utils/normalizeAPIError';
export * from './utils/prefixFileUrlWithBackendUrl';
export * from './utils/prefixPluginTranslations';
export * from './utils/stopPropagation';
export * from './utils/translatedErrors';

View File

@ -1,10 +1,9 @@
import React from 'react';
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import PropTypes from 'prop-types';
import { AssetDefinition, AssetType } from '../../constants';
import { createAssetUrl, getFileExtension } from '../../utils';
import { createAssetUrl, getFileExtension, prefixFileUrlWithBackendUrl } from '../../utils';
import { AudioAssetCard } from './AudioAssetCard';
import { DocAssetCard } from './DocAssetCard';

View File

@ -1,12 +1,12 @@
import React from 'react';
import { CarouselActions, IconButton } from '@strapi/design-system';
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import { Pencil, Plus, Trash } from '@strapi/icons';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { AssetDefinition } from '../../../constants';
import { prefixFileUrlWithBackendUrl } from '../../../utils';
import getTrad from '../../../utils/getTrad';
import { CopyLinkButton } from '../../CopyLinkButton';

View File

@ -1,13 +1,12 @@
import React from 'react';
import { Avatar, Box, Icon, Initials } from '@strapi/design-system';
import { prefixFileUrlWithBackendUrl } 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, getFileExtension } from '../../utils';
import { createAssetUrl, getFileExtension, prefixFileUrlWithBackendUrl } from '../../utils';
import { VideoPreview } from '../AssetCard/VideoPreview';
const VideoPreviewWrapper = styled(Box)`

View File

@ -1,4 +1,4 @@
import { prefixFileUrlWithBackendUrl } from '@strapi/helper-plugin';
import prefixFileUrlWithBackendUrl from './prefixFileUrlWithBackendUrl';
/**
* Create image URL for asset

View File

@ -12,3 +12,4 @@ export { default as getFolderURL } from './getFolderURL';
export { default as getTrad } from './getTrad';
export { default as toSingularTypes } from './toSingularTypes';
export { default as getFileExtension } from './getFileExtension';
export { default as prefixFileUrlWithBackendUrl } from './prefixFileUrlWithBackendUrl';

View File

@ -0,0 +1,12 @@
/**
* Create the file URL with the backend URL
* @param {Object} asset
* @param {String} fileURL - if true, return the file URL with the Backend url
* if there's no file url or it doesn't start with a slash return the original file url.
* @return {String} file Url
*/
const prefixFileUrlWithBackendUrl = (fileURL) => {
return !!fileURL && fileURL.startsWith('/') ? `${window.strapi.backendURL}${fileURL}` : fileURL;
};
export default prefixFileUrlWithBackendUrl;

View File

@ -1,6 +1,6 @@
import { prefixFileUrlWithBackendUrl } from '../prefixFileUrlWithBackendUrl';
import prefixFileUrlWithBackendUrl from '../prefixFileUrlWithBackendUrl';
describe('HELPER_PLUGIN | utils | prefixFileUrlWithBackendUrl', () => {
describe('prefixFileUrlWithBackendUrl', () => {
it("should add the strapi back-end url if the file's url startsWith '/'", () => {
const data = '/upload/test';
const expected = 'http://localhost:1337/upload/test';