Skip to content

Commit

Permalink
fixed download file url filename and port (#46)
Browse files Browse the repository at this point in the history
- Path.GetFilename is not cross-platform
- Set UriBuilder.Port to -1 to prevent port from being included in string
  • Loading branch information
sei-aschlackman authored May 23, 2024
1 parent 51225ea commit c5efa58
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Player.Vm.Api/Domain/Vsphere/Services/VsphereService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,14 @@ public async Task<string> 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();

Expand All @@ -829,6 +832,12 @@ public async Task<string> 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<TaskInfo> WaitForVimTask(ManagedObjectReference task, VsphereConnection connection)
{
int i = 0;
Expand Down

0 comments on commit c5efa58

Please sign in to comment.