Add setup step in /info

This commit is contained in:
Zoe Roux 2024-05-26 00:49:32 +02:00
parent c35e41aebe
commit db2204258a
No known key found for this signature in database
3 changed files with 41 additions and 2 deletions

View File

@ -46,6 +46,11 @@ public class ServerInfo
/// The list of permissions available for the guest account.
/// </summary>
public List<string> GuestPermissions { get; set; }
/// <summary>
/// Check if kyoo's setup is finished.
/// </summary>
public SetupStep SetupStatus { get; set; }
}
public class OidcInfo
@ -60,3 +65,24 @@ public class OidcInfo
/// </summary>
public string? LogoUrl { get; set; }
}
/// <summary>
/// Check if kyoo's setup is finished.
/// </summary>
public enum SetupStep
{
/// <summary>
/// No admin account exists, create an account before exposing kyoo to the internet!
/// </summary>
MissingAdminAccount,
/// <summary>
/// No video was registered on kyoo, have you configured the rigth library path?
/// </summary>
NoVideoFound,
/// <summary>
/// Setup finished!
/// </summary>
Done,
}

View File

@ -25,6 +25,7 @@ using System.Threading.Tasks;
using Dapper;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Kyoo.Authentication.Models;
using Kyoo.Postgresql;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@ -129,6 +130,15 @@ public class MiscRepository(
.OrderBy(x => x.RefreshDate)
.ToListAsync();
}
public async Task<SetupStep> GetSetupStep()
{
bool hasUser = await context.Users.AnyAsync();
if (!hasUser)
return SetupStep.MissingAdminAccount;
bool hasItem = await context.Movies.AnyAsync() || await context.Shows.AnyAsync();
return hasItem ? SetupStep.Done : SetupStep.NoVideoFound;
}
}
public class RefreshableItem

View File

@ -18,8 +18,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Authentication.Models;
using Kyoo.Core.Controllers;
using Microsoft.AspNetCore.Mvc;
using static Kyoo.Abstractions.Models.Utils.Constants;
@ -31,9 +33,9 @@ namespace Kyoo.Authentication.Views;
[ApiController]
[Route("info")]
[ApiDefinition("Info", Group = UsersGroup)]
public class InfoApi(PermissionOption options) : ControllerBase
public class InfoApi(PermissionOption options, MiscRepository info) : ControllerBase
{
public ActionResult<ServerInfo> GetInfo()
public async Task<ActionResult<ServerInfo>> GetInfo()
{
return Ok(
new ServerInfo()
@ -48,6 +50,7 @@ public class InfoApi(PermissionOption options) : ControllerBase
new() { DisplayName = x.Value.DisplayName, LogoUrl = x.Value.LogoUrl, }
))
.ToDictionary(x => x.Key, x => x.Value),
SetupStatus = await info.GetSetupStep()
}
);
}