增加移动端,可以查看统计数据和日志

This commit is contained in:
jianzhichu
2025-12-11 22:16:03 +08:00
parent fc7886a76e
commit d0c4322907
16 changed files with 1531 additions and 164 deletions
+57 -3
View File
@@ -12,12 +12,12 @@ namespace dy.net.Controllers
public class LogsController : ControllerBase
{
private readonly IWebHostEnvironment webHostEnvironment;
private readonly DouyinHttpClientService douyinHttpClientService;
private readonly LogInfoService logInfoService;
public LogsController(IWebHostEnvironment webHostEnvironment,DouyinHttpClientService douyinHttpClientService)
public LogsController(IWebHostEnvironment webHostEnvironment,LogInfoService logInfoService)
{
this.webHostEnvironment = webHostEnvironment;
this.douyinHttpClientService = douyinHttpClientService;
this.logInfoService = logInfoService;
}
[HttpGet]
@@ -38,5 +38,59 @@ namespace dy.net.Controllers
//var fileContent = encoding.GetString(fileBytes);
//return Content (fileContent, "text/plain", encoding);
}
/// <summary>
/// 获取最近10天的日志文件列表
/// </summary>
[HttpGet("/api/logs/list")]
public IActionResult GetLogFiles()
{
try
{
var _logDirectory = Path.Combine(Directory.GetCurrentDirectory(), "logs");
var files = logInfoService.GetLogFiles(_logDirectory);
return Ok(new {code=0,data=files});
}
catch (Exception ex)
{
return StatusCode(500, new { message = "获取日志列表失败", error = ex.Message });
}
}
/// <summary>
/// 获取日志文件内容流
/// </summary>
[HttpGet("/api/logs/content")]
public IActionResult GetLogContent([FromQuery] LogContentRequest request)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
var _logDirectory = Path.Combine(Directory.GetCurrentDirectory(), "logs");
var stream = logInfoService.GetLogFileStream(_logDirectory, request.Type, request.Date);
// 返回文件流,指定MIME类型为文本
return File(stream, "text/plain", $"log-{request.Type}-{request.Date}.txt");
}
catch (FileNotFoundException ex)
{
return NotFound(new { message = ex.Message });
}
catch (ArgumentException ex)
{
return BadRequest(new { message = ex.Message });
}
catch (Exception ex)
{
return StatusCode(500, new { message = "读取日志文件失败", error = ex.Message });
}
}
}
}