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
+2
View File
@@ -15,6 +15,8 @@
<script> <script>
window.pages = { window.pages = {
"Base": "{{ .pages.Base }}", "Base": "{{ .pages.Base }}",
"TrueBase": "{{ .pages.TrueBase }}",
"ExternalURI": "{{ .pages.ExternalURI }}",
"Current": "{{ .pages.Current }}", "Current": "{{ .pages.Current }}",
"Admin": "{{ .pages.Admin }}", "Admin": "{{ .pages.Admin }}",
"MyAccount": "{{ .pages.MyAccount }}", "MyAccount": "{{ .pages.MyAccount }}",
+4 -1
View File
@@ -485,5 +485,8 @@ type PagePaths struct {
type PagePathsDTO struct { type PagePathsDTO struct {
PagePaths PagePaths
// The subdirectory this bit of the app is hosted on (e.g. admin is usually on "/", myacc is usually on "/my/account") // 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"`
} }
+2 -2
View File
@@ -174,12 +174,12 @@ const defaultTab = tabs[0];
window.tabs = new Tabs(); window.tabs = new Tabs();
for (let tab of 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 let matchedTab = false
for (const tab of tabs) { 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); window.tabs.switch(tab.url, true);
matchedTab = true; matchedTab = true;
} }
+7 -1
View File
@@ -4,6 +4,12 @@ import { reloadProfileNames } from "../modules/profiles.js";
declare var window: GlobalWindow; 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 { class DOMInvite implements Invite {
updateNotify = (checkbox: HTMLInputElement) => { updateNotify = (checkbox: HTMLInputElement) => {
let state: { [code: string]: { [type: string]: boolean } } = {}; let state: { [code: string]: { [type: string]: boolean } } = {};
@@ -63,7 +69,7 @@ class DOMInvite implements Invite {
get code(): string { return this._code; } get code(): string { return this._code; }
set code(code: string) { set code(code: string) {
this._code = code; this._code = code;
this._codeLink = window.pages.Base + window.pages.Form + "/" + code; this._codeLink = generateCodeLink(code);
const linkEl = this._codeArea.querySelector("a") as HTMLAnchorElement; const linkEl = this._codeArea.querySelector("a") as HTMLAnchorElement;
if (this.label == "") { if (this.label == "") {
linkEl.textContent = code.replace(/-/g, '-'); linkEl.textContent = code.replace(/-/g, '-');
+5 -1
View File
@@ -13,14 +13,18 @@ interface ArrayConstructor {
} }
declare interface PagePaths { declare interface PagePaths {
// The base subfolder the app is hosted on. // The base subfolder the app is being accessed from.
Base: string; 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") // The subdirectory this bit of the app is hosted on (e.g. admin is usually on "/", myacc is usually on "/my/account")
Current: string; Current: string;
// Those for other pages // Those for other pages
Admin: string; Admin: string;
MyAccount: string; MyAccount: string;
Form: string; Form: string;
// The "External jfa-go URL"
ExternalURI: string;
} }
declare interface GlobalWindow extends Window { declare interface GlobalWindow extends Window {
+9 -7
View File
@@ -6,6 +6,7 @@ import { Login } from "./modules/login.js";
import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js"; import { Discord, Telegram, Matrix, ServiceConfiguration, MatrixConfiguration } from "./modules/account-linking.js";
import { Validator, ValidatorConf, ValidatorRespDTO } from "./modules/validator.js"; import { Validator, ValidatorConf, ValidatorRespDTO } from "./modules/validator.js";
import { PageManager } from "./modules/pages.js"; import { PageManager } from "./modules/pages.js";
import { generateCodeLink } from "./modules/invites.js";
interface userWindow extends GlobalWindow { interface userWindow extends GlobalWindow {
jellyfinID: string; jellyfinID: string;
@@ -305,14 +306,15 @@ class ReferralCard {
this._code = c; this._code = c;
let u = new URL(window.location.href); // let u = new URL(window.location.href);
const path = window.pages.Base + window.pages.Form + "/" + this._code; // const path = window.pages.Base + window.pages.Form + "/" + this._code;
//
// u.pathname = path;
// u.hash = "";
// u.search = "";
u.pathname = path; // this._url = u.toString();
u.hash = ""; this._url = generateCodeLink(this._code);
u.search = "";
this._url = u.toString();
} }
get remaining_uses(): number { return this._remainingUses; } get remaining_uses(): number { return this._remainingUses; }
+3 -1
View File
@@ -87,7 +87,9 @@ func (app *appContext) BasePageTemplateValues(gc *gin.Context, page Page, base g
} }
pages := PagePathsDTO{ pages := PagePathsDTO{
PagePaths: PAGES, PagePaths: PAGES,
ExternalURI: app.ExternalURI,
TrueBase: PAGES.Base,
} }
pages.Base = app.getURLBase(gc) pages.Base = app.getURLBase(gc)
switch page { switch page {