Merge pull request #27 from kartik1112/main

[ISSUE] #19 Fix urls (trailing or missing slashes)
This commit is contained in:
Mohamed Marrouchi 2024-09-18 06:41:10 +01:00 committed by GitHub
commit 35b911d2d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -51,6 +51,7 @@ import {
import { INlpSampleEntity } from "@/types/nlp-sample_entity.types";
import { PermissionAction } from "@/types/permission.types";
import { getDateTimeFormatter } from "@/utils/date";
import { buildURL } from "@/utils/URL";
import { NlpImportDialog } from "../NlpImportDialog";
import { NlpSampleDialog } from "../NlpSampleDialog";
@ -285,9 +286,10 @@ export default function NlpSample() {
) ? (
<Button
variant="contained"
href={`${publicRuntimeConfig.apiUrl}/nlpsample/export${
dataset ? `?type=${dataset}` : ""
}`}
href={buildURL(
publicRuntimeConfig.apiUrl,
`nlpsample/export${dataset ? `?type=${dataset}` : ""}`,
)}
startIcon={<DownloadIcon />}
>
{t("button.export")}

View File

@ -26,3 +26,14 @@ export const getFromQuery = ({
return defaultValue;
}
};
export const buildURL = (baseUrl: string, relativePath: string): string => {
try {
const url = new URL(relativePath, baseUrl);
return url.toString();
} catch {
throw new Error(`Invalid base URL: ${baseUrl}`);
}
};