This commit is contained in:
parent
3c4867a276
commit
2dd82aad13
@ -14,10 +14,7 @@ internal class HttpDownloadClient : DownloadClient
|
|||||||
|
|
||||||
public HttpDownloadClient(GlobalBase clone, Dictionary<byte, int> rateLimitRequestsPerMinute) : base(clone, rateLimitRequestsPerMinute)
|
public HttpDownloadClient(GlobalBase clone, Dictionary<byte, int> rateLimitRequestsPerMinute) : base(clone, rateLimitRequestsPerMinute)
|
||||||
{
|
{
|
||||||
if (settings.customUserAgent is null || settings.customUserAgent.Length < 1)
|
Client.DefaultRequestHeaders.UserAgent.Add(settings.userAgent);
|
||||||
Client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Tranga", "1.0"));
|
|
||||||
else
|
|
||||||
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", settings.customUserAgent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
@ -200,6 +200,9 @@ public class Server : GlobalBase
|
|||||||
case "Settings":
|
case "Settings":
|
||||||
SendResponse(HttpStatusCode.OK, response, settings);
|
SendResponse(HttpStatusCode.OK, response, settings);
|
||||||
break;
|
break;
|
||||||
|
case "Settings/userAgent":
|
||||||
|
SendResponse(HttpStatusCode.OK, response, settings.userAgent);
|
||||||
|
break;
|
||||||
case "NotificationConnectors":
|
case "NotificationConnectors":
|
||||||
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
SendResponse(HttpStatusCode.OK, response, notificationConnectors);
|
||||||
break;
|
break;
|
||||||
@ -384,13 +387,13 @@ public class Server : GlobalBase
|
|||||||
settings.UpdateWorkingDirectory(workingDirectory);
|
settings.UpdateWorkingDirectory(workingDirectory);
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
SendResponse(HttpStatusCode.Accepted, response);
|
||||||
break;*/
|
break;*/
|
||||||
case "Settings/customUserAgent":
|
case "Settings/userAgent":
|
||||||
if(!requestVariables.TryGetValue("userAgent", out string? customUserAgent))
|
if(!requestVariables.TryGetValue("userAgent", out string? customUserAgent))
|
||||||
{
|
{
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
settings.customUserAgent = customUserAgent;
|
settings.UpdateUserAgent(customUserAgent);
|
||||||
SendResponse(HttpStatusCode.Accepted, response);
|
SendResponse(HttpStatusCode.Accepted, response);
|
||||||
break;
|
break;
|
||||||
case "Settings/customRequestLimit":
|
case "Settings/customRequestLimit":
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Net.Http.Headers;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Tranga.LibraryConnectors;
|
using Tranga.LibraryConnectors;
|
||||||
using Tranga.NotificationConnectors;
|
using Tranga.NotificationConnectors;
|
||||||
@ -12,7 +13,7 @@ public class TrangaSettings
|
|||||||
public string workingDirectory { get; private set; }
|
public string workingDirectory { get; private set; }
|
||||||
public int apiPortNumber { get; init; }
|
public int apiPortNumber { get; init; }
|
||||||
public string styleSheet { get; private set; }
|
public string styleSheet { get; private set; }
|
||||||
public string? customUserAgent { get; set; } = null;
|
public ProductInfoHeaderValue userAgent { get; set; } = new ("Tranga", "1.0");
|
||||||
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
|
||||||
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
|
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
|
||||||
@ -120,6 +121,11 @@ public class TrangaSettings
|
|||||||
ExportSettings();
|
ExportSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateUserAgent(string customUserAgent)
|
||||||
|
{
|
||||||
|
this.userAgent = new ProductInfoHeaderValue(ProductHeaderValue.Parse(customUserAgent));
|
||||||
|
}
|
||||||
|
|
||||||
public void ExportSettings()
|
public void ExportSettings()
|
||||||
{
|
{
|
||||||
if (File.Exists(settingsFilePath))
|
if (File.Exists(settingsFilePath))
|
||||||
|
Loading…
Reference in New Issue
Block a user