From c5efa58773fac3c730a489e8051a3d5d71466fad Mon Sep 17 00:00:00 2001 From: Andrew Schlackman <72105194+sei-aschlackman@users.noreply.github.com> Date: Thu, 23 May 2024 12:45:22 -0400 Subject: [PATCH] fixed download file url filename and port (#46) - Path.GetFilename is not cross-platform - Set UriBuilder.Port to -1 to prevent port from being included in string --- .../Domain/Vsphere/Services/VsphereService.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Player.Vm.Api/Domain/Vsphere/Services/VsphereService.cs b/src/Player.Vm.Api/Domain/Vsphere/Services/VsphereService.cs index cc43d73..869f118 100644 --- a/src/Player.Vm.Api/Domain/Vsphere/Services/VsphereService.cs +++ b/src/Player.Vm.Api/Domain/Vsphere/Services/VsphereService.cs @@ -811,11 +811,14 @@ public async Task GetVmFileUrl(Guid id, string username, string password if (_rewriteHostOptions.RewriteHost) { - var builder = new UriBuilder(fileTransferUrl); + var builder = new UriBuilder(fileTransferUrl) + { + Port = -1 + }; var query = HttpUtility.ParseQueryString(builder.Query); query[_rewriteHostOptions.RewriteHostQueryParam] = builder.Host; - var fileName = Path.GetFileName(filepath); + var fileName = this.GetFileName(filepath); query["fileName"] = fileName; builder.Query = query.ToString(); @@ -829,6 +832,12 @@ public async Task GetVmFileUrl(Guid id, string username, string password return ""; } + private string GetFileName(string filePath) + { + var fileUri = new Uri($"file://{filePath}"); + return Path.GetFileName(fileUri.ToString()); + } + private async Task WaitForVimTask(ManagedObjectReference task, VsphereConnection connection) { int i = 0;