re-organize Nextcloud project structure

This commit is contained in:
2023-10-02 15:38:58 +02:00
parent b2ef1e5cce
commit fc50ebb3d5
27 changed files with 49 additions and 44 deletions

View File

@@ -1,12 +1,11 @@
using Pilz.Networking.CloudProviders.Nextcloud.Model.Apps.FilesRetention;
using Pilz.Networking.CloudProviders.Nextcloud.OCS.APIs.Apps;
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention
{
public class FilesRetentionClient : ClientBase
{

View File

@@ -0,0 +1,35 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
{
public class RetentionRule : RetentionRuleInfo
{
/// <summary>
/// The ID for the retention rule.
/// </summary>
public int ID { get; init; }
/// <summary>
/// Defines if a background job has been generated
/// </summary>
public bool HasJob { get; init; }
public RetentionRule()
{
}
public RetentionRule(OcsResponseDataEntryRetention data)
{
ID = data.ID ?? -1;
TagID = data.TagID ?? -1;
TimeUnit = (RetentionTimeUnit)(data.TimeUnit ?? 0);
TimeAmount = data.TimeAmount ?? -1;
TimeAfter = (RetentionTimeAfter)(data.TimeAfter ?? 0);
}
}
}

View File

@@ -0,0 +1,43 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
{
public class RetentionRuleInfo
{
/// <summary>
/// The ID for the tag that is used for this rule.
/// </summary>
public int TagID { get; init; }
/// <summary>
/// The unit used for the time.
/// </summary>
public RetentionTimeUnit TimeUnit { get; init; }
/// <summary>
/// Represents numer of days/weeks/months/years.
/// </summary>
public int TimeAmount { get; init; }
/// <summary>
/// The time used for the rule.
/// </summary>
public RetentionTimeAfter TimeAfter { get; init; }
public OcsDataRetentionRule ToOcsData()
{
return new OcsDataRetentionRule
{
TagID = TagID,
TimeUnit = (int)TimeUnit,
TimeAmount = TimeAmount,
TimeAfter = (int)TimeAfter
};
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
{
public enum RetentionTimeAfter
{
CreationDate,
LastAccess
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
{
public enum RetentionTimeUnit
{
Day,
Week,
Month,
Year
}
}

View File

@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs
{
public class OcsDataRetentionRule : OcsData
{
[JsonProperty("tagid")]
public int? TagID { get; set; }
[JsonProperty("timeunit")]
public int? TimeUnit { get; set; }
[JsonProperty("timeamount")]
public int? TimeAmount { get; set; }
[JsonProperty("timeafter")]
public int? TimeAfter { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs
{
public class OcsResponseDataEntryRetention : OcsResponseDataEntry
{
[JsonProperty("id")]
public int? ID { get; set; }
[JsonProperty("tagid")]
public int? TagID { get; set; }
[JsonProperty("timeunit")]
public int? TimeUnit { get; set; }
[JsonProperty("timeamount")]
public int? TimeAmount { get; set; }
[JsonProperty("timeafter")]
public int? TimeAfter { get; set; }
[JsonProperty("hasJob")]
public bool? HasJob { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs
{
public class OcsResponseRetention : OcsResponse<OcsResponseDataArray<OcsResponseDataEntryRetention>>
{
}
}

View File

@@ -0,0 +1,39 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention
{
public class OcsApiFilesRetention : OcsApiBase
{
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULES = new("/ocs/v2.php/apps/files_retention/api/v1/retentions");
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULE = new("/ocs/v2.php/apps/files_retention/api/v1/retentions/{0}");
public OcsApiFilesRetention(OcsApi manager) : base(manager)
{
}
public bool CreateRetentionRule(OcsDataRetentionRule rule)
{
var response = Manager.MakeRequest(HttpMethod.Post, OCS_FILE_RETENTION_RULES, content: rule);
return response.IsSuccessStatusCode;
}
public bool DeleteRetentionRule(int ruleID)
{
var response = Manager.MakeRequest(HttpMethod.Delete, OCS_FILE_RETENTION_RULE.FillParameters(ruleID));
return response.IsSuccessStatusCode;
}
public OcsResponseRetention? GetRetentionRules()
{
return Manager.MakeRequestOcs<OcsResponseRetention>(HttpMethod.Get, OCS_FILE_RETENTION_RULES);
}
}
}

View File

@@ -1,11 +1,11 @@
using Pilz.Networking.CloudProviders.Nextcloud.Model.Cloud;
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud
{
public class CloudClient : ClientBase
{

View File

@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
{
public class UserBackendCapabilities
{
/// <summary>
/// Defines if the display name can be changed.
/// </summary>
public bool SetDisplayName { get; set; }
/// <summary>
/// Defines if the password can be changed.
/// </summary>
public bool SetPassword { get; set; }
}
}

View File

@@ -0,0 +1,131 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
{
public class UserInfo
{
/// <summary>
/// Defines if the user is enabled.
/// </summary>
public bool Enabled { get; init; }
/// <summary>
/// The location of the user's storage directory.
/// </summary>
public string? StorageLocation { get; init; }
/// <summary>
/// The uniquie user id that infos are for.
/// </summary>
public string? ID { get; init; }
/// <summary>
/// The last time when the user has logged in to its account.
/// </summary>
public DateTime LastLogin { get; init; }
/// <summary>
/// The backend of the user. Common values are "Database" or "LDAP".
/// </summary>
public string? Backend { get; init; }
/// <summary>
/// The Email address of the user.
/// </summary>
public string? Email { get; init; }
/// <summary>
/// The displayname of the user.
/// </summary>
public string? Displayname { get; init; }
/// <summary>
/// The displayname of the user.
/// </summary>
public string? Displayname2 { get; init; }
/// <summary>
/// The phone number of the user.
/// </summary>
public string? Phone { get; init; }
/// <summary>
/// The address of the user.
/// </summary>
public string? Address { get; init; }
/// <summary>
/// The Website of the user.
/// </summary>
public string? Website { get; init; }
/// <summary>
/// The twitter profile name of the user.
/// </summary>
public string? Twitter { get; init; }
/// <summary>
/// Defines the groups the user is member of.
/// </summary>
public string[] Groups { get; init; }
/// <summary>
/// The configured language of the user.
/// </summary>
public string? Language { get; init; }
/// <summary>
/// The configured location of the user.
/// </summary>
public string? Locale { get; init; }
/// <summary>
/// Quota informations for the user.
/// </summary>
public UserQuota Quota { get; } = new();
/// <summary>
/// Backend capabilities of the user.
/// </summary>
public UserBackendCapabilities BackendCapabilities { get; } = new();
public UserInfo(OcsResponseDataUser responseData)
{
Enabled = Convert.ToBoolean(responseData.Enabled);
StorageLocation = responseData.StorageLocation;
ID = responseData.ID;
LastLogin = DateTimeOffset.FromUnixTimeMilliseconds(responseData.LastLogin ?? 0).LocalDateTime;
Backend = responseData.Backend;
Email = responseData.Email;
Displayname = responseData.Displayname;
Displayname2 = responseData.Displayname2;
Phone = responseData.Phone;
Address = responseData.Address;
Website = responseData.Website;
Twitter = responseData.Twitter;
Groups = responseData.Groups ?? Array.Empty<string>();
Language = responseData.Language;
Locale = responseData.Locale;
if (responseData.Quota != null)
{
Quota.Free = responseData.Quota.Free ?? 0;
Quota.Used = responseData.Quota.Used ?? 0;
Quota.Total = responseData.Quota.Total ?? 0;
Quota.Relative = responseData.Quota.Relative ?? 0.0F;
Quota.Quota = responseData.Quota.Quota ?? 0;
}
if (responseData.BackendCapabilities != null)
{
BackendCapabilities.SetDisplayName = Convert.ToBoolean(responseData.BackendCapabilities.SetDisplayName);
BackendCapabilities.SetPassword = Convert.ToBoolean(responseData.BackendCapabilities.SetPassword);
}
}
}
}

View File

@@ -0,0 +1,37 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
{
public class UserQuota
{
/// <summary>
/// Amount of free bytes left.
/// </summary>
public long Free { get; set; }
/// <summary>
/// Amount of already used bytes.
/// </summary>
public long Used { get; set; }
/// <summary>
/// Total amount of all bytes (free + used).
/// </summary>
public long Total { get; set; }
/// <summary>
/// Relative amount of used quota in percent.
/// </summary>
public float Relative { get; set; }
/// <summary>
/// Total amount of bytes available.
/// </summary>
public long Quota { get; set; }
}
}

View File

@@ -0,0 +1,91 @@
using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs
{
public class OcsResponseDataUser : OcsResponseData
{
public class ResponseQuota
{
[JsonProperty("free")]
public long? Free { get; set; }
[JsonProperty("used")]
public long? Used { get; set; }
[JsonProperty("total")]
public long? Total { get; set; }
[JsonProperty("relative")]
public float? Relative { get; set; }
[JsonProperty("quota")]
public long? Quota { get; set; }
}
public class ResponseBackendCapabilities
{
[JsonProperty("setDisplayName")]
public bool? SetDisplayName { get; set; }
[JsonProperty("setPassword")]
public bool? SetPassword { get; set; }
}
[JsonProperty("enabled")]
public bool? Enabled { get; set; }
[JsonProperty("storageLocation")]
public string? StorageLocation { get; set; }
[JsonProperty("id")]
public string? ID { get; set; }
[JsonProperty("lastLogin")]
public long? LastLogin { get; set; }
[JsonProperty("backend")]
public string? Backend { get; set; }
[JsonProperty("quota")]
public ResponseQuota? Quota { get; set; }
[JsonProperty("email")]
public string? Email { get; set; }
[JsonProperty("displayname")]
public string? Displayname { get; set; }
[JsonProperty("display-name")]
public string? Displayname2 { get; set; }
[JsonProperty("phone")]
public string? Phone { get; set; }
[JsonProperty("address")]
public string? Address { get; set; }
[JsonProperty("website")]
public string? Website { get; set; }
[JsonProperty("twitter")]
public string? Twitter { get; set; }
[JsonProperty("groups")]
public string[]? Groups { get; set; }
[JsonProperty("language")]
public string? Language { get; set; }
[JsonProperty("locale")]
public string? Locale { get; set; }
[JsonProperty("backendCapabilities")]
public ResponseBackendCapabilities? BackendCapabilities { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs
{
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
{
}
}

View File

@@ -0,0 +1,24 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud
{
public class OcsApiCloud : OcsApiBase
{
public readonly static OcsApiUrlPath OCS_CLOUD_USER_METADATA = new("/ocs/v1.php/cloud/users/{0}");
public OcsApiCloud(OcsApi manager) : base(manager)
{
}
public OcsResponseUser? GetUserMeta(string username)
{
return Manager.MakeRequestOcs<OcsResponseUser>(HttpMethod.Get, OCS_CLOUD_USER_METADATA.FillParameters(username));
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Core
{
public class OcsApiCore : OcsApiBase
{
public static readonly OcsApiUrlPath OCS_CORE_APPPASSWORD = "/ocs/v2.php/core/apppassword";
public OcsApiCore(OcsApi manager) : base(manager)
{
}
public bool DeleteAppPassword()
{
using var msg = Manager.MakeRequest(HttpMethod.Delete, OCS_CORE_APPPASSWORD);
return msg != null && msg.IsSuccessStatusCode;
}
}
}

View File

@@ -0,0 +1,40 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs
{
public class OcsResponseLoginFlowV2
{
public class PollData
{
/// <summary>
/// The login token that has been created for the login process.
/// It can be used to poll the login state.
/// </summary>
[JsonProperty("token")]
public string? Token { get; set; }
/// <summary>
///
/// </summary>
[JsonProperty("endpoint")]
public string? Endpoint { get; set; }
}
/// <summary>
///
/// </summary>
[JsonProperty("poll")]
public PollData? Poll { get; set; }
/// <summary>
/// The temporary login url that should be used for login.
/// </summary>
[JsonProperty("login")]
public string? LoginUrl { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs
{
public class OcsResponseLoginFlowV2Credentials
{
/// <summary>
/// The server url the login credentials are for.
/// </summary>
[JsonProperty("server")]
public string? Server { get; set; }
/// <summary>
/// The login name (username or password) used for the login.
/// </summary>
[JsonProperty("loginName")]
public string? LoginName { get; set; }
/// <summary>
/// The app password that has been generated.
/// </summary>
[JsonProperty("appPassword")]
public string? AppPassword { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
using Pilz.Networking.CloudProviders.Nextcloud.OCS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2
{
public class OcsApiLoginFlowV2 : OcsApiBase
{
private const string OCS_LOGIN_INIT = "/index.php/login/v2";
public OcsApiLoginFlowV2(OcsApi manager) : base(manager)
{
}
public OcsResponseLoginFlowV2? Init(string url)
{
return Manager.MakeRequest<OcsResponseLoginFlowV2>(HttpMethod.Get, url + OCS_LOGIN_INIT);
}
public OcsResponseLoginFlowV2Credentials? Poll(OcsResponseLoginFlowV2.PollData poll)
{
ArgumentNullException.ThrowIfNull(poll?.Endpoint);
ArgumentNullException.ThrowIfNull(poll?.Token);
return Manager.MakeRequest<OcsResponseLoginFlowV2Credentials?>(HttpMethod.Get, poll.Endpoint,
parameters: new Dictionary<string, string>
{
{ "token", poll.Token }
});
}
}
}