Files
TuneRipper/TuneRipper.Api/Controllers/SessionController.cs
T
Michal Vrba 2d2e855202 Refactor downloads to use job-specific subdirectories
Organize downloaded files into per-job subdirectories under "downloads" instead of a flat structure. Update DownloadController and VideoService to read, write, and delete files within these job-specific directories. Add helper methods for directory management and improve logging. Update download/delete endpoints and result URLs to reflect the new structure. Clean up empty job directories after file deletion.
2025-12-14 11:04:46 +01:00

79 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Mvc;
using TuneRipper.Api.Services;
namespace TuneRipper.Api.Controllers;
[ApiController]
[Route("api/[controller]")]
public class SessionController : ControllerBase
{
private readonly ISessionService _sessionService;
private readonly ILogger<SessionController> _logger;
public SessionController(ISessionService sessionService, ILogger<SessionController> logger)
{
_sessionService = sessionService;
_logger = logger;
}
[HttpPost("create")]
public ActionResult<object> CreateSession()
{
try
{
var sessionId = _sessionService.CreateSession();
return Ok(new
{
sessionId,
message = "Session created successfully",
expiresAt = DateTime.UtcNow.AddHours(24)
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error creating session");
return StatusCode(500, "Error creating session");
}
}
[HttpGet("validate/{sessionId}")]
public ActionResult<object> ValidateSession(string sessionId)
{
if (string.IsNullOrWhiteSpace(sessionId))
{
return BadRequest("Session ID is required");
}
var isValid = _sessionService.IsValidSession(sessionId);
return Ok(new
{
sessionId,
isValid,
message = isValid ? "Session is valid" : "Session is invalid or expired"
});
}
[HttpPost("refresh/{sessionId}")]
public ActionResult<object> RefreshSession(string sessionId)
{
if (string.IsNullOrWhiteSpace(sessionId))
{
return BadRequest("Session ID is required");
}
if (!_sessionService.IsValidSession(sessionId))
{
return NotFound("Session not found or expired");
}
// Session is automatically refreshed when IsValidSession is called
return Ok(new
{
sessionId,
message = "Session refreshed successfully",
expiresAt = DateTime.UtcNow.AddHours(24)
});
}
}