refactor: 重构个人中心头像上传

This commit is contained in:
Argo-Tianyi 2022-01-14 18:12:09 +08:00
parent fb0d42b02e
commit a4599b835e
2 changed files with 19 additions and 2 deletions

View File

@ -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);
}

View File

@ -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);