Implement download controller

This commit is contained in:
Maksym Pavlenko
2016-11-08 14:45:18 -08:00
parent c39dd14cc3
commit d9dd677329
3 changed files with 41 additions and 4 deletions
@@ -0,0 +1,35 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Podsync.Services.Links;
using Podsync.Services.Resolver;
namespace Podsync.Controllers
{
[Route("download")]
public class DownloadController : Controller
{
private readonly IResolverService _resolverService;
private readonly ILinkService _linkService;
public DownloadController(IResolverService resolverService, ILinkService linkService)
{
_resolverService = resolverService;
_linkService = linkService;
}
[Route("{provider}/{videoId}.mp4")]
public async Task<IActionResult> Download(Provider provider, string videoId)
{
var url = _linkService.Make(new LinkInfo
{
Provider = provider,
LinkType = LinkType.Video,
Id = videoId
});
var redirectUrl = await _resolverService.Resolve(url);
return Redirect(redirectUrl.ToString());
}
}
}