2
0

Compare commits

..

6 Commits

4 changed files with 31 additions and 31 deletions

View File

@ -67,7 +67,7 @@ public struct Manga
while (this.folderName.EndsWith('.')) while (this.folderName.EndsWith('.'))
this.folderName = this.folderName.Substring(0, this.folderName.Length - 1); this.folderName = this.folderName.Substring(0, this.folderName.Length - 1);
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter)); string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}")); this.internalId = DateTime.Now.Ticks.ToString();
this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f; this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f;
this.latestChapterDownloaded = 0; this.latestChapterDownloaded = 0;
this.latestChapterAvailable = 0; this.latestChapterAvailable = 0;

View File

@ -1,4 +1,6 @@
using Newtonsoft.Json; using System.Data;
using System.Diagnostics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace Tranga.MangaConnectors; namespace Tranga.MangaConnectors;
@ -22,29 +24,22 @@ public class MangaConnectorJsonConverter : JsonConverter
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{ {
JObject jo = JObject.Load(reader); JObject jo = JObject.Load(reader);
switch (jo.GetValue("name")!.Value<string>()!) string? connectorName = jo.Value<string>("name");
if (connectorName is null)
throw new ConstraintException("Name can not be null.");
return connectorName switch
{ {
case "MangaDex": "MangaDex" => this._connectors.First(c => c is MangaDex),
return this._connectors.First(c => c is MangaDex); "Manganato" => this._connectors.First(c => c is Manganato),
case "Manganato": "MangaKatana" => this._connectors.First(c => c is MangaKatana),
return this._connectors.First(c => c is Manganato); "Mangasee" => this._connectors.First(c => c is Mangasee),
case "MangaKatana": "Mangaworld" => this._connectors.First(c => c is Mangaworld),
return this._connectors.First(c => c is MangaKatana); "Bato" => this._connectors.First(c => c is Bato),
case "Mangasee": "Manga4Life" => this._connectors.First(c => c is MangaLife),
return this._connectors.First(c => c is Mangasee); "ManhuaPlus" => this._connectors.First(c => c is ManhuaPlus),
case "Mangaworld": "MangaHere" => this._connectors.First(c => c is MangaHere),
return this._connectors.First(c => c is Mangaworld); _ => throw new UnreachableException($"Could not find Connector with name {connectorName}")
case "Bato": };
return this._connectors.First(c => c is Bato);
case "Manga4Life":
return this._connectors.First(c => c is MangaLife);
case "ManhuaPlus":
return this._connectors.First(c => c is ManhuaPlus);
case "MangaHere":
return this._connectors.First(c => c is MangaHere);
}
throw new Exception();
} }
public override bool CanWrite => false; public override bool CanWrite => false;

View File

@ -243,7 +243,7 @@ public class MangaDex : MangaConnector
continue; continue;
} }
if(chapterNum is not "null") if(chapterNum is not "null" && !chapters.Any(chp => chp.volumeNumber.Equals(volume) && chp.chapterNumber.Equals(chapterNum)))
chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId)); chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId));
} }
} }

View File

@ -63,10 +63,11 @@ public class Server : GlobalBase
{ {
HttpListenerRequest request = context.Request; HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response; HttpListenerResponse response = context.Response;
if(request.HttpMethod == "OPTIONS") if (request.Url!.LocalPath.Contains("favicon"))
SendResponse(HttpStatusCode.OK, context.Response); {
if(request.Url!.LocalPath.Contains("favicon"))
SendResponse(HttpStatusCode.NoContent, response); SendResponse(HttpStatusCode.NoContent, response);
return;
}
switch (request.HttpMethod) switch (request.HttpMethod)
{ {
@ -79,7 +80,10 @@ public class Server : GlobalBase
case "DELETE": case "DELETE":
HandleDelete(request, response); HandleDelete(request, response);
break; break;
default: case "OPTIONS":
SendResponse(HttpStatusCode.OK, context.Response);
break;
default:
SendResponse(HttpStatusCode.BadRequest, response); SendResponse(HttpStatusCode.BadRequest, response);
break; break;
} }
@ -707,14 +711,15 @@ public class Server : GlobalBase
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null) private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
{ {
//Log($"Response: {statusCode} {content}"); //Log($"Response: {statusCode} {content}");
response.StatusCode = (int)statusCode; response.StatusCode = (int)statusCode;
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With"); 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-Allow-Methods", "GET, POST, DELETE");
response.AddHeader("Access-Control-Max-Age", "1728000"); response.AddHeader("Access-Control-Max-Age", "1728000");
response.AppendHeader("Access-Control-Allow-Origin", "*"); response.AppendHeader("Access-Control-Allow-Origin", "*");
try try
{ {
if (content is not Stream) if (content is not Stream)
{ {
response.ContentType = "application/json"; response.ContentType = "application/json";
@ -750,7 +755,7 @@ public class Server : GlobalBase
stream.Close(); stream.Close();
} }
} }
catch (HttpListenerException e) catch (Exception e)
{ {
Log(e.ToString()); Log(e.ToString());
} }