Merge pull request #2111 from maxberger/master

UI: Fix handling of servers with Prefix
This commit is contained in:
Peter Bieringer
2026-04-26 18:46:09 +02:00
committed by GitHub
3 changed files with 24 additions and 11 deletions

View File

@@ -24,7 +24,7 @@ import { get_auth_header } from "../api/common.js";
import { Collection, CollectionType, Permission } from "../models/collection.js"; import { Collection, CollectionType, Permission } from "../models/collection.js";
import { collectionsCache } from "../utils/collections_cache.js"; import { collectionsCache } from "../utils/collections_cache.js";
import { ErrorHandler } from "../utils/error.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 { UrlTextHandler } from "../utils/url_text.js";
import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js"; import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js";
import { DeleteConfirmationScene } from "./DeleteConfirmationScene.js"; import { DeleteConfirmationScene } from "./DeleteConfirmationScene.js";
@@ -237,7 +237,7 @@ export class CollectionsScene {
} }
contentcount_form.textContent = contentcount_form_txt; contentcount_form.textContent = contentcount_form_txt;
} }
let href = collection.href; let href = completeHref(collection.href);
new UrlTextHandler(url_form, copy_btn).setHref(href); new UrlTextHandler(url_form, copy_btn).setHref(href);
download_btn.href = href; download_btn.href = href;
download_btn.onclick = (event) => { download_btn.onclick = (event) => {

View File

@@ -19,6 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { ROOT_PATH, SERVER } from "../constants.js";
/** /**
* Escape string for usage in XML * Escape string for usage in XML
* @param {string} s * @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. * Checks if a proposed HREF for a collection has a valid format and syntax.
* @param {string} href String of the proposed HREF. * @param {string} href String of the proposed HREF.

View File

@@ -19,7 +19,8 @@
/** /**
* Utilities for resource URL boxes * Utilities for resource URL boxes
*/ */
import { SERVER } from "../constants.js";
import { completeHref } from "./misc.js";
/** /**
* Handles the display of URLs in input fields. * Handles the display of URLs in input fields.
@@ -107,14 +108,8 @@ export class UrlTextHandler {
* @param {string} href The href to set. * @param {string} href The href to set.
*/ */
setHref(href) { setHref(href) {
if (href.startsWith("/")) { this._element.value = completeHref(href);
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._update_username_index(); this._update_username_index();
this._updateScroll(); this._updateScroll();
} }