2
0

Compare commits

..

10 Commits

Author SHA1 Message Date
cf171d5c38 Bring CLI in line with new Methods 2023-05-21 22:02:35 +02:00
6d49b4b934 Swagger 2023-05-21 22:02:19 +02:00
b55d2a2d06 no duplicate keys 2023-05-21 22:02:05 +02:00
737eebf599 bring /settings/update in line with new methods 2023-05-21 22:01:56 +02:00
aef01b684c Fixed null on settings.komga 2023-05-21 22:01:40 +02:00
53bff61174 Added Swagger 2023-05-21 22:01:28 +02:00
431a602a40 Added Method UpdateSettings to SettingsData
Added Method UpdateSettings to TaskManager (to export data after update)
2023-05-21 22:01:04 +02:00
9afb81cee2 string and json 2023-05-21 21:24:18 +02:00
ea69b355b5 No duplicate keys 2023-05-21 21:24:04 +02:00
84dbc36bbf dont add duplicates 2023-05-21 21:23:51 +02:00
5 changed files with 41 additions and 19 deletions

View File

@ -25,8 +25,14 @@ else
TaskManager taskManager = new (settings, logger);
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers().AddNewtonsoftJson();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseSwagger();
app.UseSwaggerUI();
app.MapGet("/GetAvailableControllers", () => taskManager.GetAvailableConnectors());
@ -99,24 +105,18 @@ app.MapPost("/Queue/Dequeue", (string taskType, string? connectorName, string? p
app.MapGet("/Settings/Get", () => new Settings(taskManager.settings));
app.MapPost("/Setting/Update", (string? downloadLocation, string? komgaUrl, string? komgaAuth) =>
{
if(downloadLocation is not null)
taskManager.settings.downloadLocation = downloadLocation;
if(komgaUrl is not null && komgaAuth is not null)
taskManager.settings.komga = new Komga(komgaUrl, komgaAuth, logger);
});
app.MapPost("/Settings/Update", (string? downloadLocation, string? komgaUrl, string? komgaAuth) => taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth) );
app.Run();
class Settings
{
public string downloadLocation;
public Komga? komga;
public string downloadLocation { get; }
public Komga? komga { get; }
public Settings(TaskManager.SettingsData settings)
{
this.downloadLocation = settings.downloadLocation;
this.komga = komga;
this.komga = settings.komga;
}
}

View File

@ -21,6 +21,8 @@
<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>

View File

@ -41,7 +41,7 @@ public static class Tranga_Cli
while(tmpPath is null)
tmpPath = Console.ReadLine();
if(tmpPath.Length > 0)
settings.downloadLocation = tmpPath;
settings.UpdateSettings(pDownloadLocation: tmpPath, null);
Console.WriteLine($"Komga BaseURL [{settings.komga?.baseUrl}]:");
string? tmpUrl = Console.ReadLine();
@ -74,7 +74,7 @@ public static class Tranga_Cli
}
} while (key != ConsoleKey.Enter);
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass, logger);
settings.UpdateSettings(null, new Komga(tmpUrl, tmpUser, tmpPass, logger));
}
logger.WriteLine("Tranga_CLI", "Loaded.");

View File

@ -63,7 +63,7 @@ public class MangaDex : Connector
{
JsonObject altTitleObject = (JsonObject)altTitleNode!;
string key = ((IDictionary<string, JsonNode?>)altTitleObject).Keys.ToArray()[0];
altTitlesDict.Add(key, altTitleObject[key]!.GetValue<string>());
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
}
JsonArray tagsObject = attributes["tags"]!.AsArray();

View File

@ -43,6 +43,15 @@ public class TaskManager
taskChecker.Start();
}
public void UpdateSettings(string? downloadLocation, string? komgaUrl, string? komgaAuth)
{
Komga? komga = null;
if (komgaUrl is not null && komgaAuth is not null)
komga = new Komga(komgaUrl, komgaAuth, null);
settings.UpdateSettings(downloadLocation, komga);
ExportData();
}
public TaskManager(SettingsData settings, Logger? logger = null)
{
this.logger = logger;
@ -154,7 +163,7 @@ public class TaskManager
trangaTask.publication?.downloadUrl == publication?.downloadUrl))
{
if(task != TrangaTask.Task.UpdatePublications)
_chapterCollection.Add((Publication)publication!, new List<Chapter>());
_chapterCollection.TryAdd((Publication)publication!, new List<Chapter>());
_allTasks.Add(newTask);
}
}
@ -232,7 +241,10 @@ public class TaskManager
{
Publication[] ret = connector.GetPublications(title ?? "");
foreach (Publication publication in ret)
{
if(!_chapterCollection.Any(pub => pub.Key.sortName == publication.sortName))
this._chapterCollection.TryAdd(publication, new List<Chapter>());
}
return ret;
}
@ -308,9 +320,9 @@ public class TaskManager
public class SettingsData
{
public string downloadLocation { get; set; }
public string downloadLocation { get; private set; }
public string settingsFilePath { get; }
public Komga? komga { get; set; }
public Komga? komga { get; private set; }
public HashSet<TrangaTask> allTasks { get; }
public SettingsData(string downloadLocation, string? settingsFilePath, Komga? komga, HashSet<TrangaTask> allTasks)
@ -322,5 +334,13 @@ public class TaskManager
this.komga = komga;
this.allTasks = allTasks;
}
public void UpdateSettings(string? pDownloadLocation, Komga? pKomga)
{
if(pDownloadLocation is not null)
this.downloadLocation = pDownloadLocation;
if(pKomga is not null)
this.komga = pKomga;
}
}
}