Added new file manager, renamed websites to webspaces. Added cloudpanel integration partialy. Added generic repos and more stuff
This commit is contained in:
83
Moonlight/App/ApiClients/CloudPanel/CloudPanelApiHelper.cs
Normal file
83
Moonlight/App/ApiClients/CloudPanel/CloudPanelApiHelper.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using Moonlight.App.Database.Entities;
|
||||
using Moonlight.App.Models.Plesk.Resources;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
|
||||
namespace Moonlight.App.ApiClients.CloudPanel;
|
||||
|
||||
public class CloudPanelApiHelper
|
||||
{
|
||||
private readonly RestClient Client;
|
||||
|
||||
public CloudPanelApiHelper()
|
||||
{
|
||||
Client = new();
|
||||
}
|
||||
|
||||
public async Task Post(Database.Entities.CloudPanel cloudPanel, string resource, object? body)
|
||||
{
|
||||
var request = CreateRequest(cloudPanel, resource);
|
||||
|
||||
request.Method = Method.Post;
|
||||
|
||||
if(body != null)
|
||||
request.AddParameter("text/plain", JsonConvert.SerializeObject(body), ParameterType.RequestBody);
|
||||
|
||||
var response = await Client.ExecuteAsync(request);
|
||||
|
||||
if (!response.IsSuccessful)
|
||||
{
|
||||
if (response.StatusCode != 0)
|
||||
{
|
||||
throw new CloudPanelException(
|
||||
$"An error occured: ({response.StatusCode}) {response.Content}",
|
||||
(int)response.StatusCode
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"An internal error occured: {response.ErrorMessage}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Delete(Database.Entities.CloudPanel cloudPanel, string resource, object? body)
|
||||
{
|
||||
var request = CreateRequest(cloudPanel, resource);
|
||||
|
||||
request.Method = Method.Delete;
|
||||
|
||||
if(body != null)
|
||||
request.AddParameter("text/plain", JsonConvert.SerializeObject(body), ParameterType.RequestBody);
|
||||
|
||||
var response = await Client.ExecuteAsync(request);
|
||||
|
||||
if (!response.IsSuccessful)
|
||||
{
|
||||
if (response.StatusCode != 0)
|
||||
{
|
||||
throw new CloudPanelException(
|
||||
$"An error occured: ({response.StatusCode}) {response.Content}",
|
||||
(int)response.StatusCode
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"An internal error occured: {response.ErrorMessage}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RestRequest CreateRequest(Database.Entities.CloudPanel cloudPanel, string resource)
|
||||
{
|
||||
var url = $"{cloudPanel.ApiUrl}/" + resource;
|
||||
|
||||
var request = new RestRequest(url);
|
||||
|
||||
request.AddHeader("Content-Type", "application/json");
|
||||
request.AddHeader("Accept", "application/json");
|
||||
request.AddHeader("Authorization", "Bearer " + cloudPanel.ApiKey);
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
32
Moonlight/App/ApiClients/CloudPanel/CloudPanelException.cs
Normal file
32
Moonlight/App/ApiClients/CloudPanel/CloudPanelException.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Moonlight.App.ApiClients.CloudPanel;
|
||||
|
||||
[Serializable]
|
||||
public class CloudPanelException : Exception
|
||||
{
|
||||
public int StatusCode { get; set; }
|
||||
|
||||
public CloudPanelException()
|
||||
{
|
||||
}
|
||||
|
||||
public CloudPanelException(string message, int statusCode) : base(message)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
}
|
||||
|
||||
public CloudPanelException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CloudPanelException(string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
}
|
||||
|
||||
protected CloudPanelException(
|
||||
SerializationInfo info,
|
||||
StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
16
Moonlight/App/ApiClients/CloudPanel/Requests/AddPhpSite.cs
Normal file
16
Moonlight/App/ApiClients/CloudPanel/Requests/AddPhpSite.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Moonlight.App.ApiClients.CloudPanel.Requests;
|
||||
|
||||
public class AddPhpSite
|
||||
{
|
||||
[JsonProperty("domainName")] public string DomainName { get; set; } = "";
|
||||
|
||||
[JsonProperty("siteUser")] public string SiteUser { get; set; } = "";
|
||||
|
||||
[JsonProperty("siteUserPassword")] public string SiteUserPassword { get; set; } = "";
|
||||
|
||||
[JsonProperty("vHostTemplate")] public string VHostTemplate { get; set; } = "";
|
||||
|
||||
[JsonProperty("phpVersion")] public string PhpVersion { get; set; } = "";
|
||||
}
|
||||
Reference in New Issue
Block a user