mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
* Corrected tooltip for Cache * Ensure we sync the DB to what's in appsettings.json for Cache key. * Change the fingerprinting method for Windows installs exclusively to avoid churn due to how security updates are handled. * Hooked up the ability to see where reviews are from via an icon on the review card, rather than having to click or know that MAL has "external Review" as title. * Updated FAQ for Kavita+ to link directly to the FAQ * Added the ability for all ratings on a series to be shown to the user. Added favorite count on AL and MAL * Cleaned up so the check for Kavita+ license doesn't seem like it's running when no license is registered. * Tweaked the test instance buy link to test new product.
80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using API.Constants;
|
|
using API.Data;
|
|
using API.DTOs.Account;
|
|
using API.DTOs.License;
|
|
using API.Entities.Enums;
|
|
using API.Services.Plus;
|
|
using Kavita.Common;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Controllers;
|
|
|
|
public class LicenseController : BaseApiController
|
|
{
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
private readonly ILogger<LicenseController> _logger;
|
|
private readonly ILicenseService _licenseService;
|
|
|
|
public LicenseController(IUnitOfWork unitOfWork, ILogger<LicenseController> logger,
|
|
ILicenseService licenseService)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
_logger = logger;
|
|
_licenseService = licenseService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if the user's license is valid or not
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("valid-license")]
|
|
[ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)]
|
|
public async Task<ActionResult<bool>> HasValidLicense(bool forceCheck = false)
|
|
{
|
|
return Ok(await _licenseService.HasActiveLicense(forceCheck));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Has any license
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Authorize("RequireAdminRole")]
|
|
[HttpGet("has-license")]
|
|
[ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)]
|
|
public async Task<ActionResult<bool>> HasLicense()
|
|
{
|
|
return Ok(!string.IsNullOrEmpty(
|
|
(await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey)).Value));
|
|
}
|
|
|
|
[Authorize("RequireAdminRole")]
|
|
[HttpDelete]
|
|
[ResponseCache(CacheProfileName = ResponseCacheProfiles.LicenseCache)]
|
|
public async Task<ActionResult> RemoveLicense()
|
|
{
|
|
_logger.LogInformation("Removing license on file for Server");
|
|
var setting = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey);
|
|
setting.Value = null;
|
|
_unitOfWork.SettingsRepository.Update(setting);
|
|
await _unitOfWork.CommitAsync();
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates server license
|
|
/// </summary>
|
|
/// <remarks>Caches the result</remarks>
|
|
/// <returns></returns>
|
|
[Authorize("RequireAdminRole")]
|
|
[HttpPost]
|
|
public async Task<ActionResult> UpdateLicense(UpdateLicenseDto dto)
|
|
{
|
|
await _licenseService.AddLicense(dto.License.Trim(), dto.Email.Trim());
|
|
return Ok();
|
|
}
|
|
}
|