Jellyfin.Plugin.Webdav/StreamingController.cs

35 lines
1.2 KiB
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Jellyfin.Plugin.Webdav;
using Jellyfin.Plugin.Webdav.Configuration;
namespace Jellyfin.Plugin.Webdav.Controllers
{
/// <summary>
/// Controller for streaming WebDAV media.
/// </summary>
[Route("WebDav/[controller]")]
public class StreamController : ControllerBase
{
private readonly WebDavClientService _webDavClientService;
private readonly PluginConfiguration _config;
public StreamController(WebDavClientService webDavClientService, PluginConfiguration config)
{
_webDavClientService = webDavClientService;
_config = config;
}
/// <summary>
/// Streams the file at the given WebDAV path.
/// </summary>
/// <param name="*path">The relative path under the configured root.</param>
[HttpGet("{*path}")]
public async Task<IActionResult> Get(string path)
{
var fullPath = $"{_config.RootPath.TrimEnd('/')}/{path}";
var stream = await _webDavClientService.GetStreamAsync(fullPath).ConfigureAwait(false);
return File(stream, "application/octet-stream");
}
}
}