-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jijie Chen
committed
Jul 30, 2019
1 parent
85a1aad
commit 1cb0998
Showing
3 changed files
with
18 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 7 additions & 2 deletions
9
...cussion.Web/Services/UserManagement/Avatar/UrlGenerators/StorageFileAvatarUrlGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
using Discussion.Core.Models.UserAvatar; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Discussion.Web.Services.UserManagement.Avatar.UrlGenerators | ||
{ | ||
public class StorageFileAvatarUrlGenerator : IUserAvatarUrlGenerator<StorageFileAvatar> | ||
{ | ||
private readonly IUrlHelper _urlHelper; | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
|
||
public StorageFileAvatarUrlGenerator(IUrlHelper urlHelper) | ||
public StorageFileAvatarUrlGenerator(IUrlHelper urlHelper, IHttpContextAccessor httpContextAccessor) | ||
{ | ||
_urlHelper = urlHelper; | ||
_httpContextAccessor = httpContextAccessor; | ||
} | ||
|
||
public string GetUserAvatarUrl(StorageFileAvatar avatar) | ||
{ | ||
var request = _httpContextAccessor.HttpContext.Request; | ||
// ReSharper disable Mvc.ActionNotResolved | ||
// ReSharper disable Mvc.ControllerNotResolved | ||
return _urlHelper.Action("DownloadFile", | ||
"Common", | ||
new {slug = avatar.StorageFileSlug}, | ||
_urlHelper.ActionContext.HttpContext.Request.Scheme); | ||
request.Scheme, | ||
request.Host.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters