diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-10-15 19:09:41 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-10-15 19:09:41 -0500 |
| commit | 8663b3fac9597f7b0c6ffd8081b99c761a18b326 (patch) | |
| tree | 6780fbd2e1b950f60f2bf7f57dcd963d853df50b /src/slskd/Network/NetworkClient.cs | |
| parent | 7e34146d679b3b6c1692a41f1ea9ab4547889a43 (diff) | |
| download | slskd-8663b3fac9597f7b0c6ffd8081b99c761a18b326.tar.gz | |
add file info handling
Diffstat (limited to 'src/slskd/Network/NetworkClient.cs')
| -rw-r--r-- | src/slskd/Network/NetworkClient.cs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/slskd/Network/NetworkClient.cs b/src/slskd/Network/NetworkClient.cs index d171e9b9..6e4e4dca 100644 --- a/src/slskd/Network/NetworkClient.cs +++ b/src/slskd/Network/NetworkClient.cs @@ -156,7 +156,7 @@ namespace slskd.Network Log.Information("Upload shares succeeded"); } - private async Task HandleFileRequest(Guid id, string filename) + private async Task HandleFileRequest(string filename, Guid id) { Log.Information("Network controller requested file {Filename} with ID {Id}", filename, id); @@ -164,7 +164,7 @@ namespace slskd.Network { var localFilename = await Shares.ResolveFileAsync(filename); - var localFileInfo = new FileInfo(filename); + var localFileInfo = new FileInfo(localFilename); if (!localFileInfo.Exists) { @@ -202,6 +202,25 @@ namespace slskd.Network } } + private async Task HandleFileInfoRequest(string filename, Guid id) + { + Log.Information("Network controller requested file info for {Filename} with ID {Id}", filename, id); + + try + { + var localFilename = await Shares.ResolveFileAsync(filename); + + var localFileInfo = new FileInfo(localFilename); + + await HubConnection.InvokeAsync(nameof(NetworkHub.ReturnFileInfo), id, localFileInfo.Exists, localFileInfo.Length); + } + catch (Exception ex) + { + Log.Error(ex, "Failed to handle file info request: {Message}", ex.Message); + await HubConnection.InvokeAsync(nameof(NetworkHub.ReturnFileInfo), id, false, 0); + } + } + private async Task HandleAuthenticationChallenge(string challengeToken) { Log.Debug("Network controller sent an authentication challenge"); @@ -296,7 +315,7 @@ namespace slskd.Network HubConnection.Reconnecting += HubConnection_Reconnecting; HubConnection.Closed += HubConnection_Closed; - HubConnection.On<Guid, string>(NetworkHubMethods.RequestFile, HandleFileRequest); + HubConnection.On<string, Guid>(NetworkHubMethods.RequestFile, HandleFileRequest); HubConnection.On<string>(NetworkHubMethods.AuthenticationChallenge, HandleAuthenticationChallenge); LastOptionsHash = optionsHash; |
