fix: trailing slash integration url issues (#1571)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { extractErrorMessage } from "@homarr/common";
|
||||
import { extractErrorMessage, removeTrailingSlash } from "@homarr/common";
|
||||
import type { IntegrationSecretKind } from "@homarr/definitions";
|
||||
import { logger } from "@homarr/log";
|
||||
import type { TranslationObject } from "@homarr/translation";
|
||||
@@ -29,6 +29,19 @@ export abstract class Integration {
|
||||
return secret.value;
|
||||
}
|
||||
|
||||
protected url(path: `/${string}`, queryParams?: Record<string, string | Date | number | boolean>) {
|
||||
const baseUrl = removeTrailingSlash(this.integration.url);
|
||||
const url = new URL(`${baseUrl}${path}`);
|
||||
|
||||
if (queryParams) {
|
||||
for (const [key, value] of Object.entries(queryParams)) {
|
||||
url.searchParams.set(key, value instanceof Date ? value.toISOString() : value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the connection to the integration
|
||||
* @throws {IntegrationTestConnectionError} if the connection fails
|
||||
|
||||
Reference in New Issue
Block a user