ffffng/server/utils/urlBuilder.ts

39 lines
1 KiB
TypeScript
Raw Normal View History

import _ from "lodash"
import {config} from "../config"
2022-07-18 17:49:42 +02:00
import {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 += _.join(
_.map(
queryParams,
function (value, key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
),
'&'
);
}
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});
}