/* * Jellyfin.Plugin.Webdav * Copyright (C) 2025 Jellyfin contributors * Licensed under GPLv3 */ namespace Jellyfin.Plugin.Webdav { using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; using Jellyfin.Plugin.Webdav.Configuration; using WebDav; /// /// Service for interacting with WebDAV endpoints. /// public sealed class WebDavClientService { private readonly PluginConfiguration _config; private readonly WebDavClient _client; /// /// Initializes a new instance of the class. /// /// Plugin configuration. public WebDavClientService(PluginConfiguration config) { _config = config; var parameters = new WebDavClientParams { BaseAddress = new Uri(_config.BaseUrl.TrimEnd('/')), Credentials = new NetworkCredential(_config.Username, _config.Password), PreAuthenticate = true }; _client = new WebDavClient(parameters); } /// /// Lists resources at the specified WebDAV path. /// /// Remote path. /// A collection of WebDAV resources. public async Task> ListAsync(string path) { var response = await _client.Propfind(path).ConfigureAwait(false); return response.Resources; } /// /// Gets a raw file stream from the WebDAV endpoint. /// /// Remote file path. /// A stream for the remote file. public async Task GetStreamAsync(string path) { var response = await _client.GetRawFile(path).ConfigureAwait(false); return response.Stream; } } }