Implement debug API for portal files and enhance file listing functionality: add a no-auth endpoint for troubleshooting, improve error handling, and streamline the portal files listing logic. Update HTML template to handle session expiration gracefully and provide a read-only fallback for unauthenticated users.
This commit is contained in:
@@ -85,6 +85,7 @@
|
||||
<script>
|
||||
function authFetch(url, opts) {
|
||||
opts = opts || {};
|
||||
opts.credentials = opts.credentials || 'same-origin';
|
||||
return fetch(url, opts).then(function(r) {
|
||||
if (r.status === 401) { window.location = '/login?next=' + encodeURIComponent(window.location.pathname); return Promise.reject(new Error('Login required')); }
|
||||
return r;
|
||||
@@ -167,8 +168,23 @@
|
||||
|
||||
function fetchPortal() {
|
||||
var url = '/api/portal-files';
|
||||
if (currentPath) url += '?path=' + encodeURIComponent(currentPath);
|
||||
authFetch(url).then(function(r) { return r.json(); }).then(renderPortal).catch(function() {});
|
||||
if (currentPath) url += (url.indexOf('?') >= 0 ? '&' : '?') + 'path=' + encodeURIComponent(currentPath);
|
||||
authFetch(url).then(function(r) { return r.json(); }).then(renderPortal).catch(function(err) {
|
||||
document.getElementById('portalEmpty').style.display = 'block';
|
||||
document.getElementById('portalEmpty').textContent = 'Could not load list (session may have expired). Trying read-only list…';
|
||||
var fallbackUrl = '/api/portal-files?debug=1' + (currentPath ? '&path=' + encodeURIComponent(currentPath) : '');
|
||||
fetch(fallbackUrl).then(function(r) { return r.json(); }).then(function(data) {
|
||||
if (data.items && data.items.length) {
|
||||
document.getElementById('portalEmpty').style.display = 'none';
|
||||
renderPortal(data);
|
||||
document.getElementById('portalDir').textContent = (data.portal_files_dir || '—') + ' (read-only; log in to edit)';
|
||||
} else {
|
||||
document.getElementById('portalEmpty').textContent = 'Server sees ' + (data.items ? data.items.length : 0) + ' item(s) at ' + (data.portal_files_dir || '?') + '. Log in to see and edit.';
|
||||
}
|
||||
}).catch(function() {
|
||||
document.getElementById('portalEmpty').textContent = 'Could not load list. Log out and log in again, then refresh.';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('newFolderBtn').onclick = function() {
|
||||
|
||||
Reference in New Issue
Block a user