47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using WebDav.Client;
|
|
|
|
namespace Jellyfin.Plugin.Webdav
|
|
{
|
|
/// <summary>
|
|
/// Service for interacting with WebDAV endpoints.
|
|
/// </summary>
|
|
public class WebDavClientService
|
|
{
|
|
private readonly PluginConfiguration _config;
|
|
private readonly WebDavClient _client;
|
|
|
|
public WebDavClientService(PluginConfiguration config)
|
|
{
|
|
_config = config;
|
|
var parameters = new WebDavClientParams
|
|
{
|
|
BaseAddress = new Uri(_config.BaseUrl),
|
|
Credentials = new NetworkCredential(_config.Username, _config.Password)
|
|
};
|
|
_client = new WebDavClient(parameters);
|
|
}
|
|
|
|
/// <summary>
|
|
/// List resources at the specified WebDAV path.
|
|
/// </summary>
|
|
public async Task<IEnumerable<WebDavResource>> ListAsync(string path)
|
|
{
|
|
var response = await _client.Propfind(path).ConfigureAwait(false);
|
|
return response.Resources;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a raw file stream from the WebDAV endpoint.
|
|
/// </summary>
|
|
public async Task<Stream> GetStreamAsync(string path)
|
|
{
|
|
var response = await _client.GetRawFile(path).ConfigureAwait(false);
|
|
return response.Stream;
|
|
}
|
|
}
|
|
} |