Added API call to retrieve cover with internalId.
No need to mount imageCache over multiple containers.
This commit is contained in:
parent
394829ee36
commit
32036df057
@ -105,37 +105,54 @@ public class Server : GlobalBase
|
||||
private void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
|
||||
{
|
||||
Dictionary<string, string> requestVariables = GetRequestVariables(request.Url!.Query);
|
||||
string? connectorName, jobId;
|
||||
MangaConnector connector;
|
||||
string? connectorName, jobId, internalId;
|
||||
MangaConnector? connector;
|
||||
Manga? manga;
|
||||
string path = Regex.Match(request.Url!.LocalPath, @"[A-z0-9]+(\/[A-z0-9]+)*").Value;
|
||||
switch (path)
|
||||
{
|
||||
case "Connectors":
|
||||
SendResponse(HttpStatusCode.OK, response, _parent.GetConnectors().Select(con => con.name).ToArray());
|
||||
break;
|
||||
case "Manga/Cover":
|
||||
if (!requestVariables.TryGetValue("internalId", out internalId) ||
|
||||
!_parent.TryGetPublicationById(internalId, out manga))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
|
||||
string filePath = settings.GetFullCoverPath((Manga)manga!);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
FileStream coverStream = new(filePath, FileMode.Open);
|
||||
SendResponse(HttpStatusCode.OK, response, coverStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendResponse(HttpStatusCode.NotFound, response);
|
||||
}
|
||||
break;
|
||||
case "Manga/FromConnector":
|
||||
if (!requestVariables.TryGetValue("connector", out connectorName) ||
|
||||
!requestVariables.TryGetValue("title", out string? title) ||
|
||||
_parent.GetConnector(connectorName) is null)
|
||||
!_parent.TryGetConnector(connectorName, out connector))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
connector = _parent.GetConnector(connectorName)!;
|
||||
SendResponse(HttpStatusCode.OK, response, connector.GetPublications(title));
|
||||
SendResponse(HttpStatusCode.OK, response, connector!.GetPublications(title));
|
||||
break;
|
||||
case "Manga/Chapters":
|
||||
if(!requestVariables.TryGetValue("connector", out connectorName) ||
|
||||
!requestVariables.TryGetValue("internalId", out string? internalId) ||
|
||||
_parent.GetConnector(connectorName) is null ||
|
||||
_parent.GetPublicationById(internalId) is null)
|
||||
!requestVariables.TryGetValue("internalId", out internalId) ||
|
||||
!_parent.TryGetConnector(connectorName, out connector) ||
|
||||
!_parent.TryGetPublicationById(internalId, out manga))
|
||||
{
|
||||
SendResponse(HttpStatusCode.BadRequest, response);
|
||||
break;
|
||||
}
|
||||
connector = _parent.GetConnector(connectorName)!;
|
||||
Manga manga = (Manga)_parent.GetPublicationById(internalId)!;
|
||||
SendResponse(HttpStatusCode.OK, response, connector.GetChapters(manga));
|
||||
SendResponse(HttpStatusCode.OK, response, connector!.GetChapters((Manga)manga!));
|
||||
break;
|
||||
case "Jobs":
|
||||
if (!requestVariables.TryGetValue("jobId", out jobId))
|
||||
@ -430,6 +447,9 @@ public class Server : GlobalBase
|
||||
response.AddHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
|
||||
response.AddHeader("Access-Control-Max-Age", "1728000");
|
||||
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
if (content is not FileStream stream)
|
||||
{
|
||||
response.ContentType = "application/json";
|
||||
try
|
||||
{
|
||||
@ -443,4 +463,11 @@ public class Server : GlobalBase
|
||||
Log(e.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.CopyTo(response.OutputStream);
|
||||
response.OutputStream.Close();
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,12 @@ public partial class Tranga : GlobalBase
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool TryGetConnector(string name, out MangaConnector? connector)
|
||||
{
|
||||
connector = GetConnector(name);
|
||||
return connector is not null;
|
||||
}
|
||||
|
||||
public IEnumerable<MangaConnector> GetConnectors()
|
||||
{
|
||||
return connectors;
|
||||
@ -46,6 +52,12 @@ public partial class Tranga : GlobalBase
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool TryGetPublicationById(string internalId, out Manga? manga)
|
||||
{
|
||||
manga = GetPublicationById(internalId);
|
||||
return manga is not null;
|
||||
}
|
||||
|
||||
private void StartJobBoss()
|
||||
{
|
||||
Thread t = new (() =>
|
||||
|
@ -127,4 +127,9 @@ public class TrangaSettings
|
||||
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
||||
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this));
|
||||
}
|
||||
|
||||
public string GetFullCoverPath(Manga manga)
|
||||
{
|
||||
return Path.Join(this.coverImageCache, manga.coverFileNameInCache);
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ services:
|
||||
image: glax/tranga-api:latest
|
||||
container_name: tranga-api
|
||||
volumes:
|
||||
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
||||
- ./Manga:/Manga
|
||||
ports:
|
||||
- "6531:6531"
|
||||
@ -12,8 +11,6 @@ services:
|
||||
tranga-website:
|
||||
image: glax/tranga-website:latest
|
||||
container_name: tranga-website
|
||||
volumes:
|
||||
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
||||
ports:
|
||||
- "9555:80"
|
||||
depends_on:
|
||||
|
Loading…
Reference in New Issue
Block a user