Skip to content

Commit 40a5666

Browse files
feat: Update file browser modal to support dynamic API base path and improve directory loading logic
1 parent bc991b0 commit 40a5666

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

src/XtremeIdiots.Portal.Web/Views/Shared/_FileBrowserModal.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- File Transport Browser Modal — reusable file browser component -->
2-
<div class="modal fade" id="fileBrowseModal" tabindex="-1" aria-labelledby="fileBrowseModalLabel" aria-hidden="true">
2+
<div class="modal fade" id="fileBrowseModal" tabindex="-1" aria-labelledby="fileBrowseModalLabel" aria-hidden="true" data-api-base-path="@Url.Content("~/api/file-browse")">
33
<div class="modal-dialog modal-lg modal-dialog-scrollable">
44
<div class="modal-content">
55
<div class="modal-header">

src/XtremeIdiots.Portal.Web/XtremeIdiots.Portal.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<PackageReference Include="MX.Observability.ApplicationInsights.AspNetCore" Version="1.1.1" />
4848
<PackageReference Include="MX.Api.Abstractions" Version="2.3.31" />
4949
<PackageReference Include="MX.Api.Client" Version="2.3.31" />
50-
<PackageReference Include="XtremeIdiots.Portal.Integrations.Servers.Api.Client.V1" Version="2.1.176" />
50+
<PackageReference Include="XtremeIdiots.Portal.Integrations.Servers.Api.Client.V1" Version="2.1.178" />
5151
<PackageReference Include="XtremeIdiots.Portal.Repository.Api.Client.V1" Version="2.1.240" />
5252
<PackageReference Include="XtremeIdiots.Portal.Repository.Abstractions.V1" Version="2.1.243" />
5353
<PackageReference Include="MX.GeoLocation.Api.Client.V1" Version="1.2.39" />

src/XtremeIdiots.Portal.Web/wwwroot/js/file-browse.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var _targetInputId = null;
1212
var _fileFilter = null;
1313
var _selectionMode = 'file';
14+
var _apiBasePath = '/api/file-browse';
1415
var _currentPath = '/';
1516
var _selectedPath = null;
1617
var _modal = null;
@@ -29,6 +30,14 @@
2930
_modal = new bootstrap.Modal(document.getElementById('fileBrowseModal'));
3031
}
3132

33+
var modalElement = document.getElementById('fileBrowseModal');
34+
if (modalElement) {
35+
var apiBasePath = modalElement.getAttribute('data-api-base-path');
36+
if (apiBasePath) {
37+
_apiBasePath = apiBasePath;
38+
}
39+
}
40+
3241
updateModalLabels();
3342
updateSelectButton();
3443
_modal.show();
@@ -100,25 +109,19 @@
100109
}
101110
}
102111

103-
function navigateTo(path) {
112+
function navigateTo(path, allowRootFallback) {
104113
var loading = document.getElementById('fileBrowseLoading');
105114
var error = document.getElementById('fileBrowseError');
106115
var container = document.getElementById('fileBrowseListingContainer');
116+
var normalizedPath = normalizeClientPath(path);
107117

108118
loading.style.display = '';
109119
error.style.display = 'none';
110120
container.style.display = 'none';
111-
_selectedPath = _selectionMode === 'directory' ? normalizeClientPath(path) : null;
121+
_selectedPath = _selectionMode === 'directory' ? normalizedPath : null;
112122
updateSelectButton();
113123

114-
fetch('/api/file-browse/' + _gameServerId + '/browse?path=' + encodeURIComponent(path))
115-
.then(function (response) {
116-
if (response.status === 403) throw new Error('You do not have permission to browse this server\'s files.');
117-
if (!response.ok) throw new Error('Failed to browse directory (HTTP ' + response.status + ')');
118-
var contentType = response.headers.get('content-type') || '';
119-
if (!contentType.includes('application/json')) throw new Error('Unexpected response from server.');
120-
return response.json();
121-
})
124+
loadDirectory(normalizedPath, allowRootFallback !== false)
122125
.then(function (data) {
123126
loading.style.display = 'none';
124127
container.style.display = '';
@@ -137,6 +140,21 @@
137140
});
138141
}
139142

143+
function loadDirectory(path, allowRootFallback) {
144+
return fetch(_apiBasePath + '/' + _gameServerId + '/browse?path=' + encodeURIComponent(path))
145+
.then(function (response) {
146+
if (response.status === 404 && allowRootFallback && path !== '/') {
147+
return loadDirectory('/', false);
148+
}
149+
150+
if (response.status === 403) throw new Error('You do not have permission to browse this server\'s files.');
151+
if (!response.ok) throw new Error('Failed to browse directory (HTTP ' + response.status + ')');
152+
var contentType = response.headers.get('content-type') || '';
153+
if (!contentType.includes('application/json')) throw new Error('Unexpected response from server.');
154+
return response.json();
155+
});
156+
}
157+
140158
function renderBreadcrumb(currentPath) {
141159
var breadcrumb = document.getElementById('fileBrowseBreadcrumb');
142160
breadcrumb.innerHTML = '';

0 commit comments

Comments
 (0)