Skip to content

Commit

Permalink
chore: add user end pass to rclone rc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahnitam committed Aug 11, 2022
1 parent b70e3be commit 60298d5
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 288 deletions.
66 changes: 7 additions & 59 deletions Api/ApiController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Net;
using System.Net.Mime;
using GenerateStrmFromRclone.Manager;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -20,55 +19,23 @@ public ApiController(ILogger<ApiController> logger)
{
_logger = logger;
}
[HttpGet("getNetworksInterfaces")]
[ProducesResponseType(typeof(List<Dictionary<string, dynamic?>>), StatusCodes.Status200OK)]
[Produces(MediaTypeNames.Application.Json)]
public IActionResult GetNetworksInterfaces()
{
List<Dictionary<string, dynamic?>> interfaces = new List<Dictionary<string, dynamic?>>();
try
{
foreach (var ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
interfaces.Add(new Dictionary<string, dynamic?> {
{ "address", ip.ToString() },
{ "addressFamily", ip.AddressFamily.ToString() }
});
}
}
catch (Exception e)
{
_logger.LogError(e.ToString(), e);
}

return Ok(interfaces);
}


[HttpGet("getRcloneDrives")]
[ProducesResponseType(typeof(List<Dictionary<string, dynamic?>>), StatusCodes.Status200OK)]
[Produces(MediaTypeNames.Application.Json)]
public IActionResult GetRcloneDrives([FromQuery] string? rcloneRcPort)
public IActionResult GetRcloneDrives([FromQuery] string rcloneRcUrl, [FromQuery] string? rcloneAuth)
{
if (rcloneRcPort != null)
{
return Ok(Rclone.GetRcloneDrives(rcloneRcPort));
}else {
return BadRequest();
}
return Ok(Rclone.GetRcloneDrives(rcloneRcUrl, rcloneAuth));
}

[HttpGet("driveExists")]
[ProducesResponseType(typeof(Dictionary<string, bool>), StatusCodes.Status200OK)]
[Produces(MediaTypeNames.Application.Json)]
public IActionResult DriveExist([FromQuery] string drive, [FromQuery] string? drivePath, [FromQuery] string? rcloneRcPort)
public IActionResult DriveExist([FromQuery] string rcloneRcUrl, [FromQuery] string? rcloneAuth, [FromQuery] string drive, [FromQuery] string? drivePath)
{
if(rcloneRcPort != null){
return Ok(new Dictionary<string, bool> {
{ "exists", Rclone.CheckConfiguration(rcloneRcPort, drive, drivePath) }
});
} else {
return BadRequest();
}
return Ok(new Dictionary<string, bool> {
{ "exists", Rclone.CheckConfiguration(rcloneRcUrl, rcloneAuth, drive, drivePath) }
});
}

[HttpGet("folderExists")]
Expand All @@ -89,24 +56,5 @@ public IActionResult FolderExists([FromQuery] string folder)
});
}
}

[HttpGet("fileExists")]
[ProducesResponseType(typeof(Dictionary<string, bool>), StatusCodes.Status200OK)]
[Produces(MediaTypeNames.Application.Json)]
public IActionResult FileExists([FromQuery] string file)
{
try
{
return Ok(new Dictionary<string, bool> {
{ "exists", System.IO.File.Exists(file) }
});
}
catch (System.Exception)
{
return Ok(new Dictionary<string, bool> {
{ "exists", false }
});
}
}
}
}
14 changes: 8 additions & 6 deletions Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ public class PluginConfiguration : BasePluginConfiguration
{
public PluginConfiguration()
{
rcloneServeIP = null;
rcloneServePort = 5000;
rcloneRcPort = 5572;
rcloneServeUrl = null;
rcloneRcUrl = null;
rcloneAuthType = null;
rcloneAuth = null;
rcloneMediaPATH = null;
rcloneRemoteDrive = null;
rcloneDrivePATH = "";
}
public string? rcloneServeIP { get; set; }
public int rcloneServePort { get; set; }
public int rcloneRcPort { get; set; }
public string? rcloneServeUrl { get; set; }
public string? rcloneRcUrl { get; set; }
public string? rcloneAuthType { get; set; }
public string? rcloneAuth { get; set; }
public string? rcloneRemoteDrive { get; set; }
public string rcloneDrivePATH { get; set; }
public string? rcloneMediaPATH { get; set; }
Expand Down
Loading

0 comments on commit 60298d5

Please sign in to comment.