From 0a5478e393a4c408a6dd949429e21af740164e4a Mon Sep 17 00:00:00 2001 From: gordielachance Date: Mon, 14 Oct 2024 15:34:20 +0200 Subject: [PATCH] moved prefixFileUrlWithBackendUrl in its own file --- admin/src/components/MediaLib.tsx | 11 +---------- admin/src/utils/prefixFileUrlWithBackendUrl.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 admin/src/utils/prefixFileUrlWithBackendUrl.ts diff --git a/admin/src/components/MediaLib.tsx b/admin/src/components/MediaLib.tsx index 9619e7c..4f6cfcf 100644 --- a/admin/src/components/MediaLib.tsx +++ b/admin/src/components/MediaLib.tsx @@ -1,17 +1,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import { useStrapiApp } from '@strapi/strapi/admin'; +import prefixFileUrlWithBackendUrl from '../utils/prefixFileUrlWithBackendUrl'; -const prefixFileUrlWithBackendUrl = (fileURL: string) => { - return !!fileURL && - fileURL.startsWith("/") && - "strapi" in window && - window.strapi instanceof Object && - "backendURL" in window.strapi && - window.strapi.backendURL - ? `${window.strapi.backendURL}${fileURL}` - : fileURL; -}; const MediaLib = ( { isOpen = false, onChange = () => {}, onToggle = () => {} } ) => { const { components } = useStrapiApp( 'library', app => app ); diff --git a/admin/src/utils/prefixFileUrlWithBackendUrl.ts b/admin/src/utils/prefixFileUrlWithBackendUrl.ts new file mode 100644 index 0000000..e1ed811 --- /dev/null +++ b/admin/src/utils/prefixFileUrlWithBackendUrl.ts @@ -0,0 +1,12 @@ +const prefixFileUrlWithBackendUrl = (fileURL: string) => { + return !!fileURL && + fileURL.startsWith("/") && + "strapi" in window && + window.strapi instanceof Object && + "backendURL" in window.strapi && + window.strapi.backendURL + ? `${window.strapi.backendURL}${fileURL}` + : fileURL; +}; + +export default prefixFileUrlWithBackendUrl;