Compare commits

..

No commits in common. "3c4867a276545519380477824c5fdc63792ee08b" and "e49db9a4cb57f5012cb7e6bc3b7d13a6fe36681b" have entirely different histories.

7 changed files with 19 additions and 53 deletions

View File

@ -27,14 +27,17 @@ public class UpdateMetadata : Job
Manga? possibleUpdatedManga = mangaConnector.GetMangaFromId(manga.publicationId); Manga? possibleUpdatedManga = mangaConnector.GetMangaFromId(manga.publicationId);
if (possibleUpdatedManga is { } updatedManga) if (possibleUpdatedManga is { } updatedManga)
{ {
if (updatedManga.Equals(this.manga)) //Check if anything changed if(updatedManga.Equals(this.manga))//Check if anything changed
{
this.progressToken.Complete();
return Array.Empty<Job>(); return Array.Empty<Job>();
}
this.manga.UpdateMetadata(updatedManga); this.manga.UpdateMetadata(updatedManga);
this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); this.manga.SaveSeriesInfoJson(settings.downloadLocation, true);
/* //TODO remove if this fixes #90
if (parentJobId is not null && jobBoss.GetJobById(this.parentJobId) is DownloadNewChapters dncJob)
{
dncJob.manga = updatedManga;
}*/
this.progressToken.Complete(); this.progressToken.Complete();
} }
else else

View File

@ -62,17 +62,8 @@ internal class ChromiumDownloadClient : DownloadClient
{ {
IPage page = this.browser.NewPageAsync().Result; IPage page = this.browser.NewPageAsync().Result;
page.DefaultTimeout = 10000; page.DefaultTimeout = 10000;
IResponse response; IResponse response = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
try Log("Page loaded.");
{
response = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
Log("Page loaded.");
}
catch (Exception e)
{
Log($"Could not load Page:\n{e.Message}");
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
}
Stream stream = Stream.Null; Stream stream = Stream.Null;
HtmlDocument? document = null; HtmlDocument? document = null;

View File

@ -15,14 +15,6 @@ internal abstract class DownloadClient : GlobalBase
foreach (KeyValuePair<byte, int> limit in rateLimitRequestsPerMinute) foreach (KeyValuePair<byte, int> limit in rateLimitRequestsPerMinute)
_rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value)); _rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value));
} }
internal void SetCustomRequestLimit(byte requestType, int limit)
{
if (_rateLimit.ContainsKey(requestType))
_rateLimit[requestType] = TimeSpan.FromMinutes(1).Divide(limit);
else
_rateLimit.Add(requestType, TimeSpan.FromMinutes(1).Divide(limit));
}
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null, string? clickButton = null) public RequestResult MakeRequest(string url, byte requestType, string? referrer = null, string? clickButton = null)
{ {

View File

@ -8,16 +8,20 @@ internal class HttpDownloadClient : DownloadClient
{ {
private static readonly HttpClient Client = new() private static readonly HttpClient Client = new()
{ {
Timeout = TimeSpan.FromSeconds(10) Timeout = TimeSpan.FromSeconds(60),
DefaultRequestHeaders =
{
UserAgent =
{
new ProductInfoHeaderValue("Tranga", "0.1")
}
}
}; };
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(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)

View File

@ -178,7 +178,7 @@ public abstract class MangaConnector : GlobalBase
string fileInCache = Path.Join(settings.coverImageCache, manga.coverFileNameInCache); string fileInCache = Path.Join(settings.coverImageCache, manga.coverFileNameInCache);
if (!File.Exists(fileInCache)) if (!File.Exists(fileInCache))
{ {
Log($"Cloning cover failed: File missing {fileInCache}."); Log($"Cloníng cover failed: File missing {fileInCache}.");
if (retries > 0 && manga.coverUrl is not null) if (retries > 0 && manga.coverUrl is not null)
{ {
Log($"Trying {retries} more times"); Log($"Trying {retries} more times");

View File

@ -384,29 +384,6 @@ public class Server : GlobalBase
settings.UpdateWorkingDirectory(workingDirectory); settings.UpdateWorkingDirectory(workingDirectory);
SendResponse(HttpStatusCode.Accepted, response); SendResponse(HttpStatusCode.Accepted, response);
break;*/ break;*/
case "Settings/customUserAgent":
if(!requestVariables.TryGetValue("userAgent", out string? customUserAgent))
{
SendResponse(HttpStatusCode.BadRequest, response);
break;
}
settings.customUserAgent = customUserAgent;
SendResponse(HttpStatusCode.Accepted, response);
break;
case "Settings/customRequestLimit":
if (!requestVariables.TryGetValue("requestType", out string? requestTypeStr) ||
!requestVariables.TryGetValue("requestsPerMinute", out string? requestsPerMinuteStr) ||
!requestVariables.TryGetValue("connector", out connectorName) ||
!byte.TryParse(requestTypeStr, out byte requestType) ||
!int.TryParse(requestsPerMinuteStr, out int requestsPerMinute) ||
!_parent.TryGetConnector(connectorName, out connector))
{
SendResponse(HttpStatusCode.BadRequest, response);
break;
}
connector!.downloadClient.SetCustomRequestLimit(requestType, requestsPerMinute);
SendResponse(HttpStatusCode.Accepted, response);
break;
case "NotificationConnectors/Update": case "NotificationConnectors/Update":
if (!requestVariables.TryGetValue("notificationConnector", out string? notificationConnectorStr) || if (!requestVariables.TryGetValue("notificationConnector", out string? notificationConnectorStr) ||
!Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationConnectorType notificationConnectorType)) !Enum.TryParse(notificationConnectorStr, out NotificationConnector.NotificationConnectorType notificationConnectorType))

View File

@ -12,7 +12,6 @@ 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;
[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");