Added Endpoint /v2/Manga lists all known Manga

Implemented /v2/Manga/*
This commit is contained in:
2024-04-22 04:42:10 +02:00
parent c3231327f9
commit ea866e0136
3 changed files with 65 additions and 8 deletions

View File

@ -23,10 +23,11 @@ public partial class Server : GlobalBase, IDisposable
{
new ("GET", @"/v2/Connector/Types", GetV2ConnectorTypes),
new ("GET", @"/v2/Connector/([a-zA-Z]+)/GetManga", GetV2ConnectorConnectorNameGetManga),
new ("GET", @"/v2/Manga/([-A-Za-z0-9+/]*={0,3})", GetV2MangaInternalId),
new ("DELETE", @"/v2/Manga/([-A-Za-z0-9+/]*={0,3})", DeleteV2MangaInternalId),
new ("GET", @"/v2/Manga/([-A-Za-z0-9+/]*={0,3})/Cover", GetV2MangaInternalIdCover),
new ("GET", @"/v2/Manga/([-A-Za-z0-9+/]*={0,3})/Chapters", GetV2MangaInternalIdChapters),
new ("GET", @"/v2/Manga", GetV2Manga),
new ("GET", @"/v2/Manga/([-A-Za-z0-9]*={0,3})", GetV2MangaInternalId),
new ("DELETE", @"/v2/Manga/([-A-Za-z0-9]*={0,3})", DeleteV2MangaInternalId),
new ("GET", @"/v2/Manga/([-A-Za-z0-9]*={0,3})/Cover", GetV2MangaInternalIdCover),
new ("GET", @"/v2/Manga/([-A-Za-z0-9]*={0,3})/Chapters", GetV2MangaInternalIdChapters),
new ("GET", @"/v2/Jobs", GetV2Jobs),
new ("GET", @"/v2/Jobs/Running", GetV2JobsRunning),
new ("GET", @"/v2/Jobs/Waiting", GetV2JobsWaiting),

View File

@ -1,27 +1,63 @@
using System.Net;
using System.Text.RegularExpressions;
using Tranga.Jobs;
namespace Tranga.Server;
public partial class Server
{
private ValueTuple<HttpStatusCode, object?> GetV2Manga(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, cachedPublications.Select(m => m.internalId));
}
private ValueTuple<HttpStatusCode, object?> GetV2MangaInternalId(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
if(groups.Count < 1 ||
!_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) ||
manga is null)
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, manga);
}
private ValueTuple<HttpStatusCode, object?> DeleteV2MangaInternalId(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
if(groups.Count < 1 ||
!_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) ||
manga is null)
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
Job[] jobs = _parent.jobBoss.GetJobsLike(publication: manga).ToArray();
_parent.jobBoss.RemoveJobs(jobs);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, null);
}
private ValueTuple<HttpStatusCode, object?> GetV2MangaInternalIdCover(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
if(groups.Count < 1 ||
!_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) ||
manga is null)
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
string filePath = settings.GetFullCoverPath((Manga)manga!);
if (File.Exists(filePath))
{
FileStream coverStream = new(filePath, FileMode.Open);
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, coverStream);
}
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, "Cover-File not found.");
}
private ValueTuple<HttpStatusCode, object?> GetV2MangaInternalIdChapters(GroupCollection groups, Dictionary<string, string> requestParameters)
{
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotImplemented, "Not Implemented");
if(groups.Count < 1 ||
!_parent.TryGetPublicationById(groups[1].Value, out Manga? manga) ||
manga is null)
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.NotFound, $"Manga with ID '{groups[1].Value} could not be found.'");
Chapter[] chapters = requestParameters.TryGetValue("language", out string? parameter) switch
{
true => manga.Value.mangaConnector.GetChapters((Manga)manga, parameter),
false => manga.Value.mangaConnector.GetChapters((Manga)manga)
};
return new ValueTuple<HttpStatusCode, object?>(HttpStatusCode.OK, chapters);
}
}