76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using GameServices;
|
|
|
|
namespace Server.Api;
|
|
|
|
[ApiController]
|
|
[Route("api/admin/cdn")]
|
|
public class CdnBrowserController : ControllerBase
|
|
{
|
|
private readonly ICdnBrowserService _cdnService;
|
|
|
|
public CdnBrowserController(ICdnBrowserService cdnService)
|
|
{
|
|
_cdnService = cdnService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if CDN browsing is configured
|
|
/// </summary>
|
|
[HttpGet("status")]
|
|
public IActionResult GetStatus()
|
|
{
|
|
return Ok(new {
|
|
configured = _cdnService.IsConfigured,
|
|
message = _cdnService.IsConfigured
|
|
? "MinIO configured and ready"
|
|
: "MinIO not configured - set AccessKey and SecretKey in appsettings"
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// List files in a CDN prefix/folder
|
|
/// </summary>
|
|
[HttpGet("list")]
|
|
public async Task<IActionResult> ListFiles(
|
|
[FromQuery] string prefix = "textures/items",
|
|
[FromQuery] int maxKeys = 100)
|
|
{
|
|
if (!_cdnService.IsConfigured)
|
|
{
|
|
return Ok(new {
|
|
files = new List<CdnFile>(),
|
|
error = "MinIO not configured"
|
|
});
|
|
}
|
|
|
|
var files = await _cdnService.ListFilesAsync(prefix, maxKeys);
|
|
return Ok(new {
|
|
prefix,
|
|
files,
|
|
count = files.Count
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// List subfolders in a prefix
|
|
/// </summary>
|
|
[HttpGet("folders")]
|
|
public async Task<IActionResult> ListFolders([FromQuery] string prefix = "textures")
|
|
{
|
|
if (!_cdnService.IsConfigured)
|
|
{
|
|
return Ok(new {
|
|
folders = new List<string>(),
|
|
error = "MinIO not configured"
|
|
});
|
|
}
|
|
|
|
var folders = await _cdnService.ListPrefixesAsync(prefix);
|
|
return Ok(new {
|
|
prefix,
|
|
folders
|
|
});
|
|
}
|
|
}
|