Fix links for the menus in the view file page (#22795)

This commit is contained in:
wxiaoguang 2023-02-08 00:08:44 +08:00 committed by GitHub
parent d5fa2e7510
commit 2c6cc0b8c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 12 deletions

View file

@ -134,9 +134,15 @@ export function convertImage(blob, mime) {
});
}
export function toAbsoluteUrl(relUrl) {
if (relUrl.startsWith('http://') || relUrl.startsWith('https://')) {
return relUrl;
export function toAbsoluteUrl(url) {
if (url.startsWith('http://') || url.startsWith('https://')) {
return url;
}
return `${window.location.origin}${relUrl}`;
if (url.startsWith('//')) {
return `${window.location.protocol}${url}`; // it's also a somewhat absolute URL (with the current scheme)
}
if (url && !url.startsWith('/')) {
throw new Error('unsupported url, it should either start with / or http(s)://');
}
return `${window.location.origin}${url}`;
}