diff --git a/radicale/web/internal_data/js/scenes/CollectionsScene.js b/radicale/web/internal_data/js/scenes/CollectionsScene.js index 4125d8d0..2e7c0e3d 100644 --- a/radicale/web/internal_data/js/scenes/CollectionsScene.js +++ b/radicale/web/internal_data/js/scenes/CollectionsScene.js @@ -24,7 +24,7 @@ import { get_auth_header } from "../api/common.js"; import { Collection, CollectionType, Permission } from "../models/collection.js"; import { collectionsCache } from "../utils/collections_cache.js"; import { ErrorHandler } from "../utils/error.js"; -import { bytesToHumanReadable, get_element, get_element_by_id } from "../utils/misc.js"; +import { bytesToHumanReadable, completeHref, get_element, get_element_by_id } from "../utils/misc.js"; import { UrlTextHandler } from "../utils/url_text.js"; import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js"; import { DeleteConfirmationScene } from "./DeleteConfirmationScene.js"; @@ -237,7 +237,7 @@ export class CollectionsScene { } contentcount_form.textContent = contentcount_form_txt; } - let href = collection.href; + let href = completeHref(collection.href); new UrlTextHandler(url_form, copy_btn).setHref(href); download_btn.href = href; download_btn.onclick = (event) => { diff --git a/radicale/web/internal_data/js/utils/misc.js b/radicale/web/internal_data/js/utils/misc.js index dcafefa1..4444b892 100644 --- a/radicale/web/internal_data/js/utils/misc.js +++ b/radicale/web/internal_data/js/utils/misc.js @@ -19,6 +19,8 @@ * along with this program. If not, see . */ +import { ROOT_PATH, SERVER } from "../constants.js"; + /** * Escape string for usage in XML * @param {string} s @@ -74,6 +76,22 @@ export function onCleanHREFinput(event) { } } +/** + * Make sure HREF is complete including server and prefix. + * @param {string} href + */ +export function completeHref(href) { + let full_href = href; + if (!href.includes("://")) { + if (!href.startsWith("/")) { + full_href = "/" + href; + } + // ROOT_PATH ends in / and href starts with /, so remove the duplicate / + full_href = SERVER + ROOT_PATH + full_href.substring(1); + } + return full_href; +} + /** * Checks if a proposed HREF for a collection has a valid format and syntax. * @param {string} href String of the proposed HREF. diff --git a/radicale/web/internal_data/js/utils/url_text.js b/radicale/web/internal_data/js/utils/url_text.js index 08d1cf89..004bdbbe 100644 --- a/radicale/web/internal_data/js/utils/url_text.js +++ b/radicale/web/internal_data/js/utils/url_text.js @@ -19,7 +19,8 @@ /** * Utilities for resource URL boxes */ -import { SERVER } from "../constants.js"; + +import { completeHref } from "./misc.js"; /** * Handles the display of URLs in input fields. @@ -107,14 +108,8 @@ export class UrlTextHandler { * @param {string} href The href to set. */ setHref(href) { - if (href.startsWith("/")) { - this._element.value = SERVER + href; - } else if (!href.includes("://")) { - // Handle cases where the href might not start with a slash - this._element.value = SERVER + "/" + href; - } else { - this._element.value = href; - } + this._element.value = completeHref(href); + this._update_username_index(); this._updateScroll(); }