Holiday Bugfixes (#1762)

* Don't show "not much going on" when we are actively downloading

* Swipe to paginate is now behind a flag in the user preferences.

* Added a new server setting for host name, if the server sits behind a reverse proxy. If this is set, email link generation will use it and will not perform any checks on accessibility (thus email will always send)

* Refactored the code that checks if the server is accessible to check if host name is set, and thus return rue if so.

* Added back the system drawing library for markdown parsing.

* Fixed a validation error

* Fixed a bug where folder watching could get re-triggered when it was disabled at a server level.

* Made the manga reader loader absolute positioned for better visibility

* Indentation
This commit is contained in:
Joe Milazzo 2023-01-30 00:50:19 -08:00 committed by GitHub
parent 2a47029209
commit 5e9bbd0768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 1986 additions and 49 deletions

View file

@ -2,12 +2,15 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using API.Constants;
using API.Data;
using API.Entities;
using API.Errors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace API.Services;
@ -20,6 +23,8 @@ public interface IAccountService
Task<IEnumerable<ApiException>> ValidateEmail(string email);
Task<bool> HasBookmarkPermission(AppUser user);
Task<bool> HasDownloadPermission(AppUser user);
Task<bool> CheckIfAccessible(HttpRequest request);
Task<string> GenerateEmailLink(HttpRequest request, string token, string routePart, string email, bool withHost = true);
}
public class AccountService : IAccountService
@ -27,13 +32,44 @@ public class AccountService : IAccountService
private readonly UserManager<AppUser> _userManager;
private readonly ILogger<AccountService> _logger;
private readonly IUnitOfWork _unitOfWork;
private readonly IHostEnvironment _environment;
private readonly IEmailService _emailService;
public const string DefaultPassword = "[k.2@RZ!mxCQkJzE";
private const string LocalHost = "localhost:4200";
public AccountService(UserManager<AppUser> userManager, ILogger<AccountService> logger, IUnitOfWork unitOfWork)
public AccountService(UserManager<AppUser> userManager, ILogger<AccountService> logger, IUnitOfWork unitOfWork,
IHostEnvironment environment, IEmailService emailService)
{
_userManager = userManager;
_logger = logger;
_unitOfWork = unitOfWork;
_environment = environment;
_emailService = emailService;
}
/// <summary>
/// Checks if the instance is accessible. If the host name is filled out, then it will assume it is accessible as email generation will use host name.
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<bool> CheckIfAccessible(HttpRequest request)
{
var host = _environment.IsDevelopment() ? LocalHost : request.Host.ToString();
return !string.IsNullOrEmpty((await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).HostName) || await _emailService.CheckIfAccessible(host);
}
public async Task<string> GenerateEmailLink(HttpRequest request, string token, string routePart, string email, bool withHost = true)
{
var serverSettings = await _unitOfWork.SettingsRepository.GetSettingsDtoAsync();
var host = _environment.IsDevelopment() ? LocalHost : request.Host.ToString();
var basePart = $"{request.Scheme}://{host}{request.PathBase}/";
if (!string.IsNullOrEmpty(serverSettings.HostName))
{
basePart = serverSettings.HostName;
}
if (withHost) return $"{basePart}/registration/{routePart}?token={HttpUtility.UrlEncode(token)}&email={HttpUtility.UrlEncode(email)}";
return $"registration/{routePart}?token={HttpUtility.UrlEncode(token)}&email={HttpUtility.UrlEncode(email)}";
}
public async Task<IEnumerable<ApiException>> ChangeUserPassword(AppUser user, string newPassword)