diff options
| author | transtrike <transtrike@gmail.com> | 2021-04-02 23:17:39 +0300 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-04-02 23:17:39 +0300 |
| commit | 0c83049a3a0b417da7dcd548b1cd0992defb366f (patch) | |
| tree | b69ef0d111b7c22316a2a6603d66d85e4a568956 /src/Services/DevHive.Services | |
| parent | d672c515eb760a5351affeb5600640569ed5ee16 (diff) | |
| parent | 2448c4d31188aed26605c5e3c282bacc3bd71ae5 (diff) | |
| download | DevHive-0c83049a3a0b417da7dcd548b1cd0992defb366f.tar DevHive-0c83049a3a0b417da7dcd548b1cd0992defb366f.tar.gz DevHive-0c83049a3a0b417da7dcd548b1cd0992defb366f.zip | |
dev -> feature/profile_picture_implementation(02.03.2021)
Diffstat (limited to 'src/Services/DevHive.Services')
| -rw-r--r-- | src/Services/DevHive.Services/DevHive.Services.csproj | 8 | ||||
| -rw-r--r-- | src/Services/DevHive.Services/Services/CloudinaryService.cs | 14 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/Services/DevHive.Services/DevHive.Services.csproj b/src/Services/DevHive.Services/DevHive.Services.csproj index f51c1b6..2468711 100644 --- a/src/Services/DevHive.Services/DevHive.Services.csproj +++ b/src/Services/DevHive.Services/DevHive.Services.csproj @@ -4,15 +4,15 @@ </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0"/> - <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3"> + <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.4"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0"/> + <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.10.0"/> <PackageReference Include="AutoMapper" Version="10.1.1"/> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1"/> - <PackageReference Include="CloudinaryDotNet" Version="1.14.0"/> - <PackageReference Include="SonarAnalyzer.CSharp" Version="8.19.0.28253"/> + <PackageReference Include="CloudinaryDotNet" Version="1.15.1"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.20.0.28934"/> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\Data\DevHive.Data\DevHive.Data.csproj"/> diff --git a/src/Services/DevHive.Services/Services/CloudinaryService.cs b/src/Services/DevHive.Services/Services/CloudinaryService.cs index 57955a2..05600cc 100644 --- a/src/Services/DevHive.Services/Services/CloudinaryService.cs +++ b/src/Services/DevHive.Services/Services/CloudinaryService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.RegularExpressions; using System.Threading.Tasks; using CloudinaryDotNet; using CloudinaryDotNet.Actions; @@ -11,6 +12,10 @@ namespace DevHive.Services.Services { public class CloudinaryService : ICloudService { + // Regex for getting the filename without (final) filename extension + // So, from image.png, it will match image, and from doc.my.txt will match doc.my + private static Regex _imageRegex = new Regex(".*(?=\\.)"); + private readonly Cloudinary _cloudinary; public CloudinaryService(string cloudName, string apiKey, string apiSecret) @@ -23,7 +28,7 @@ namespace DevHive.Services.Services List<string> fileUrls = new(); foreach (var formFile in formFiles) { - string formFileId = Guid.NewGuid().ToString(); + string fileName = _imageRegex.Match(formFile.FileName).ToString(); using (var ms = new MemoryStream()) { @@ -32,8 +37,8 @@ namespace DevHive.Services.Services RawUploadParams rawUploadParams = new() { - File = new FileDescription(formFileId, new MemoryStream(formBytes)), - PublicId = formFileId, + File = new FileDescription(fileName, new MemoryStream(formBytes)), + PublicId = fileName, UseFilename = true }; @@ -47,6 +52,9 @@ namespace DevHive.Services.Services public async Task<bool> RemoveFilesFromCloud(List<string> fileUrls) { + // Workaround, this method isn't fully implemented yet + await Task.Run(null); + return true; } } |
