switchade t bootstrap och testar solid-bootstrap. konf för calibre. test m covers
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
using Bibblan.Models;
|
||||
using Bibblan.ViewModels;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Bibblan.Business.Services
|
||||
{
|
||||
public class CalibreService
|
||||
{
|
||||
private readonly BibblanOptions _options;
|
||||
CalibreContext _context;
|
||||
public CalibreService(CalibreContext context)
|
||||
public CalibreService(CalibreContext context, IOptions<BibblanOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public byte[] Cover(string path)
|
||||
{
|
||||
var fullPath = Path.Combine(_options.CalibreRoot, path, "cover.jpg");
|
||||
return File.ReadAllBytes(fullPath);
|
||||
}
|
||||
|
||||
public IQueryable<BookVm> GetAllBooks()
|
||||
{
|
||||
return from b in _context.Books
|
||||
|
@@ -8,16 +8,24 @@ namespace Bibblan.Controllers
|
||||
[Route("api/[controller]")]
|
||||
public class CalibreController : ControllerBase
|
||||
{
|
||||
CalibreService service;
|
||||
public CalibreController(CalibreContext db) {
|
||||
service = new CalibreService(db);
|
||||
CalibreService _service;
|
||||
public CalibreController(CalibreService service) {
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpGet("books")]
|
||||
public IActionResult GetBooks()
|
||||
{
|
||||
var books = service.GetAllBooks().Take(100).ToList();
|
||||
var books = _service.GetAllBooks().Take(100).ToList();
|
||||
return Ok(books);
|
||||
}
|
||||
|
||||
[HttpGet("cover")]
|
||||
public IActionResult GetCover(string path)
|
||||
{
|
||||
var bytes = _service.Cover(path);
|
||||
return File(bytes, "image/jpeg", true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
10
Server/Models/BibblanOptions.cs
Normal file
10
Server/Models/BibblanOptions.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Bibblan.Models
|
||||
{
|
||||
public class BibblanOptions
|
||||
{
|
||||
public const string Bibblan = "Bibblan";
|
||||
|
||||
public string CalibreDb { get; set; } = String.Empty;
|
||||
public string CalibreRoot { get; set; } = String.Empty;
|
||||
}
|
||||
}
|
@@ -1,14 +1,21 @@
|
||||
using Bibblan.Business.Services;
|
||||
using Bibblan.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.Configure<BibblanOptions>(
|
||||
builder.Configuration.GetSection(BibblanOptions.Bibblan));
|
||||
|
||||
builder.Services.AddScoped<CalibreService, CalibreService>();
|
||||
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
|
||||
var db = "metadata.db";
|
||||
var connection = $"Data Source={db};Mode=ReadOnly;";
|
||||
builder.Services.AddDbContext<CalibreContext>(options => options.UseSqlite(connection));
|
||||
|
@@ -5,5 +5,9 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"Bibblan": {
|
||||
"CalibreDb": "metadata.db",
|
||||
"CalibreRoot": "\\\\diskstation\\Books\\"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user