From 9ee4b30f671743cea1f088a2bc88d4e33d5c6b43 Mon Sep 17 00:00:00 2001 From: Mateusz Ziarko Date: Wed, 19 Jun 2024 18:27:57 +0200 Subject: [PATCH] fix: add trailing slashes to the urls if not present --- admin/src/pages/Settings/Settings.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/admin/src/pages/Settings/Settings.tsx b/admin/src/pages/Settings/Settings.tsx index f1968dc..5740209 100644 --- a/admin/src/pages/Settings/Settings.tsx +++ b/admin/src/pages/Settings/Settings.tsx @@ -82,14 +82,16 @@ export const Settings = () => { mutationFn: (apiKey: string) => http.put<{ apiKey: string }, { valid: boolean }>('/settings/validate', { apiKey }), }); + const addTrailingSlashes = (value: string) => value.endsWith('/') ? value : `${value}/`; + const preparePayload = useCallback((values: FormData) => { const source = pickBy({ id: values.sourceType === SOURCE_TYPES.OTHER && values.sourceId ? values.sourceId : undefined, type: values.sourceType, - url: values.sourceUrl ? values.sourceUrl : undefined, + url: values.sourceUrl ? addTrailingSlashes(values.sourceUrl) : undefined, }, (value) => value !== undefined) as ConfigData['source']; const payload: ConfigData = { - mediaLibrarySourceUrl: values.mediaLibrarySourceUrl, + mediaLibrarySourceUrl: values.mediaLibrarySourceUrl ? addTrailingSlashes(values.mediaLibrarySourceUrl) : values.mediaLibrarySourceUrl, source: isEmpty(source) ? { url: '', type: SOURCE_TYPES.FOLDER } : source, }; if (values.sourceType === SOURCE_TYPES.OTHER) {