49 lines
2.1 KiB
C#
49 lines
2.1 KiB
C#
using MiaoJiZhang.Infrastructure.Persistence;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.EntityFrameworkCore;
|
||
|
||
namespace MiaoJiZhang.Api.Controllers;
|
||
|
||
/// <summary>公开配置:前端拉取品牌信息、可用形象/性格列表(无需管理员权限)</summary>
|
||
[ApiController]
|
||
[Route("api/public")]
|
||
public class PublicConfigController(AppDbContext db) : ControllerBase
|
||
{
|
||
/// <summary>品牌配置(App 名称、Slogan、Logo)</summary>
|
||
[HttpGet("brand")]
|
||
public async Task<IActionResult> Brand()
|
||
{
|
||
var configs = await db.AppConfigs
|
||
.Where(c => c.Key.StartsWith("brand.") || c.Key.StartsWith("feature."))
|
||
.ToDictionaryAsync(c => c.Key, c => c.Value);
|
||
bool Enabled(string key) =>
|
||
!configs.TryGetValue(key, out var value) ||
|
||
!value.Equals("false", StringComparison.OrdinalIgnoreCase);
|
||
return Ok(new
|
||
{
|
||
appName = configs.GetValueOrDefault("brand.app_name", "记之"),
|
||
slogan = configs.GetValueOrDefault("brand.slogan", ""),
|
||
logoUrl = configs.GetValueOrDefault("brand.logo_url", ""),
|
||
features = new
|
||
{
|
||
voice = Enabled("feature.voice_enabled"),
|
||
image = Enabled("feature.ocr_enabled"),
|
||
screenshot = Enabled("feature.screenshot_bookkeeping_enabled"),
|
||
stickers = Enabled("feature.sticker_enabled"),
|
||
aiAutoBook = Enabled("feature.ai_auto_book"),
|
||
},
|
||
});
|
||
}
|
||
|
||
/// <summary>可用的 AI 形象列表(按 Key 排序)</summary>
|
||
[HttpGet("avatars")]
|
||
public async Task<IActionResult> Avatars() =>
|
||
Ok(await db.AiAvatars.Where(a => a.IsEnabled).OrderBy(a => a.Key)
|
||
.Select(a => new { a.Key, a.DefaultName, a.SpeechTic, a.ImageUrl }).ToListAsync());
|
||
|
||
/// <summary>可用的 AI 性格列表(按 Key 排序)</summary>
|
||
[HttpGet("personas")]
|
||
public async Task<IActionResult> Personas() =>
|
||
Ok(await db.AiPersonas.Where(p => p.IsEnabled).OrderBy(p => p.Key)
|
||
.Select(p => new { p.Key, p.Name, p.Description, p.SampleLine }).ToListAsync());
|
||
} |