Typescript migration
* utils/strings.js * utils/urlBuilder.js
This commit is contained in:
parent
2c2c6336db
commit
7325cd4db6
5 changed files with 67 additions and 68 deletions
server/utils
40
server/utils/urlBuilder.ts
Normal file
40
server/utils/urlBuilder.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
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 });
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue