refactor: 重构个人中心头像上传
This commit is contained in:
parent
fb0d42b02e
commit
a4599b835e
|
@ -0,0 +1,17 @@
|
|||
namespace BootstrapAdmin.Web.Extensions;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class WebHostExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="webHost"></param>
|
||||
/// <param name="logoFolder"></param>
|
||||
/// <param name="logoFile"></param>
|
||||
/// <returns></returns>
|
||||
public static string CombineLogoFile(this IWebHostEnvironment webHost, string logoFolder, string logoFile) => Path.Combine(webHost.WebRootPath, logoFolder.Replace("/", "\\").TrimStart('\\'), logoFile);
|
||||
|
||||
}
|
|
@ -131,7 +131,7 @@ public partial class Profiles
|
|||
{
|
||||
// 保存到物理文件
|
||||
var logoFile = $"{CurrentUser.UserName}{Path.GetExtension(file.OriginFileName)}";
|
||||
var fileName = Path.Combine(WebHost.WebRootPath, DefaultLogoFolder.Replace("/", "\\").TrimStart('\\'), logoFile);
|
||||
var fileName = WebHost.CombineLogoFile(DefaultLogoFolder, logoFile);
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
|
@ -163,7 +163,7 @@ public partial class Profiles
|
|||
var logoFile = file.FileName;
|
||||
if (!string.IsNullOrEmpty(logoFile))
|
||||
{
|
||||
var fileName = Path.Combine(WebHost.WebRootPath, DefaultLogoFolder.Replace("/", "\\").TrimStart('\\'), logoFile);
|
||||
var fileName = WebHost.CombineLogoFile(DefaultLogoFolder, logoFile);
|
||||
if (!logoFile.Equals(DefaultLogo, StringComparison.OrdinalIgnoreCase) && File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
|
|
Loading…
Reference in New Issue