diff options
| author | Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> | 2023-05-31 00:04:15 +0300 |
|---|---|---|
| committer | Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> | 2023-05-31 00:29:41 +0300 |
| commit | 1c9fc9422e304c8710b56e9719960e429e7a1878 (patch) | |
| tree | 45e0f87034d2553c70679d7f5af645432ba9897f | |
| parent | 6c26e40aea8f63b2f422c4f9fbf92c7ff1c0383c (diff) | |
add buildURL func
| -rw-r--r-- | web/assets/js/util/common.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/web/assets/js/util/common.js b/web/assets/js/util/common.js index 563bfd45..8e30bce7 100644 --- a/web/assets/js/util/common.js +++ b/web/assets/js/util/common.js @@ -135,3 +135,21 @@ function doAllItemsExist(array1, array2) { } return true; } + +function buildURL({ host, port, isTLS, base, path }) { + if (!host || host.length === 0) host = window.location.hostname; + if (!port || port.length === 0) port = window.location.port; + + if (isTLS === undefined) isTLS = window.location.protocol === "https:"; + + const protocol = isTLS ? "https:" : "http:"; + + port = String(port); + if (port === "" || (isTLS && port === "443") || (!isTLS && port === "80")) { + port = ""; + } else { + port = `:${port}`; + } + + return `${protocol}//${host}${port}${base}${path}`; +} |
