mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Refactor done
This commit is contained in:
45
src/Jackett/Models/Config/ServerConfig.cs
Normal file
45
src/Jackett/Models/Config/ServerConfig.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jackett.Models.Config
|
||||
{
|
||||
public class ServerConfig
|
||||
{
|
||||
public ServerConfig()
|
||||
{
|
||||
Port = 9117;
|
||||
}
|
||||
|
||||
public int Port { get; set; }
|
||||
public bool AllowExternal { get; set; }
|
||||
public string APIKey { get; set; }
|
||||
|
||||
public string GetListenAddress(bool? external = null)
|
||||
{
|
||||
|
||||
if (external == null)
|
||||
{
|
||||
external = AllowExternal;
|
||||
}
|
||||
return "http://" + (external.Value ? "*" : "localhost") + ":" + Port + "/";
|
||||
}
|
||||
|
||||
public string GenerateApi()
|
||||
{
|
||||
var chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var randBytes = new byte[32];
|
||||
var rngCsp = new RNGCryptoServiceProvider();
|
||||
rngCsp.GetBytes(randBytes);
|
||||
var key = "";
|
||||
foreach (var b in randBytes)
|
||||
{
|
||||
key += chars[b % chars.Length];
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user