using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Jellyfin.Plugin.Webdav; using Jellyfin.Plugin.Webdav.Configuration; namespace Jellyfin.Plugin.Webdav.Controllers { /// /// Controller for streaming WebDAV media. /// [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; } /// /// Streams the file at the given WebDAV path. /// /// The relative path under the configured root. [HttpGet("{*path}")] public async Task Get(string path) { var fullPath = $"{_config.RootPath.TrimEnd('/')}/{path}"; var stream = await _webDavClientService.GetStreamAsync(fullPath).ConfigureAwait(false); return File(stream, "application/octet-stream"); } } }