Skip to content

Commit 9dcd990

Browse files
committed
fix: reverse proxy support
1 parent 640e586 commit 9dcd990

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

TelegramDownloader/Pages/Partials/impl/LocalFileManagerImpl.razor

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
@inject ILogger<FileManager> Logger;
1212
@inject NavigationManager NavManager
1313

14-
@* Loading while detecting viewport *@
15-
@if (!_viewportDetected)
14+
@* Loading while detecting viewport and base URL *@
15+
@if (!_viewportDetected || string.IsNullOrEmpty(_baseUrl))
1616
{
1717
<div style="display: flex; justify-content: center; align-items: center; height: 200px;">
1818
<div class="spinner-border text-primary" role="status">
@@ -21,8 +21,8 @@
2121
</div>
2222
}
2323

24-
@* Desktop FileManager - only render when viewport detected and not on mobile *@
25-
@if (_viewportDetected && !_isMobileView)
24+
@* Desktop FileManager - only render when viewport detected, base URL ready, and not on mobile *@
25+
@if (_viewportDetected && !string.IsNullOrEmpty(_baseUrl) && !_isMobileView)
2626
{
2727
<SfFileManager @ref="FileManager" ID="localfm" TValue="FileManagerDirectoryContent">
2828
<FileManagerAjaxSettings Url="@FileOperationsUrl"
@@ -39,7 +39,7 @@
3939
}
4040

4141
@* Mobile FileManager *@
42-
@if (_viewportDetected && _isMobileView)
42+
@if (_viewportDetected && !string.IsNullOrEmpty(_baseUrl) && _isMobileView)
4343
{
4444
<div class="mobile-fm-container">
4545
<MobileFileManager @ref="mobileFileManager"
@@ -101,11 +101,12 @@
101101
private bool _viewportDetected = false;
102102
private const int MobileBreakpoint = 1920; // Custom breakpoint for mobile file manager
103103
104-
// Use NavigationManager.BaseUri to build absolute URLs that work with both direct access and reverse proxies
105-
private string FileOperationsUrl => $"{NavManager.BaseUri}api/file/FileOperations";
106-
private string UploadUrl => $"{NavManager.BaseUri}api/file/Upload";
107-
private string DownloadUrl => $"{NavManager.BaseUri}api/file/Download";
108-
private string GetImageUrl => $"{NavManager.BaseUri}api/file/GetImage";
104+
// URLs will be set from JavaScript to get the actual browser origin
105+
private string _baseUrl = "";
106+
private string FileOperationsUrl => $"{_baseUrl}/api/file/FileOperations";
107+
private string UploadUrl => $"{_baseUrl}/api/file/Upload";
108+
private string DownloadUrl => $"{_baseUrl}/api/file/Download";
109+
private string GetImageUrl => $"{_baseUrl}/api/file/GetImage";
109110

110111

111112
public List<ToolBarItemModel> Items = new List<ToolBarItemModel>(){
@@ -150,8 +151,16 @@
150151
{
151152
_firstRenderComplete = true;
152153
_currentInstance = this;
154+
155+
// Get actual browser origin via JavaScript (works correctly with reverse proxies)
156+
_baseUrl = await JSRuntime.InvokeAsync<string>("eval", "window.location.origin");
157+
Logger.LogInformation($"LocalFileManager BaseUrl: {_baseUrl}");
158+
153159
// Detect viewport size on first render
154160
await DetectMobileView();
161+
162+
// Force re-render to apply the URLs
163+
StateHasChanged();
155164
}
156165

157166
if (_needsRefresh && FileManager != null)

0 commit comments

Comments
 (0)