admin: change path behaviour for the billionth time

URLs are made with app.ExternalURI (now included in window.pages), which
itself should include Base. Also fixed the subfolder being removed from
the url after login.
This commit is contained in:
Harvey Tindall
2025-05-27 15:40:08 +01:00
parent d8e624ad22
commit 42d1abe130
7 changed files with 32 additions and 13 deletions

View File

@@ -15,6 +15,8 @@
<script>
window.pages = {
"Base": "{{ .pages.Base }}",
"TrueBase": "{{ .pages.TrueBase }}",
"ExternalURI": "{{ .pages.ExternalURI }}",
"Current": "{{ .pages.Current }}",
"Admin": "{{ .pages.Admin }}",
"MyAccount": "{{ .pages.MyAccount }}",

View File

@@ -485,5 +485,8 @@ type PagePaths struct {
type PagePathsDTO struct {
PagePaths
// The subdirectory this bit of the app is hosted on (e.g. admin is usually on "/", myacc is usually on "/my/account")
Current string `json:"Current"`
Current string `json:"Current"`
ExternalURI string `json:"ExternalURI"`
// The subdirectory the app is meant to be accessed from ("Reverse proxy subfolder")
TrueBase string `json:"TrueBase"`
}

View File

@@ -174,12 +174,12 @@ const defaultTab = tabs[0];
window.tabs = new Tabs();
for (let tab of tabs) {
window.tabs.addTab(tab.id, window.pages.Admin + "/" + tab.url, null, tab.reloader, tab.unloader || null);
window.tabs.addTab(tab.id, window.pages.Base + window.pages.Admin + "/" + tab.url, null, tab.reloader, tab.unloader || null);
}
let matchedTab = false
for (const tab of tabs) {
if (window.location.pathname.startsWith(window.pages.Base + window.pages.Current + "/" + tab.url)) {
if (window.location.pathname.startsWith(window.pages.Current + "/" + tab.url)) {
window.tabs.switch(tab.url, true);
matchedTab = true;
}

View File

@@ -4,6 +4,12 @@ import { reloadProfileNames } from "../modules/profiles.js";
declare var window: GlobalWindow;
export const generateCodeLink = (code: string): string => {
// let codeLink = window.pages.Base + window.pages.Form + "/" + code;
let codeLink = window.pages.ExternalURI + window.pages.Form + "/" + code;
return codeLink;
}
class DOMInvite implements Invite {
updateNotify = (checkbox: HTMLInputElement) => {
let state: { [code: string]: { [type: string]: boolean } } = {};
@@ -63,7 +69,7 @@ class DOMInvite implements Invite {
get code(): string { return this._code; }
set code(code: string) {
this._code = code;
this._codeLink = window.pages.Base + window.pages.Form + "/" + code;
this._codeLink = generateCodeLink(code);
const linkEl = this._codeArea.querySelector("a") as HTMLAnchorElement;
if (this.label == "") {
linkEl.textContent = code.replace(/-/g, '-');

View File

@@ -13,14 +13,18 @@ interface ArrayConstructor {
}
declare interface PagePaths {
// The base subfolder the app is hosted on.
// The base subfolder the app is being accessed from.
Base: string;
// The base subfolder the app is meant to be accessed from ("Reverse proxy subfolder")
TrueBase: string;
// The subdirectory this bit of the app is hosted on (e.g. admin is usually on "/", myacc is usually on "/my/account")
Current: string;
// Those for other pages
Admin: string;
MyAccount: string;
Form: string;
// The "External jfa-go URL"
ExternalURI: string;
}
declare interface GlobalWindow extends Window {

View File

@@ -6,6 +6,7 @@ import { Login } from "./modules/login.js";
import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js";
import { Validator, ValidatorConf, ValidatorRespDTO } from "./modules/validator.js";
import { PageManager } from "./modules/pages.js";
import { generateCodeLink } from "./modules/invites.js";
interface userWindow extends GlobalWindow {
jellyfinID: string;
@@ -305,14 +306,15 @@ class ReferralCard {
this._code = c;
let u = new URL(window.location.href);
const path = window.pages.Base + window.pages.Form + "/" + this._code;
u.pathname = path;
u.hash = "";
u.search = "";
// let u = new URL(window.location.href);
// const path = window.pages.Base + window.pages.Form + "/" + this._code;
//
// u.pathname = path;
// u.hash = "";
// u.search = "";
this._url = u.toString();
// this._url = u.toString();
this._url = generateCodeLink(this._code);
}
get remaining_uses(): number { return this._remainingUses; }

View File

@@ -87,7 +87,9 @@ func (app *appContext) BasePageTemplateValues(gc *gin.Context, page Page, base g
}
pages := PagePathsDTO{
PagePaths: PAGES,
PagePaths: PAGES,
ExternalURI: app.ExternalURI,
TrueBase: PAGES.Base,
}
pages.Base = app.getURLBase(gc)
switch page {