ffffng/server/utils/urlBuilder.ts
baldo 7325cd4db6 Typescript migration
* utils/strings.js
* utils/urlBuilder.js
2020-04-08 21:25:33 +02:00

40 lines
1 KiB
TypeScript

import _ from "lodash"
import {config} from "../config"
import {NodeSecrets} from "../types"
// TODO: Typed URLs
function formUrl(route: string, queryParams?: {[key: string]: string}): string {
let url = config.server.baseUrl;
if (route || queryParams) {
url += '/#/';
}
if (route) {
url += route;
}
if (queryParams) {
url += '?';
url += _.join(
_.map(
queryParams,
function (value, key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
),
'&'
);
}
return url;
}
export function editNodeUrl (): string {
return formUrl('update');
}
export function monitoringConfirmUrl (nodeSecrets: NodeSecrets): string {
return formUrl('monitoring/confirm', { token: nodeSecrets.monitoringToken });
}
export function monitoringDisableUrl (nodeSecrets: NodeSecrets): string {
return formUrl('monitoring/disable', { token: nodeSecrets.monitoringToken });
}