Browse Source

更改用户头像地址为oss上传地址

zhontai 2 years ago
parent
commit
0ce360823c

+ 1 - 1
build/pkg.props

@@ -1,6 +1,6 @@
 <Project>
   <PropertyGroup>
-    <Version>3.3.4</Version>
+    <Version>3.3.5</Version>
 	<TargetFramework>net7.0</TargetFramework>
 	<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
 	<GenerateDocumentationFile>true</GenerateDocumentationFile>

+ 5 - 7
src/platform/ZhonTai.Admin/Services/User/UserService.cs

@@ -30,6 +30,7 @@ using ZhonTai.Admin.Domain.User.Dto;
 using ZhonTai.Admin.Domain.RoleOrg;
 using ZhonTai.Admin.Domain.UserOrg;
 using Microsoft.AspNetCore.Identity;
+using ZhonTai.Admin.Services.File;
 
 namespace ZhonTai.Admin.Services.User;
 
@@ -49,8 +50,8 @@ public partial class UserService : BaseService, IUserService, IDynamicApi
     private IUserRoleRepository _userRoleRepository => LazyGetRequiredService<IUserRoleRepository>();
     private IRoleOrgRepository _roleOrgRepository => LazyGetRequiredService<IRoleOrgRepository>();
     private IUserOrgRepository _userOrgRepository => LazyGetRequiredService<IUserOrgRepository>();
-
     private IPasswordHasher<UserEntity> _passwordHasher => LazyGetRequiredService<IPasswordHasher<UserEntity>>();
+    private IFileService _fileService => LazyGetRequiredService<IFileService>();
 
     public UserService()
     {
@@ -723,16 +724,13 @@ public partial class UserService : BaseService, IUserService, IDynamicApi
     [Login]
     public async Task<string> AvatarUpload([FromForm] IFormFile file, bool autoUpdate = false)
     {
-        var uploadConfig = LazyGetRequiredService<IOptionsMonitor<UploadConfig>>().CurrentValue;
-        var uploadHelper = LazyGetRequiredService<UploadHelper>();
-        var config = uploadConfig.Avatar;
-        var fileInfo = await uploadHelper.UploadAsync(file, config, new { User.Id });
+        var fileInfo = await _fileService.UploadFileAsync(file);
         if (autoUpdate)
         {
             var entity = await _userRepository.GetAsync(User.Id);
-            entity.Avatar = fileInfo.FileRelativePath;
+            entity.Avatar = fileInfo.LinkUrl;
             await _userRepository.UpdateAsync(entity);
         }
-        return fileInfo.FileRelativePath;
+        return fileInfo.LinkUrl;
     }
 }

+ 8 - 8
src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj

@@ -16,9 +16,9 @@
 		<PackageReference Include="CSRedisCore" Version="3.8.670" />
 		<PackageReference Include="Caching.CSRedis" Version="3.8.670" />
 		<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
-		<PackageReference Include="FreeSql" Version="3.2.688" />
+		<PackageReference Include="FreeSql" Version="3.2.689" />
 		<PackageReference Include="FreeSql.Cloud" Version="1.6.3" />
-		<PackageReference Include="FreeSql.Repository" Version="3.2.688" />
+		<PackageReference Include="FreeSql.Repository" Version="3.2.689" />
 		<PackageReference Include="FreeScheduler" Version="1.0.9" />
 		<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
 		<PackageReference Include="Mapster" Version="7.3.0" />
@@ -37,12 +37,12 @@
 	</ItemGroup>
 
 	<ItemGroup Condition="'$(Configuration)'=='Debug'">
-		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.688" />
-		<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.688" />
-		<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.688" />
-		<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.688" />
-		<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.688" />
-		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.688" />
+		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.689" />
+		<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.689" />
 	</ItemGroup>
 
 	<ItemGroup>