From 8ff670c5643cefdcb26d841123e5b71523dcb4e8 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 22 Sep 2024 09:47:02 +0200 Subject: [PATCH] fix(gui): get version from header when not authenticated (#9724) ### Purpose Since #8757, the Syncthing GUI now has an unauthenticated state. One consequence of this is that `$scope.versionBase()` is not initialized while unauthenticated, which causes the `docsURL` function to truncate links to just `https://docs.syncthing.net`/, discarding the section path. This currently affects at least the "Help > Introduction" link reachable both while logged in and not. The issue is exacerbated in https://github.com/syncthing/syncthing/pull/9175 where we sometimes want to show additional contextual help links from the login page to particular sections of the docs. I don't think it's any worse to try to preserve the section path even without an explicit version tag, than to fall back to just the host and lose all context the link was attempting to provide. ### Testing - On commit b1ed2802fb944bb5e3dea3b4a80c05db3a9df7c3 (before): - Open the GUI, set a username and log out. - Open the "Help" drop-down. The "Introduction" item links to: https://docs.syncthing.net/ - Log in. - Open the "Help" drop-down. The "Introduction" item links to: https://docs.syncthing.net/v1.27.10/intro/gui - On commit 44fef317800ce1d0795b4e2ebfbd5e9deda849ef (after): - Open the GUI, set a username and log out. - Open the "Help" drop-down. The "Introduction" item links to: https://docs.syncthing.net/intro/gui - Log in. - Open the "Help" drop-down. The "Introduction" item links to: https://docs.syncthing.net/v1.27.10/intro/gui ### Screenshots This is a GUI change, but affecting only URLs in the markup with no visual changes. ### Drawbacks If a `docsURL` call generates a versionless link to a docs page that doesn't exist on https://docs.syncthing.net - presumably because Syncthing is not the latest version and links to a deleted page? - then this will lead to GitHub's generic 404 page with no link to the Syncthing docs root. Before, any versionless link would also be a pathless link, leading to the Syncthing docs root instead of a 404 page. --- gui/default/syncthing/core/syncthingController.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gui/default/syncthing/core/syncthingController.js b/gui/default/syncthing/core/syncthingController.js index 57309cee2..517663d94 100644 --- a/gui/default/syncthing/core/syncthingController.js +++ b/gui/default/syncthing/core/syncthingController.js @@ -16,6 +16,15 @@ angular.module('syncthing.core') LocaleService.autoConfigLocale(); if (!$scope.authenticated) { + function setVersionFromHeader(_data, _status, headers) { + var version = headers('X-Syncthing-Version'); + if (version) { + $scope.version = { version: version }; + } + } + // Get index.html again (likely cached) to retrieve the version header + $http.get('').success(setVersionFromHeader).error(setVersionFromHeader); + // Can't proceed yet - wait for the page reload after successful login. return; }