Skip to content

Commit

Permalink
Merge pull request #4 from imgix/fix/trailing-slashes-in-urls
Browse files Browse the repository at this point in the history
fix: add trailing slashes to the urls if not present
  • Loading branch information
cyp3rius authored Jun 21, 2024
2 parents 1caa290 + 9ee4b30 commit 7b9c390
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions admin/src/pages/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7b9c390

Please sign in to comment.