UI: Fix handling of servers with Prefix
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
* 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
|
||||
* @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.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user