40 lines
1.5 KiB
C#
40 lines
1.5 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;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="StreamController"/> class.
|
|
/// </summary>
|
|
/// <param name="webDavClientService">The WebDAV client service.</param>
|
|
/// <param name="config">The plugin configuration.</param>
|
|
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");
|
|
}
|
|
}
|
|
} |