mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-15 11:02:17 +02:00
Compare commits
4 Commits
3b542c04f6
...
1.5
Author | SHA1 | Date | |
---|---|---|---|
cdd2d94ba1 | |||
d5b7645cd2 | |||
9af5c1603e | |||
1035939309 |
@ -1,10 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<RootNamespace>Tranga_API</RootNamespace>
|
<Nullable>enable</Nullable>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -15,14 +15,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
|
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
13
API/Dockerfile
Normal file
13
API/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
||||||
|
WORKDIR /src
|
||||||
|
COPY . /src/
|
||||||
|
RUN dotnet restore API/API.csproj
|
||||||
|
RUN dotnet publish -c Release -o /publish
|
||||||
|
|
||||||
|
FROM glax/tranga-base:dev as runtime
|
||||||
|
WORKDIR /publish
|
||||||
|
COPY --from=build-env /publish .
|
||||||
|
EXPOSE 6531
|
||||||
|
ENTRYPOINT ["dotnet", "/publish/API.dll"]
|
46
API/Program.cs
Normal file
46
API/Program.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Logging;
|
||||||
|
using Tranga;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
||||||
|
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
||||||
|
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
|
||||||
|
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
||||||
|
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(logsFolderPath);
|
||||||
|
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga", "Loading settings.");
|
||||||
|
|
||||||
|
TrangaSettings settings;
|
||||||
|
if (File.Exists(settingsFilePath))
|
||||||
|
settings = TrangaSettings.LoadSettings(settingsFilePath, logger);
|
||||||
|
else
|
||||||
|
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
||||||
|
|
||||||
|
Directory.CreateDirectory(settings.workingDirectory);
|
||||||
|
Directory.CreateDirectory(settings.downloadLocation);
|
||||||
|
Directory.CreateDirectory(settings.coverImageCache);
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
|
||||||
|
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
|
||||||
|
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
|
||||||
|
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
|
||||||
|
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
|
||||||
|
|
||||||
|
logger.WriteLine("Tranga", "Loading Taskmanager.");
|
||||||
|
TaskManager taskManager = new (settings, logger);
|
||||||
|
|
||||||
|
Server server = new (6531, taskManager, logger);
|
||||||
|
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
||||||
|
nm.SendNotification("Tranga-API", "Started Tranga-API");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
361
API/RequestHandler.cs
Normal file
361
API/RequestHandler.cs
Normal file
@ -0,0 +1,361 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Tranga;
|
||||||
|
using Tranga.TrangaTasks;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class RequestHandler
|
||||||
|
{
|
||||||
|
private TaskManager _taskManager;
|
||||||
|
private Server _parent;
|
||||||
|
|
||||||
|
private List<ValueTuple<HttpMethod, string, string[]>> _validRequestPaths = new()
|
||||||
|
{
|
||||||
|
new(HttpMethod.Get, "/", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Get, "/Connectors", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Get, "/Publications/Known", new[] { "internalId?" }),
|
||||||
|
new(HttpMethod.Get, "/Publications/FromConnector", new[] { "connectorName", "title" }),
|
||||||
|
new(HttpMethod.Get, "/Publications/Chapters",
|
||||||
|
new[] { "connectorName", "internalId", "onlyNew?", "onlyExisting?", "language?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks/Types", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Post, "/Tasks/CreateMonitorTask",
|
||||||
|
new[] { "connectorName", "internalId", "reoccurrenceTime", "language?" }),
|
||||||
|
new(HttpMethod.Post, "/Tasks/CreateUpdateLibraryTask", new[] { "reoccurrenceTime" }),
|
||||||
|
new(HttpMethod.Post, "/Tasks/CreateDownloadChaptersTask",
|
||||||
|
new[] { "connectorName", "internalId", "chapters", "language?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks", new[] { "taskType", "connectorName?", "publicationId?" }),
|
||||||
|
new(HttpMethod.Delete, "/Tasks", new[] { "taskType", "connectorName?", "searchString?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks/Progress",
|
||||||
|
new[] { "taskType", "connectorName", "publicationId", "chapterSortNumber?" }),
|
||||||
|
new(HttpMethod.Post, "/Tasks/Start", new[] { "taskType", "connectorName?", "internalId?" }),
|
||||||
|
new(HttpMethod.Get, "/Tasks/RunningTasks", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Get, "/Queue/List", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Post, "/Queue/Enqueue", new[] { "taskType", "connectorName?", "publicationId?" }),
|
||||||
|
new(HttpMethod.Delete, "/Queue/Dequeue", new[] { "taskType", "connectorName?", "publicationId?" }),
|
||||||
|
new(HttpMethod.Get, "/Settings", Array.Empty<string>()),
|
||||||
|
new(HttpMethod.Post, "/Settings/Update", new[]
|
||||||
|
{
|
||||||
|
"downloadLocation?", "komgaUrl?", "komgaAuth?", "kavitaUrl?", "kavitaUsername?",
|
||||||
|
"kavitaPassword?", "gotifyUrl?", "gotifyAppToken?", "lunaseaWebhook?"
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
public RequestHandler(TaskManager taskManager, Server parent)
|
||||||
|
{
|
||||||
|
this._taskManager = taskManager;
|
||||||
|
this._parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleRequest(HttpListenerRequest request, HttpListenerResponse response)
|
||||||
|
{
|
||||||
|
string requestPath = request.Url!.LocalPath;
|
||||||
|
if (requestPath.Contains("favicon"))
|
||||||
|
{
|
||||||
|
_parent.SendResponse(HttpStatusCode.NoContent, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this._validRequestPaths.Any(path => path.Item1.Method == request.HttpMethod && path.Item2 == requestPath))
|
||||||
|
{
|
||||||
|
_parent.SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Dictionary<string, string> variables = GetRequestVariables(request.Url!.Query);
|
||||||
|
object? responseObject = null;
|
||||||
|
switch (request.HttpMethod)
|
||||||
|
{
|
||||||
|
case "GET":
|
||||||
|
responseObject = this.HandleGet(requestPath, variables);
|
||||||
|
break;
|
||||||
|
case "POST":
|
||||||
|
this.HandlePost(requestPath, variables);
|
||||||
|
break;
|
||||||
|
case "DELETE":
|
||||||
|
this.HandleDelete(requestPath, variables);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_parent.SendResponse(HttpStatusCode.OK, response, responseObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, string> GetRequestVariables(string query)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> ret = new();
|
||||||
|
Regex queryRex = new (@"\?{1}([A-z]+=[A-z]+)+(&[A-z]+=[A-z]+)*");
|
||||||
|
if (!queryRex.IsMatch(query))
|
||||||
|
return ret;
|
||||||
|
query = query.Substring(1);
|
||||||
|
foreach(string kvpair in query.Split('&'))
|
||||||
|
ret.Add(kvpair.Split('=')[0], kvpair.Split('=')[1]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleDelete(string requestPath, Dictionary<string, string> variables)
|
||||||
|
{
|
||||||
|
switch (requestPath)
|
||||||
|
{
|
||||||
|
case "/Tasks":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType1);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName1);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId1);
|
||||||
|
if(taskType1 is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType1);
|
||||||
|
foreach(TrangaTask tTask in _taskManager.GetTasksMatching(task, connectorName1, internalId: publicationId1))
|
||||||
|
_taskManager.DeleteTask(tTask);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "/Queue/Dequeue":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType2);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId2);
|
||||||
|
if(taskType2 is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
||||||
|
TrangaTask? task = _taskManager
|
||||||
|
.GetTasksMatching(pTask, connectorName: connectorName2, internalId: publicationId2).FirstOrDefault();
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
_taskManager.RemoveTaskFromQueue(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandlePost(string requestPath, Dictionary<string, string> variables)
|
||||||
|
{
|
||||||
|
switch (requestPath)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "/Tasks/CreateMonitorTask":
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName1);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId1);
|
||||||
|
variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime1);
|
||||||
|
variables.TryGetValue("language", out string? language1);
|
||||||
|
if (connectorName1 is null || internalId1 is null || reoccurrenceTime1 is null)
|
||||||
|
return;
|
||||||
|
Connector? connector1 =
|
||||||
|
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName1).Value;
|
||||||
|
if (connector1 is null)
|
||||||
|
return;
|
||||||
|
Publication? publication1 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1);
|
||||||
|
if (publication1 is null)
|
||||||
|
return;
|
||||||
|
_taskManager.AddTask(new MonitorPublicationTask(connectorName1, (Publication)publication1, TimeSpan.Parse(reoccurrenceTime1), language1 ?? "en"));
|
||||||
|
break;
|
||||||
|
case "/Tasks/CreateUpdateLibraryTask":
|
||||||
|
variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime2);
|
||||||
|
if (reoccurrenceTime2 is null)
|
||||||
|
return;
|
||||||
|
_taskManager.AddTask(new UpdateLibrariesTask(TimeSpan.Parse(reoccurrenceTime2)));
|
||||||
|
break;
|
||||||
|
case "/Tasks/CreateDownloadChaptersTask":
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId2);
|
||||||
|
variables.TryGetValue("chapters", out string? chapters);
|
||||||
|
variables.TryGetValue("language", out string? language2);
|
||||||
|
if (connectorName2 is null || internalId2 is null || chapters is null)
|
||||||
|
return;
|
||||||
|
Connector? connector2 =
|
||||||
|
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName2).Value;
|
||||||
|
if (connector2 is null)
|
||||||
|
return;
|
||||||
|
Publication? publication2 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId2);
|
||||||
|
if (publication2 is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IEnumerable<Chapter> toDownload = connector2.SearchChapters((Publication)publication2, chapters, language2 ?? "en");
|
||||||
|
foreach(Chapter chapter in toDownload)
|
||||||
|
_taskManager.AddTask(new DownloadChapterTask(connectorName2, (Publication)publication2, chapter, "en"));
|
||||||
|
break;
|
||||||
|
case "/Tasks/Start":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType1);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName3);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId3);
|
||||||
|
if (taskType1 is null)
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType1);
|
||||||
|
TrangaTask? task = _taskManager
|
||||||
|
.GetTasksMatching(pTask, connectorName: connectorName3, internalId: internalId3).FirstOrDefault();
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
_taskManager.ExecuteTaskNow(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "/Queue/Enqueue":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType2);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName4);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId);
|
||||||
|
if (taskType2 is null)
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
||||||
|
TrangaTask? task = _taskManager
|
||||||
|
.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault();
|
||||||
|
|
||||||
|
if (task is null)
|
||||||
|
return;
|
||||||
|
_taskManager.AddTaskToQueue(task);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "/Settings/Update":
|
||||||
|
variables.TryGetValue("downloadLocation", out string? downloadLocation);
|
||||||
|
variables.TryGetValue("komgaUrl", out string? komgaUrl);
|
||||||
|
variables.TryGetValue("komgaAuth", out string? komgaAuth);
|
||||||
|
variables.TryGetValue("kavitaUrl", out string? kavitaUrl);
|
||||||
|
variables.TryGetValue("kavitaUsername", out string? kavitaUsername);
|
||||||
|
variables.TryGetValue("kavitaPassword", out string? kavitaPassword);
|
||||||
|
variables.TryGetValue("gotifyUrl", out string? gotifyUrl);
|
||||||
|
variables.TryGetValue("gotifyAppToken", out string? gotifyAppToken);
|
||||||
|
variables.TryGetValue("lunaseaWebhook", out string? lunaseaWebhook);
|
||||||
|
|
||||||
|
if (downloadLocation is not null && downloadLocation.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, _parent.logger, downloadLocation);
|
||||||
|
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 5 && komgaAuth.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Komga, _parent.logger, komgaUrl, komgaAuth);
|
||||||
|
if (kavitaUrl is not null && kavitaPassword is not null && kavitaUsername is not null && kavitaUrl.Length > 5 &&
|
||||||
|
kavitaUsername.Length > 0 && kavitaPassword.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, _parent.logger, kavitaUrl, kavitaUsername,
|
||||||
|
kavitaPassword);
|
||||||
|
if (gotifyUrl is not null && gotifyAppToken is not null && gotifyUrl.Length > 5 && gotifyAppToken.Length > 0)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, _parent.logger, gotifyUrl, gotifyAppToken);
|
||||||
|
if(lunaseaWebhook is not null && lunaseaWebhook.Length > 5)
|
||||||
|
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.LunaSea, _parent.logger, lunaseaWebhook);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object? HandleGet(string requestPath, Dictionary<string, string> variables)
|
||||||
|
{
|
||||||
|
switch (requestPath)
|
||||||
|
{
|
||||||
|
case "/Connectors":
|
||||||
|
return this._taskManager.GetAvailableConnectors().Keys.ToArray();
|
||||||
|
case "/Publications/Known":
|
||||||
|
variables.TryGetValue("internalId", out string? internalId1);
|
||||||
|
if(internalId1 is null)
|
||||||
|
return _taskManager.GetAllPublications();
|
||||||
|
return new [] { _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1) };
|
||||||
|
case "/Publications/FromConnector":
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName1);
|
||||||
|
variables.TryGetValue("title", out string? title);
|
||||||
|
if (connectorName1 is null || title is null)
|
||||||
|
return null;
|
||||||
|
Connector? connector1 = _taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName1).Value;
|
||||||
|
if (connector1 is null)
|
||||||
|
return null;
|
||||||
|
if(title.Length < 4)
|
||||||
|
return null;
|
||||||
|
return _taskManager.GetPublicationsFromConnector(connector1, title);
|
||||||
|
case "/Publications/Chapters":
|
||||||
|
string[] yes = { "true", "yes", "1", "y" };
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName2);
|
||||||
|
variables.TryGetValue("internalId", out string? internalId2);
|
||||||
|
variables.TryGetValue("onlyNew", out string? onlyNew);
|
||||||
|
variables.TryGetValue("onlyExisting", out string? onlyExisting);
|
||||||
|
variables.TryGetValue("language", out string? language);
|
||||||
|
if (connectorName2 is null || internalId2 is null)
|
||||||
|
return null;
|
||||||
|
bool newOnly = onlyNew is not null && yes.Contains(onlyNew);
|
||||||
|
bool existingOnly = onlyExisting is not null && yes.Contains(onlyExisting);
|
||||||
|
|
||||||
|
Connector? connector2 = _taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName2).Value;
|
||||||
|
if (connector2 is null)
|
||||||
|
return null;
|
||||||
|
Publication? publication = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId2);
|
||||||
|
if (publication is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if(newOnly)
|
||||||
|
return _taskManager.GetNewChaptersList(connector2, (Publication)publication, language??"en").ToArray();
|
||||||
|
else if (existingOnly)
|
||||||
|
return _taskManager.GetExistingChaptersList(connector2, (Publication)publication, language ?? "en").ToArray();
|
||||||
|
else
|
||||||
|
return connector2.GetChapters((Publication)publication, language??"en");
|
||||||
|
case "/Tasks/Types":
|
||||||
|
return Enum.GetNames(typeof(TrangaTask.Task));
|
||||||
|
case "/Tasks":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType1);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName3);
|
||||||
|
variables.TryGetValue("searchString", out string? searchString);
|
||||||
|
if (taskType1 is null)
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType1);
|
||||||
|
return _taskManager.GetTasksMatching(task, connectorName:connectorName3, searchString:searchString);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "/Tasks/Progress":
|
||||||
|
variables.TryGetValue("taskType", out string? taskType2);
|
||||||
|
variables.TryGetValue("connectorName", out string? connectorName4);
|
||||||
|
variables.TryGetValue("publicationId", out string? publicationId);
|
||||||
|
variables.TryGetValue("chapterSortNumber", out string? chapterSortNumber);
|
||||||
|
if (taskType2 is null || connectorName4 is null || publicationId is null)
|
||||||
|
return null;
|
||||||
|
Connector? connector =
|
||||||
|
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName4).Value;
|
||||||
|
if (connector is null)
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TrangaTask? task = null;
|
||||||
|
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
||||||
|
if (pTask is TrangaTask.Task.MonitorPublication)
|
||||||
|
{
|
||||||
|
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault();
|
||||||
|
}else if (pTask is TrangaTask.Task.DownloadChapter && chapterSortNumber is not null)
|
||||||
|
{
|
||||||
|
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId,
|
||||||
|
chapterSortNumber: chapterSortNumber).FirstOrDefault();
|
||||||
|
}
|
||||||
|
if (task is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return task.progress;
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "/Tasks/RunningTasks":
|
||||||
|
return _taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running);
|
||||||
|
case "/Queue/List":
|
||||||
|
return _taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued).OrderBy(task => task.nextExecution);
|
||||||
|
case "/Settings":
|
||||||
|
return _taskManager.settings;
|
||||||
|
case "/":
|
||||||
|
default:
|
||||||
|
return this._validRequestPaths;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
API/Server.cs
Normal file
72
API/Server.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Tranga;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class Server
|
||||||
|
{
|
||||||
|
private readonly HttpListener _listener = new ();
|
||||||
|
private readonly RequestHandler _requestHandler;
|
||||||
|
internal readonly Logger? logger;
|
||||||
|
|
||||||
|
private readonly Regex _validUrl =
|
||||||
|
new (@"https?:\/\/(www\.)?[-A-z0-9]{1,256}(\.[-a-zA-Z0-9]{1,6})?(:[0-9]{1,5})?(\/{1}[A-z0-9()@:%_\+.~#?&=]+)*\/?");
|
||||||
|
public Server(int port, TaskManager taskManager, Logger? logger = null)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this._listener.Prefixes.Add($"http://*:{port}/");
|
||||||
|
this._requestHandler = new RequestHandler(taskManager, this);
|
||||||
|
Listen();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Listen()
|
||||||
|
{
|
||||||
|
this._listener.Start();
|
||||||
|
foreach (string prefix in this._listener.Prefixes)
|
||||||
|
this.logger?.WriteLine(this.GetType().ToString(), $"Listening on {prefix}");
|
||||||
|
while (this._listener.IsListening)
|
||||||
|
{
|
||||||
|
HttpListenerContext context = this._listener.GetContextAsync().Result;
|
||||||
|
Task t = new (() =>
|
||||||
|
{
|
||||||
|
HandleContext(context);
|
||||||
|
});
|
||||||
|
t.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleContext(HttpListenerContext context)
|
||||||
|
{
|
||||||
|
HttpListenerRequest request = context.Request;
|
||||||
|
HttpListenerResponse response = context.Response;
|
||||||
|
//logger?.WriteLine(this.GetType().ToString(), $"New request: {request.HttpMethod} {request.Url}");
|
||||||
|
|
||||||
|
if (!_validUrl.IsMatch(request.Url!.ToString()))
|
||||||
|
{
|
||||||
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_requestHandler.HandleRequest(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||||
|
{
|
||||||
|
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
||||||
|
response.StatusCode = (int)statusCode;
|
||||||
|
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
||||||
|
response.AddHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
|
||||||
|
response.AddHeader("Access-Control-Max-Age", "1728000");
|
||||||
|
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.ContentType = "application/json";
|
||||||
|
response.OutputStream.Write(content is not null
|
||||||
|
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||||
|
: Array.Empty<byte>());
|
||||||
|
response.OutputStream.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,8 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
#FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
||||||
|
FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime
|
||||||
WORKDIR /publish
|
WORKDIR /publish
|
||||||
RUN apt-get update && apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3
|
||||||
|
RUN apt-get autopurge -y
|
||||||
|
RUN apt-get autoclean -y
|
@ -14,7 +14,8 @@ public class MemoryLogger : LoggerBase
|
|||||||
|
|
||||||
protected override void Write(LogMessage value)
|
protected override void Write(LogMessage value)
|
||||||
{
|
{
|
||||||
_logMessages.Add(value.logTime, value);
|
while(!_logMessages.TryAdd(value.logTime, value))
|
||||||
|
Thread.Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] GetLogMessage()
|
public string[] GetLogMessage()
|
||||||
|
@ -1,268 +0,0 @@
|
|||||||
using System.Runtime.InteropServices;
|
|
||||||
using Logging;
|
|
||||||
using Tranga;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
|
||||||
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
|
||||||
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
|
|
||||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
|
||||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
|
||||||
|
|
||||||
Directory.CreateDirectory(logsFolderPath);
|
|
||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga", "Loading settings.");
|
|
||||||
|
|
||||||
TrangaSettings settings;
|
|
||||||
if (File.Exists(settingsFilePath))
|
|
||||||
settings = TrangaSettings.LoadSettings(settingsFilePath, logger);
|
|
||||||
else
|
|
||||||
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
|
||||||
|
|
||||||
Directory.CreateDirectory(settings.workingDirectory);
|
|
||||||
Directory.CreateDirectory(settings.downloadLocation);
|
|
||||||
Directory.CreateDirectory(settings.coverImageCache);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
|
|
||||||
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
|
|
||||||
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
|
|
||||||
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
|
|
||||||
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga", "Loading Taskmanager.");
|
|
||||||
TaskManager taskManager = new (settings, logger);
|
|
||||||
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
|
||||||
nm.SendNotification("Tranga-API", "Started Tranga-API");
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
|
||||||
|
|
||||||
string corsHeader = "Tranga";
|
|
||||||
builder.Services.AddCors(options =>
|
|
||||||
{
|
|
||||||
options.AddPolicy(name: corsHeader,
|
|
||||||
policy =>
|
|
||||||
{
|
|
||||||
policy.AllowAnyOrigin();
|
|
||||||
policy.WithMethods("GET", "POST", "DELETE");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var app = builder.Build();
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
|
|
||||||
app.UseCors(corsHeader);
|
|
||||||
|
|
||||||
app.MapGet("/Controllers/Get", () => taskManager.GetAvailableConnectors().Keys.ToArray());
|
|
||||||
|
|
||||||
app.MapGet("/Publications/GetKnown", (string? internalId) =>
|
|
||||||
{
|
|
||||||
if(internalId is null)
|
|
||||||
return taskManager.GetAllPublications();
|
|
||||||
|
|
||||||
return new [] { taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId) };
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Publications/GetFromConnector", (string connectorName, string title) =>
|
|
||||||
{
|
|
||||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return Array.Empty<Publication>();
|
|
||||||
if(title.Length < 4)
|
|
||||||
return Array.Empty<Publication>();
|
|
||||||
return taskManager.GetPublicationsFromConnector(connector, title);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Publications/GetChapters",
|
|
||||||
(string connectorName, string internalId, string? onlyNew, string? onlyExisting, string? language) =>
|
|
||||||
{
|
|
||||||
string[] yes = { "true", "yes", "1", "y" };
|
|
||||||
bool newOnly = onlyNew is not null && yes.Contains(onlyNew);
|
|
||||||
bool existingOnly = onlyExisting is not null && yes.Contains(onlyExisting);
|
|
||||||
|
|
||||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return Array.Empty<Chapter>();
|
|
||||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
|
|
||||||
if (publication is null)
|
|
||||||
return Array.Empty<Chapter>();
|
|
||||||
|
|
||||||
if(newOnly)
|
|
||||||
return taskManager.GetNewChaptersList(connector, (Publication)publication, language??"en").ToArray();
|
|
||||||
else if (existingOnly)
|
|
||||||
return taskManager.GetExistingChaptersList(connector, (Publication)publication, language ?? "en").ToArray();
|
|
||||||
else
|
|
||||||
return connector.GetChapters((Publication)publication, language??"en");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));
|
|
||||||
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/CreateMonitorTask",
|
|
||||||
(string connectorName, string internalId, string reoccurrenceTime, string? language) =>
|
|
||||||
{
|
|
||||||
Connector? connector =
|
|
||||||
taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return;
|
|
||||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
|
|
||||||
if (publication is null)
|
|
||||||
return;
|
|
||||||
taskManager.AddTask(new MonitorPublicationTask(connectorName, (Publication)publication, TimeSpan.Parse(reoccurrenceTime), language ?? "en"));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/CreateUpdateLibraryTask", (string reoccurrenceTime) =>
|
|
||||||
{
|
|
||||||
taskManager.AddTask(new UpdateLibrariesTask(TimeSpan.Parse(reoccurrenceTime)));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/CreateDownloadChaptersTask", (string connectorName, string internalId, string chapters, string? language) => {
|
|
||||||
|
|
||||||
Connector? connector =
|
|
||||||
taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return;
|
|
||||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId);
|
|
||||||
if (publication is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IEnumerable<Chapter> toDownload = connector.SearchChapters((Publication)publication, chapters, language ?? "en");
|
|
||||||
foreach(Chapter chapter in toDownload)
|
|
||||||
taskManager.AddTask(new DownloadChapterTask(connectorName, (Publication)publication, chapter, "en"));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
foreach(TrangaTask tTask in taskManager.GetTasksMatching(task, connectorName, internalId: publicationId))
|
|
||||||
taskManager.DeleteTask(tTask);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
return taskManager.GetTasksMatching(task, connectorName:connectorName, searchString:searchString);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return Array.Empty<TrangaTask>();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetProgress", (string taskType, string connectorName, string publicationId, string? chapterSortNumber) =>
|
|
||||||
{
|
|
||||||
Connector? connector =
|
|
||||||
taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return -1f;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask? task = null;
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
if (pTask is TrangaTask.Task.MonitorPublication)
|
|
||||||
{
|
|
||||||
task = taskManager.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId).FirstOrDefault();
|
|
||||||
}else if (pTask is TrangaTask.Task.DownloadChapter && chapterSortNumber is not null)
|
|
||||||
{
|
|
||||||
task = taskManager.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId,
|
|
||||||
chapterSortNumber: chapterSortNumber).FirstOrDefault();
|
|
||||||
}
|
|
||||||
if (task is null)
|
|
||||||
return -1f;
|
|
||||||
|
|
||||||
return task.progress;
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return -1f;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? internalId) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
TrangaTask? task = taskManager
|
|
||||||
.GetTasksMatching(pTask, connectorName: connectorName, internalId: internalId).FirstOrDefault();
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
taskManager.ExecuteTaskNow(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Tasks/GetRunningTasks",
|
|
||||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
|
|
||||||
|
|
||||||
app.MapGet("/Queue/GetList",
|
|
||||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued).OrderBy(task => task.nextExecution));
|
|
||||||
|
|
||||||
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
TrangaTask? task = taskManager
|
|
||||||
.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId).FirstOrDefault();
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
taskManager.AddTaskToQueue(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapDelete("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
|
||||||
TrangaTask? task = taskManager
|
|
||||||
.GetTasksMatching(pTask, connectorName: connectorName, internalId: publicationId).FirstOrDefault();
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
taskManager.RemoveTaskFromQueue(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.MapGet("/Settings/Get", () => taskManager.settings);
|
|
||||||
|
|
||||||
app.MapPost("/Settings/Update",
|
|
||||||
(string? downloadLocation, string? komgaUrl, string? komgaAuth, string? kavitaUrl, string? kavitaUsername,
|
|
||||||
string? kavitaPassword, string? gotifyUrl, string? gotifyAppToken, string? lunaseaWebhook) =>
|
|
||||||
{
|
|
||||||
if (downloadLocation is not null && downloadLocation.Length > 0)
|
|
||||||
taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, logger, downloadLocation);
|
|
||||||
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 5 && komgaAuth.Length > 0)
|
|
||||||
taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Komga, logger, komgaUrl, komgaAuth);
|
|
||||||
if (kavitaUrl is not null && kavitaPassword is not null && kavitaUsername is not null && kavitaUrl.Length > 5 &&
|
|
||||||
kavitaUsername.Length > 0 && kavitaPassword.Length > 0)
|
|
||||||
taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, logger, kavitaUrl, kavitaUsername,
|
|
||||||
kavitaPassword);
|
|
||||||
if (gotifyUrl is not null && gotifyAppToken is not null && gotifyUrl.Length > 5 && gotifyAppToken.Length > 0)
|
|
||||||
taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, logger, gotifyUrl, gotifyAppToken);
|
|
||||||
if(lunaseaWebhook is not null && lunaseaWebhook.Length > 5)
|
|
||||||
taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.LunaSea, logger, lunaseaWebhook);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.Run();
|
|
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:1716",
|
|
||||||
"sslPort": 44391
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"http": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "http://localhost:5177"
|
|
||||||
},
|
|
||||||
"https": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "https://localhost:7036;http://localhost:5177"
|
|
||||||
},
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
|
@ -9,12 +9,6 @@
|
|||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="..\.dockerignore">
|
|
||||||
<Link>.dockerignore</Link>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
10
Tranga.sln
10
Tranga.sln
@ -6,7 +6,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tr
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{48F4E495-75BC-4402-8E03-DEC5B79D7E83}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -26,9 +26,9 @@ Global
|
|||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@ -133,7 +134,7 @@ public abstract class Connector
|
|||||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
/// <param name="chapter">Chapter with Images to retrieve</param>
|
||||||
/// <param name="parentTask">Will be used for progress-tracking</param>
|
/// <param name="parentTask">Will be used for progress-tracking</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
public abstract bool DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null);
|
public abstract HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the already downloaded cover from cache to downloadLocation
|
/// Copies the already downloaded cover from cache to downloadLocation
|
||||||
@ -212,15 +213,15 @@ public abstract class Connector
|
|||||||
/// <param name="fullPath"></param>
|
/// <param name="fullPath"></param>
|
||||||
/// <param name="requestType">RequestType for Rate-Limit</param>
|
/// <param name="requestType">RequestType for Rate-Limit</param>
|
||||||
/// <param name="referrer">referrer used in html request header</param>
|
/// <param name="referrer">referrer used in html request header</param>
|
||||||
private bool DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
private HttpStatusCode DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
||||||
if (!requestResult.success || requestResult.result == Stream.Null)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.result == Stream.Null)
|
||||||
return false;
|
return requestResult.statusCode;
|
||||||
byte[] buffer = new byte[requestResult.result.Length];
|
byte[] buffer = new byte[requestResult.result.Length];
|
||||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||||
File.WriteAllBytes(fullPath, buffer);
|
File.WriteAllBytes(fullPath, buffer);
|
||||||
return true;
|
return requestResult.statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -233,10 +234,10 @@ public abstract class Connector
|
|||||||
/// <param name="requestType">RequestType for RateLimits</param>
|
/// <param name="requestType">RequestType for RateLimits</param>
|
||||||
/// <param name="referrer">Used in http request header</param>
|
/// <param name="referrer">Used in http request header</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
protected bool DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, DownloadChapterTask parentTask, string? comicInfoPath = null, string? referrer = null, CancellationToken? cancellationToken = null)
|
protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, DownloadChapterTask parentTask, string? comicInfoPath = null, string? referrer = null, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||||
@ -244,7 +245,7 @@ public abstract class Connector
|
|||||||
Directory.CreateDirectory(directoryPath);
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
||||||
return false;
|
return HttpStatusCode.OK;
|
||||||
|
|
||||||
//Create a temporary folder to store images
|
//Create a temporary folder to store images
|
||||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||||
@ -256,11 +257,12 @@ public abstract class Connector
|
|||||||
string[] split = imageUrl.Split('.');
|
string[] split = imageUrl.Split('.');
|
||||||
string extension = split[^1];
|
string extension = split[^1];
|
||||||
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
|
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
|
||||||
if (!DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer))
|
HttpStatusCode status = DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||||
return false;
|
if ((int)status < 200 || (int)status >= 300)
|
||||||
|
return status;
|
||||||
parentTask.IncrementProgress(1.0 / imageUrls.Length);
|
parentTask.IncrementProgress(1.0 / imageUrls.Length);
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comicInfoPath is not null)
|
if(comicInfoPath is not null)
|
||||||
@ -272,7 +274,7 @@ public abstract class Connector
|
|||||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
File.SetUnixFileMode(saveArchiveFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
File.SetUnixFileMode(saveArchiveFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
Directory.Delete(tempFolder, true); //Cleanup
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
return true;
|
return HttpStatusCode.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected string SaveCoverImageToCache(string url, byte requestType)
|
protected string SaveCoverImageToCache(string url, byte requestType)
|
||||||
@ -332,7 +334,7 @@ public abstract class Connector
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), "RequestType not configured for rate-limit.");
|
logger?.WriteLine(this.GetType().ToString(), "RequestType not configured for rate-limit.");
|
||||||
return new RequestResult(false, Stream.Null);
|
return new RequestResult(HttpStatusCode.NotAcceptable, Stream.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan rateLimitTimeout = _rateLimit[requestType]
|
TimeSpan rateLimitTimeout = _rateLimit[requestType]
|
||||||
@ -362,19 +364,19 @@ public abstract class Connector
|
|||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
||||||
return new RequestResult(false, Stream.Null);
|
return new RequestResult(response.StatusCode, Stream.Null);
|
||||||
}
|
}
|
||||||
return new RequestResult(true, response.Content.ReadAsStream());
|
return new RequestResult(response.StatusCode, response.Content.ReadAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct RequestResult
|
public struct RequestResult
|
||||||
{
|
{
|
||||||
public bool success { get; }
|
public HttpStatusCode statusCode { get; }
|
||||||
public Stream result { get; }
|
public Stream result { get; }
|
||||||
|
|
||||||
public RequestResult(bool success, Stream result)
|
public RequestResult(HttpStatusCode statusCode, Stream result)
|
||||||
{
|
{
|
||||||
this.success = success;
|
this.statusCode = statusCode;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class MangaDex : Connector
|
|||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(
|
downloadClient.MakeRequest(
|
||||||
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}", (byte)RequestType.Manga);
|
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}", (byte)RequestType.Manga);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
break;
|
break;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ public class MangaDex : Connector
|
|||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(
|
downloadClient.MakeRequest(
|
||||||
$"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed);
|
$"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
break;
|
break;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
|
||||||
@ -207,19 +207,19 @@ public class MangaDex : Connector
|
|||||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
//Request URLs for Chapter-Images
|
//Request URLs for Chapter-Images
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return false;
|
return requestResult.statusCode;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
return false;
|
return HttpStatusCode.NoContent;
|
||||||
|
|
||||||
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
||||||
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
||||||
@ -248,7 +248,7 @@ public class MangaDex : Connector
|
|||||||
//Request information where to download Cover
|
//Request information where to download Cover
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl);
|
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return null;
|
return null;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
@ -268,7 +268,7 @@ public class MangaDex : Connector
|
|||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return ret;
|
return ret;
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
|
@ -27,7 +27,7 @@ public class Manganato : Connector
|
|||||||
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return Array.Empty<Publication>();
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
return ParsePublicationsFromHtml(requestResult.result);
|
return ParsePublicationsFromHtml(requestResult.result);
|
||||||
@ -52,7 +52,7 @@ public class Manganato : Connector
|
|||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(url, (byte)1);
|
downloadClient.MakeRequest(url, (byte)1);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return Array.Empty<Publication>();
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
||||||
@ -131,7 +131,7 @@ public class Manganato : Connector
|
|||||||
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return Array.Empty<Chapter>();
|
return Array.Empty<Chapter>();
|
||||||
|
|
||||||
//Return Chapters ordered by Chapter-Number
|
//Return Chapters ordered by Chapter-Number
|
||||||
@ -169,16 +169,16 @@ public class Manganato : Connector
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
string requestUrl = chapter.url;
|
string requestUrl = chapter.url;
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return false;
|
return requestResult.statusCode;
|
||||||
|
|
||||||
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.result);
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.result);
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class Mangasee : Connector
|
|||||||
string requestUrl = $"https://mangasee123.com/_search.php";
|
string requestUrl = $"https://mangasee123.com/_search.php";
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
downloadClient.MakeRequest(requestUrl, (byte)1);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return Array.Empty<Publication>();
|
return Array.Empty<Publication>();
|
||||||
|
|
||||||
return ParsePublicationsFromHtml(requestResult.result, publicationTitle);
|
return ParsePublicationsFromHtml(requestResult.result, publicationTitle);
|
||||||
@ -110,7 +110,7 @@ public class Mangasee : Connector
|
|||||||
{
|
{
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1);
|
downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1);
|
||||||
if (!requestResult.success)
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
return Array.Empty<Publication>();
|
return Array.Empty<Publication>();
|
||||||
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, orderedItem.s, orderedItem.i, orderedItem.a));
|
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, orderedItem.s, orderedItem.i, orderedItem.a));
|
||||||
}
|
}
|
||||||
@ -209,17 +209,17 @@ public class Mangasee : Connector
|
|||||||
return ret.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
return ret.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
while (this._browser is null && !(cancellationToken?.IsCancellationRequested??false))
|
while (this._browser is null && !(cancellationToken?.IsCancellationRequested??false))
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download...");
|
logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download...");
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested??false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
||||||
IPage page = _browser!.NewPageAsync().Result;
|
IPage page = _browser!.NewPageAsync().Result;
|
||||||
@ -240,7 +240,6 @@ public class Mangasee : Connector
|
|||||||
|
|
||||||
return DownloadChapterImages(urls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
return DownloadChapterImages(urls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
||||||
}
|
}
|
||||||
|
return response.Status;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -82,18 +82,21 @@ public class TaskManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (TrangaTask failedTask in _allTasks.Where(taskQuery =>
|
TrangaTask[] failedDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||||
taskQuery.state is TrangaTask.ExecutionState.Failed))
|
taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray();
|
||||||
|
foreach (TrangaTask failedDownloadChapterTask in failedDownloadChapterTasks)
|
||||||
{
|
{
|
||||||
switch (failedTask.task)
|
DeleteTask(failedDownloadChapterTask);
|
||||||
{
|
TrangaTask newTask = failedDownloadChapterTask.Clone();
|
||||||
case TrangaTask.Task.DownloadChapter:
|
failedDownloadChapterTask.parentTask?.AddChildTask(newTask);
|
||||||
DeleteTask(failedTask);
|
AddTask(newTask);
|
||||||
TrangaTask newTask = failedTask.Clone();
|
}
|
||||||
failedTask.parentTask?.AddChildTask(newTask);
|
|
||||||
AddTask(newTask);
|
TrangaTask[] successfulDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||||
break;
|
taskQuery.state is TrangaTask.ExecutionState.Success && taskQuery is DownloadChapterTask).ToArray();
|
||||||
}
|
foreach(TrangaTask successfulDownloadChapterTask in successfulDownloadChapterTasks)
|
||||||
|
{
|
||||||
|
DeleteTask(successfulDownloadChapterTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting))
|
if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting))
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Net;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Logging;
|
using Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@ -25,14 +26,14 @@ public abstract class TrangaTask
|
|||||||
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
||||||
public string? parentTaskId { get; set; }
|
public string? parentTaskId { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore] protected HashSet<TrangaTask> childTasks { get; }
|
[Newtonsoft.Json.JsonIgnore] protected HashSet<TrangaTask> childTasks { get; }
|
||||||
[Newtonsoft.Json.JsonIgnore] public double progress => GetProgress();
|
public double progress => GetProgress();
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => progress != 0 ? lastChange.Add(GetRemainingTime()) : DateTime.MaxValue;
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => progress != 0 ? lastChange.Add(GetRemainingTime()) : DateTime.MaxValue;
|
||||||
[Newtonsoft.Json.JsonIgnore]public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||||
|
|
||||||
public enum ExecutionState { Waiting, Enqueued, Running, Failed }
|
public enum ExecutionState { Waiting, Enqueued, Running, Failed, Success }
|
||||||
|
|
||||||
protected TrangaTask(Task task, TimeSpan reoccurrence, TrangaTask? parentTask = null)
|
protected TrangaTask(Task task, TimeSpan reoccurrence, TrangaTask? parentTask = null)
|
||||||
{
|
{
|
||||||
@ -53,7 +54,7 @@ public abstract class TrangaTask
|
|||||||
/// <param name="taskManager"></param>
|
/// <param name="taskManager"></param>
|
||||||
/// <param name="logger"></param>
|
/// <param name="logger"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
protected abstract bool ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null);
|
protected abstract HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null);
|
||||||
|
|
||||||
public abstract TrangaTask Clone();
|
public abstract TrangaTask Clone();
|
||||||
|
|
||||||
@ -71,18 +72,24 @@ public abstract class TrangaTask
|
|||||||
this.state = ExecutionState.Running;
|
this.state = ExecutionState.Running;
|
||||||
this.executionStarted = DateTime.Now;
|
this.executionStarted = DateTime.Now;
|
||||||
this.lastChange = DateTime.Now;
|
this.lastChange = DateTime.Now;
|
||||||
bool success = ExecuteTask(taskManager, logger, cancellationToken);
|
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
||||||
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
if (success)
|
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
||||||
{
|
{
|
||||||
this.lastExecuted = DateTime.Now;
|
this.lastExecuted = DateTime.Now;
|
||||||
this.state = ExecutionState.Waiting;
|
if (this is DownloadChapterTask)
|
||||||
|
this.state = ExecutionState.Success;
|
||||||
|
else
|
||||||
|
this.state = ExecutionState.Waiting;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (this is DownloadChapterTask && statusCode == HttpStatusCode.NotFound)
|
||||||
|
this.state = ExecutionState.Success;
|
||||||
|
else
|
||||||
|
this.state = ExecutionState.Failed;
|
||||||
this.lastExecuted = DateTime.MaxValue;
|
this.lastExecuted = DateTime.MaxValue;
|
||||||
this.state = ExecutionState.Failed;
|
|
||||||
}
|
}
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
|
||||||
}
|
}
|
||||||
@ -99,8 +106,8 @@ public abstract class TrangaTask
|
|||||||
|
|
||||||
private TimeSpan GetRemainingTime()
|
private TimeSpan GetRemainingTime()
|
||||||
{
|
{
|
||||||
if(progress == 0 || lastChange > executionStarted)
|
if(progress == 0 || lastChange == DateTime.MaxValue || executionStarted == DateTime.UnixEpoch)
|
||||||
return DateTime.MaxValue.Subtract(DateTime.Now.AddYears(1));
|
return TimeSpan.Zero;
|
||||||
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
||||||
return elapsed.Divide(progress).Subtract(elapsed);
|
return elapsed.Divide(progress).Subtract(elapsed);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Logging;
|
using System.Net;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
namespace Tranga.TrangaTasks;
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
@ -19,15 +20,14 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||||
connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings);
|
connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings);
|
||||||
bool downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
|
HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
|
||||||
taskManager.DeleteTask(this);
|
if((int)downloadSuccess >= 200 && (int)downloadSuccess < 300 && parentTask is not null)
|
||||||
if(downloadSuccess && parentTask is not null)
|
|
||||||
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
||||||
nm.SendNotification("New Chapter downloaded", $"{this.publication.sortName} {this.chapter.chapterNumber} {this.chapter.name}");
|
nm.SendNotification("New Chapter downloaded", $"{this.publication.sortName} {this.chapter.chapterNumber} {this.chapter.name}");
|
||||||
return downloadSuccess;
|
return downloadSuccess;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Logging;
|
using System.Net;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
namespace Tranga.TrangaTasks;
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
@ -14,10 +15,10 @@ public class MonitorPublicationTask : TrangaTask
|
|||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||||
|
|
||||||
//Check if Publication already has a Folder
|
//Check if Publication already has a Folder
|
||||||
@ -36,7 +37,7 @@ public class MonitorPublicationTask : TrangaTask
|
|||||||
taskManager.AddTask(newTask);
|
taskManager.AddTask(newTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return HttpStatusCode.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TrangaTask Clone()
|
public override TrangaTask Clone()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Logging;
|
using System.Net;
|
||||||
|
using Logging;
|
||||||
|
|
||||||
namespace Tranga.TrangaTasks;
|
namespace Tranga.TrangaTasks;
|
||||||
|
|
||||||
@ -8,13 +9,13 @@ public class UpdateLibrariesTask : TrangaTask
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
protected override HttpStatusCode ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||||
{
|
{
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
if (cancellationToken?.IsCancellationRequested ?? false)
|
||||||
return false;
|
return HttpStatusCode.RequestTimeout;
|
||||||
foreach(LibraryManager lm in taskManager.settings.libraryManagers)
|
foreach(LibraryManager lm in taskManager.settings.libraryManagers)
|
||||||
lm.UpdateLibrary();
|
lm.UpdateLibrary();
|
||||||
return true;
|
return HttpStatusCode.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TrangaTask Clone()
|
public override TrangaTask Clone()
|
||||||
|
@ -43,60 +43,60 @@ function DeleteData(uri){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GetAvailableControllers(){
|
async function GetAvailableControllers(){
|
||||||
var uri = apiUri + "/Controllers/Get";
|
var uri = apiUri + "/Connectors";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetPublicationFromConnector(connectorName, title){
|
async function GetPublicationFromConnector(connectorName, title){
|
||||||
var uri = apiUri + `/Publications/GetFromConnector?connectorName=${connectorName}&title=${title}`;
|
var uri = apiUri + `/Publications/FromConnector?connectorName=${connectorName}&title=${title}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetKnownPublications(){
|
async function GetKnownPublications(){
|
||||||
var uri = apiUri + "/Publications/GetKnown";
|
var uri = apiUri + "/Publications/Known";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetPublication(internalId){
|
async function GetPublication(internalId){
|
||||||
var uri = apiUri + `/Publications/GetKnown?internalId=${internalId}`;
|
var uri = apiUri + `/Publications/Known?internalId=${internalId}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetChapters(internalId, connectorName, onlyNew, language){
|
async function GetChapters(internalId, connectorName, onlyNew, language){
|
||||||
var uri = apiUri + `/Publications/GetChapters?internalId=${internalId}&connectorName=${connectorName}&onlyNew=${onlyNew}&language=${language}`;
|
var uri = apiUri + `/Publications/Chapters?internalId=${internalId}&connectorName=${connectorName}&onlyNew=${onlyNew}&language=${language}`;
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetTaskTypes(){
|
async function GetTaskTypes(){
|
||||||
var uri = apiUri + "/Tasks/GetTypes";
|
var uri = apiUri + "/Tasks/Types";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
async function GetRunningTasks(){
|
async function GetRunningTasks(){
|
||||||
var uri = apiUri + "/Tasks/GetRunningTasks";
|
var uri = apiUri + "/Tasks/RunningTasks";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetDownloadTasks(){
|
async function GetDownloadTasks(){
|
||||||
var uri = apiUri + "/Tasks/Get?taskType=DownloadNewChapters";
|
var uri = apiUri + "/Tasks?taskType=DownloadNewChapters";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetSettings(){
|
async function GetSettings(){
|
||||||
var uri = apiUri + "/Settings/Get";
|
var uri = apiUri + "/Settings";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetKomgaTask(){
|
async function GetKomgaTask(){
|
||||||
var uri = apiUri + "/Tasks/Get?taskType=UpdateLibraries";
|
var uri = apiUri + "/Tasks?taskType=UpdateLibraries";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ function UpdateLunaSea(lunaseaWebhook){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function DeleteTask(taskType, connectorName, publicationId){
|
function DeleteTask(taskType, connectorName, publicationId){
|
||||||
var uri = apiUri + `/Tasks/Delete?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}`;
|
var uri = apiUri + `/Tasks?taskType=${taskType}&connectorName=${connectorName}&publicationId=${publicationId}`;
|
||||||
DeleteData(uri);
|
DeleteData(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ function DequeueTask(taskType, connectorName, publicationId){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GetQueue(){
|
async function GetQueue(){
|
||||||
var uri = apiUri + "/Queue/GetList";
|
var uri = apiUri + "/Queue/List";
|
||||||
let json = await GetData(uri);
|
let json = await GetData(uri);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ services:
|
|||||||
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
||||||
- ./Manga:/Manga
|
- ./Manga:/Manga
|
||||||
ports:
|
ports:
|
||||||
- 6531:80
|
- "6531:6531"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
tranga-website:
|
tranga-website:
|
||||||
image: glax/tranga-website:latest
|
image: glax/tranga-website:latest
|
||||||
@ -15,7 +15,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
||||||
ports:
|
ports:
|
||||||
- 9555:80
|
- "9555:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- tranga-api
|
- tranga-api
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
Reference in New Issue
Block a user