mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
# Added - Added: Ability to check for updates (stable-only) and be notified with a changelog. This is a first pass implementation. - Added: Ability to use SignalR within Kavita (websockets) ===================================== * (some debug code present). Implemented the ability to check and log if the server is up to date or not. * Fixed a bug for dark mode where anchor buttons wouldn't have the correct font color. Suppress filter/sort button if there is no filters to show. Debug: Active indicators for users currently on your server. Refactored code to send update notification only to admins. Admins now get a popup where they can open the Github release (docker users can just close). * Fixed an issue where getLibraryNames on first load would call for as many cards there was on the screen. Now we call it much earlier and the data is cached faster. * Fixed a dark mode bug from previous commit * Release notes is now rendered markdown * Implemented the ability to check for an update ad-hoc. Response will come via websocket to all admins. * Fixed a missing padding * Cleanup, added some temp code to carousel * Cleaned up old stat stuff from dev config and added debug only flow for checking for update * Misc cleanup * Added readonly to one variable * Fixed In Progress not showing for all series due to pagination bug * Fixed the In progress API returning back series that had another users progress on them. Added SplitQuery which speeds up query significantly. * SplitQuery in GetRecentlyAdded for a speed increase on API. Fixed the logic on VersionUpdaterService to properly send on non-dev systems. Disable the check button once it's triggered once since the API does a task, so it can't return anything. * Cleaned up the admin actions to be more friendly on mobile. * Cleaned up the message as we wait for SingalR to notify the user * more textual changes * Code smells
113 lines
3.7 KiB
C#
113 lines
3.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using API.DTOs.Stats;
|
|
using API.Extensions;
|
|
using API.Interfaces;
|
|
using API.Interfaces.Services;
|
|
using API.Services.Tasks;
|
|
using Kavita.Common;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
[Authorize(Policy = "RequireAdminRole")]
|
|
public class ServerController : BaseApiController
|
|
{
|
|
private readonly IHostApplicationLifetime _applicationLifetime;
|
|
private readonly ILogger<ServerController> _logger;
|
|
private readonly IConfiguration _config;
|
|
private readonly IBackupService _backupService;
|
|
private readonly IArchiveService _archiveService;
|
|
private readonly ICacheService _cacheService;
|
|
private readonly ITaskScheduler _taskScheduler;
|
|
|
|
public ServerController(IHostApplicationLifetime applicationLifetime, ILogger<ServerController> logger, IConfiguration config,
|
|
IBackupService backupService, IArchiveService archiveService, ICacheService cacheService, ITaskScheduler taskScheduler)
|
|
{
|
|
_applicationLifetime = applicationLifetime;
|
|
_logger = logger;
|
|
_config = config;
|
|
_backupService = backupService;
|
|
_archiveService = archiveService;
|
|
_cacheService = cacheService;
|
|
_taskScheduler = taskScheduler;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to Restart the server. Does not work, will shutdown the instance.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("restart")]
|
|
public ActionResult RestartServer()
|
|
{
|
|
_logger.LogInformation("{UserName} is restarting server from admin dashboard", User.GetUsername());
|
|
|
|
_applicationLifetime.StopApplication();
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Performs an ad-hoc cleanup of Cache
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("clear-cache")]
|
|
public ActionResult ClearCache()
|
|
{
|
|
_logger.LogInformation("{UserName} is clearing cache of server from admin dashboard", User.GetUsername());
|
|
_cacheService.Cleanup();
|
|
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Performs an ad-hoc backup of the Database
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("backup-db")]
|
|
public ActionResult BackupDatabase()
|
|
{
|
|
_logger.LogInformation("{UserName} is backing up database of server from admin dashboard", User.GetUsername());
|
|
_backupService.BackupDatabase();
|
|
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns non-sensitive information about the current system
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("server-info")]
|
|
public ActionResult<ServerInfoDto> GetVersion()
|
|
{
|
|
return Ok(StatsService.GetServerInfo());
|
|
}
|
|
|
|
[HttpGet("logs")]
|
|
public async Task<ActionResult> GetLogs()
|
|
{
|
|
var files = _backupService.LogFiles(_config.GetMaxRollingFiles(), _config.GetLoggingFileName());
|
|
try
|
|
{
|
|
var (fileBytes, zipPath) = await _archiveService.CreateZipForDownload(files, "logs");
|
|
return File(fileBytes, "application/zip", Path.GetFileName(zipPath));
|
|
}
|
|
catch (KavitaException ex)
|
|
{
|
|
return BadRequest(ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost("check-update")]
|
|
public ActionResult CheckForUpdates()
|
|
{
|
|
_taskScheduler.CheckForUpdate();
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|