mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add setup step in /info
This commit is contained in:
parent
c35e41aebe
commit
db2204258a
@ -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,
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user