diff --git a/archive/js/app.js b/archive/js/app.js index e7500de..920b8cf 100644 --- a/archive/js/app.js +++ b/archive/js/app.js @@ -74,14 +74,39 @@ } // Auto-connect to the HTTP server - // Derives the base URL from the current page's location + // Derives the base URL from the current page's location. + // + // Two URL shapes can serve the archive tool: + // (a) Filename-style: /Project-1/Archive/PartyA/archive.html + // (b) Auto-served: /Project-1/Archive/PartyA/Issued + // + // For (a) the URL ends with a filename (`*.html`) and the + // archive's scan root is the parent directory. For (b) the URL + // path IS the directory; trying to strip the last segment would + // wrongly scan the parent. Detect (b) by checking whether the + // path's last segment looks like a file (has a dot + extension). async function autoConnectHttpSource() { var href = window.location.href; // Strip query string and fragment href = href.split('?')[0].split('#')[0]; - // Strip the filename to get the directory - var lastSlash = href.lastIndexOf('/'); - var baseUrl = (lastSlash >= 0) ? href.substring(0, lastSlash + 1) : href + '/'; + var baseUrl; + if (href.endsWith('/')) { + // Directory URL, e.g. /Project-1/archive/ or / + baseUrl = href; + } else { + var lastSlash = href.lastIndexOf('/'); + var lastSegment = lastSlash >= 0 ? href.substring(lastSlash + 1) : href; + // A "filename" has a dot in its last segment. A bare + // directory name (e.g. "Issued") doesn't. Don't be fooled + // by dots in domain names — lastSlash is past the host. + if (lastSegment.indexOf('.') >= 0) { + baseUrl = href.substring(0, lastSlash + 1); + } else { + // Auto-served at a directory URL with no trailing + // slash. Treat the whole path as the scan root. + baseUrl = href + '/'; + } + } // Multi-project mode is opt-in via ?projects= in the URL. // ?projects= absent → not multi-project; scan whatever the URL