develop #10

Merged
s426229 merged 80 commits from develop into master 2021-01-27 18:32:19 +01:00
12 changed files with 73 additions and 9 deletions
Showing only changes of commit dd74f059da - Show all commits

View File

@ -29,9 +29,9 @@ namespace Serwer.Api.Controllers
using (var memoryStream = new MemoryStream()) using (var memoryStream = new MemoryStream())
{ {
await image.CopyToAsync(memoryStream); await image.CopyToAsync(memoryStream);
await _imageService.Process(image.Name, image.ContentType, memoryStream.ToArray()); var response = await _imageService.Process(image.Name, image.ContentType, memoryStream.ToArray());
return Ok(response);
} }
return Ok();
} }
} }
} }

View File

@ -4,6 +4,10 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Remove="wwwroot\tessdata\eng.traineddata" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" NoWarn="NU1605" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" NoWarn="NU1605" />
@ -15,4 +19,8 @@
<ProjectReference Include="..\Serwer.Infrastructure\Serwer.Infrastructure.csproj" /> <ProjectReference Include="..\Serwer.Infrastructure\Serwer.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="wwwroot\tessdata\eng.traineddata" />
</ItemGroup>
</Project> </Project>

View File

@ -25,12 +25,14 @@ namespace Serwer.Api
{ {
public class Startup public class Startup
{ {
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration, IWebHostEnvironment env)
{ {
Configuration = configuration; Configuration = configuration;
WebRootPath = env.WebRootPath;
} }
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
protected string WebRootPath { get; set; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
@ -41,6 +43,7 @@ namespace Serwer.Api
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Serwer.Api", Version = "v1" }); c.SwaggerDoc("v1", new OpenApiInfo { Title = "Serwer.Api", Version = "v1" });
}); });
var hostEnviroment = new HostEnviroment { RootPath = WebRootPath};
var jwtSettings = new JwtSettings() var jwtSettings = new JwtSettings()
{ {
Issuer = "PoszukiwaczInc", Issuer = "PoszukiwaczInc",
@ -60,6 +63,7 @@ namespace Serwer.Api
}; };
}); });
services.AddSingleton<IHostEnviroment>(hostEnviroment);
services.AddSingleton<IMapper>(AutoMapperConfig.Initialize()); services.AddSingleton<IMapper>(AutoMapperConfig.Initialize());
services.AddSingleton<IJwtHandler, JwtHandler>(sp => new JwtHandler(jwtSettings)); services.AddSingleton<IJwtHandler, JwtHandler>(sp => new JwtHandler(jwtSettings));
services.AddScoped<IUserRepository, UserRepository>(); services.AddScoped<IUserRepository, UserRepository>();
@ -82,8 +86,6 @@ namespace Serwer.Api
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Serwer.Api v1")); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Serwer.Api v1"));
} }
app.UseRouting(); app.UseRouting();
app.UseAuthentication(); app.UseAuthentication();

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,6 @@ namespace Serwer.Infrastructure.Services
{ {
public interface IImageService public interface IImageService
{ {
Task Process(string name, string contentType, byte[] bytes); Task<string> Process(string name, string contentType, byte[] bytes);
} }
} }

View File

@ -1,19 +1,30 @@
using Serwer.Core.Domain; using Serwer.Core.Domain;
using Serwer.Infrastructure.Settings;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Tesseract;
namespace Serwer.Infrastructure.Services namespace Serwer.Infrastructure.Services
{ {
public class ImageService : IImageService public class ImageService : IImageService
{ {
private readonly ISet<File> _files = new HashSet<File>(); private readonly ISet<File> _files = new HashSet<File>();
public async Task Process(string name, string contentType, byte[] bytes) private readonly string _env;
public ImageService(IHostEnviroment hostEnviroment)
{ {
var file = File.Create(name, contentType, bytes); _env = hostEnviroment.RootPath;
await Task.FromResult(_files.Add(file)); }
public async Task<string> Process(string name, string contentType, byte[] bytes)
{
var engine = new TesseractEngine(System.IO.Path.Combine(_env, "tessdata"),"eng+equ", EngineMode.Default);
var img = Pix.LoadFromMemory(bytes);
var res = engine.Process(img);
var txt = res.GetText();
return await Task.FromResult(txt);
} }
} }
} }

View File

@ -8,10 +8,27 @@
<PackageReference Include="AutoMapper" Version="10.1.1" /> <PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" /> <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
<PackageReference Include="Tesseract" Version="4.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Serwer.Core\Serwer.Core.csproj" /> <ProjectReference Include="..\Serwer.Core\Serwer.Core.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Remove="C:\Users\ppopo\.nuget\packages\tesseract\4.1.1\build\\..\x64\leptonica-1.80.0.dll" />
</ItemGroup>
<ItemGroup>
<None Remove="C:\Users\ppopo\.nuget\packages\tesseract\4.1.1\build\\..\x64\tesseract41.dll" />
</ItemGroup>
<ItemGroup>
<None Remove="C:\Users\ppopo\.nuget\packages\tesseract\4.1.1\build\\..\x86\leptonica-1.80.0.dll" />
</ItemGroup>
<ItemGroup>
<None Remove="C:\Users\ppopo\.nuget\packages\tesseract\4.1.1\build\\..\x86\tesseract41.dll" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Settings
{
public class HostEnviroment: IHostEnviroment
{
public string RootPath { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Settings
{
public interface IHostEnviroment
{
string RootPath { get; set; }
}
}