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.
79 lines
2.1 KiB
C#
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)
|
|
});
|
|
}
|
|
} |