develop #10
@ -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();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
@ -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();
|
||||||
|
BIN
Serwer/Serwer.Api/wwwroot/sample/wielomian.png
Normal file
BIN
Serwer/Serwer.Api/wwwroot/sample/wielomian.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 932 B |
BIN
Serwer/Serwer.Api/wwwroot/tessdata/eng.traineddata
Normal file
BIN
Serwer/Serwer.Api/wwwroot/tessdata/eng.traineddata
Normal file
Binary file not shown.
BIN
Serwer/Serwer.Api/wwwroot/tessdata/equ.traineddata
Normal file
BIN
Serwer/Serwer.Api/wwwroot/tessdata/equ.traineddata
Normal file
Binary file not shown.
BIN
Serwer/Serwer.Api/wwwroot/tessdata/pol.traineddata
Normal file
BIN
Serwer/Serwer.Api/wwwroot/tessdata/pol.traineddata
Normal file
Binary file not shown.
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
13
Serwer/Serwer.Infrastructure/Settings/HostEnviroment.cs
Normal file
13
Serwer/Serwer.Infrastructure/Settings/HostEnviroment.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
13
Serwer/Serwer.Infrastructure/Settings/IHostEnviroment.cs
Normal file
13
Serwer/Serwer.Infrastructure/Settings/IHostEnviroment.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user