31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import Utils from "./index";
|
|
|
|
export function replaceOriginUrl(urlToRedirectTo: string, baseRedirectHost: string) {
|
|
var newUrl = Utils.strToHexCharCode(window.location.href);
|
|
// newUrl = hexHrefToString("https://base.bestsch.com/BschHome/base/index.html#/lightapp?id=1&name=2");
|
|
// newUrl = Utils.strToHexCharCode("https://base.bestsch.com/BschHome/base/index.html#/lightapp?id=1&name=2");
|
|
var ssoUrlObj = new URL(urlToRedirectTo);
|
|
var paramsStr = ssoUrlObj.searchParams.get("service") || "";
|
|
let ssoServiceUrl = decodeURI(paramsStr).split(";")[0];
|
|
ssoServiceUrl += ";redirectToReferer=" + baseRedirectHost + "/api/RedirectTo/" + newUrl;
|
|
ssoUrlObj.searchParams.set("service", encodeURI(ssoServiceUrl));
|
|
return ssoUrlObj.href;
|
|
}
|
|
|
|
export function hexStringToHref(urlHexStr: string, paramsKey: string = "hex") {
|
|
let urlObj = new URL(urlHexStr);
|
|
let hexStr = urlObj.searchParams.get(paramsKey) || "";
|
|
urlObj.hash = Utils.hexToString(hexStr);
|
|
urlObj.searchParams.delete(paramsKey);
|
|
return urlObj.href;
|
|
}
|
|
|
|
export function hexHrefToString(hrefStr: string, paramsKey: string = "hex") {
|
|
var urlObj = new URL(hrefStr);
|
|
var hasHexStr = Utils.strToHexCharCode(urlObj.hash);
|
|
const newUrlObj = new URL(urlObj.origin);
|
|
newUrlObj.pathname = urlObj.pathname;
|
|
// newUrlObj.searchParams.set(paramsKey, hasHexStr);
|
|
return newUrlObj.href + hasHexStr;
|
|
}
|