ffffng/server/utils/urlBuilder.ts

35 lines
980 B
TypeScript
Raw Permalink Normal View History

import { config } from "../config";
import type { MonitoringToken, Url } from "../types";
2022-07-18 17:49:42 +02:00
function formUrl(route: string, queryParams?: { [key: string]: string }): Url {
let url = config.server.baseUrl as string;
if (route || queryParams) {
url += "/#/";
}
if (route) {
url += route;
}
if (queryParams) {
url += "?";
url += Object.entries(queryParams)
.map(
([key, value]) =>
encodeURIComponent(key) + "=" + encodeURIComponent(value)
)
.join("&");
}
2022-07-18 17:49:42 +02:00
return url as Url;
}
2022-07-18 17:49:42 +02:00
export function editNodeUrl(): Url {
return formUrl("update");
}
2022-07-18 17:49:42 +02:00
export function monitoringConfirmUrl(monitoringToken: MonitoringToken): Url {
return formUrl("monitoring/confirm", { token: monitoringToken });
}
2022-07-18 17:49:42 +02:00
export function monitoringDisableUrl(monitoringToken: MonitoringToken): Url {
return formUrl("monitoring/disable", { token: monitoringToken });
}