mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-09 08:22:11 +02:00
[postgres-Server-V2] Formatter fix
This commit is contained in:
parent
dd1d67ac11
commit
7dc34c10e5
@ -8,11 +8,29 @@ namespace API.Schema;
|
||||
[PrimaryKey("ChapterId")]
|
||||
public class Chapter : IComparable<Chapter>
|
||||
{
|
||||
[MaxLength(64)]
|
||||
public string ChapterId { get; init; } = TokenGen.CreateToken(typeof(Chapter), 64);
|
||||
public Chapter(Manga parentManga, string url, string chapterNumber, int? volumeNumber = null, string? title = null)
|
||||
: this(parentManga.MangaId, url, chapterNumber, volumeNumber, title)
|
||||
{
|
||||
ParentManga = parentManga;
|
||||
ArchiveFileName = BuildArchiveFileName();
|
||||
}
|
||||
|
||||
public Chapter(string parentMangaId, string url, string chapterNumber,
|
||||
int? volumeNumber = null, string? title = null)
|
||||
{
|
||||
ParentMangaId = parentMangaId;
|
||||
Url = url;
|
||||
ChapterNumber = chapterNumber;
|
||||
VolumeNumber = volumeNumber;
|
||||
Title = title;
|
||||
}
|
||||
|
||||
[MaxLength(64)] public string ChapterId { get; init; } = TokenGen.CreateToken(typeof(Chapter), 64);
|
||||
|
||||
public int? VolumeNumber { get; private set; }
|
||||
[MaxLength(10)]
|
||||
public string ChapterNumber { get; private set; }
|
||||
|
||||
[MaxLength(10)] public string ChapterNumber { get; private set; }
|
||||
|
||||
public string Url { get; internal set; }
|
||||
public string? Title { get; private set; }
|
||||
public string ArchiveFileName { get; private set; }
|
||||
@ -21,54 +39,47 @@ public class Chapter : IComparable<Chapter>
|
||||
public string ParentMangaId { get; internal set; }
|
||||
public Manga? ParentManga { get; init; }
|
||||
|
||||
public Chapter(Manga parentManga, string url, string chapterNumber, int? volumeNumber = null, string? title = null)
|
||||
: this(parentManga.MangaId, url, chapterNumber, volumeNumber, title)
|
||||
public int CompareTo(Chapter? other)
|
||||
{
|
||||
this.ParentManga = parentManga;
|
||||
this.ArchiveFileName = BuildArchiveFileName();
|
||||
}
|
||||
|
||||
public Chapter(string parentMangaId, string url, string chapterNumber,
|
||||
int? volumeNumber = null, string? title = null)
|
||||
if (other is not { } otherChapter)
|
||||
throw new ArgumentException($"{other} can not be compared to {this}");
|
||||
return VolumeNumber?.CompareTo(otherChapter.VolumeNumber) switch
|
||||
{
|
||||
this.ParentMangaId = parentMangaId;
|
||||
this.Url = url;
|
||||
this.ChapterNumber = chapterNumber;
|
||||
this.VolumeNumber = volumeNumber;
|
||||
this.Title = title;
|
||||
< 0 => -1,
|
||||
> 0 => 1,
|
||||
_ => CompareChapterNumbers(ChapterNumber, otherChapter.ChapterNumber)
|
||||
};
|
||||
}
|
||||
|
||||
public MoveFileOrFolderJob? UpdateChapterNumber(string chapterNumber)
|
||||
{
|
||||
this.ChapterNumber = chapterNumber;
|
||||
ChapterNumber = chapterNumber;
|
||||
return UpdateArchiveFileName();
|
||||
}
|
||||
|
||||
public MoveFileOrFolderJob? UpdateVolumeNumber(int? volumeNumber)
|
||||
{
|
||||
this.VolumeNumber = volumeNumber;
|
||||
VolumeNumber = volumeNumber;
|
||||
return UpdateArchiveFileName();
|
||||
}
|
||||
|
||||
public MoveFileOrFolderJob? UpdateTitle(string? title)
|
||||
{
|
||||
this.Title = title;
|
||||
Title = title;
|
||||
return UpdateArchiveFileName();
|
||||
}
|
||||
|
||||
private string BuildArchiveFileName()
|
||||
{
|
||||
return $"{this.ParentManga.Name} - Vol.{this.VolumeNumber ?? 0} Ch.{this.ChapterNumber}{(this.Title is null ? "" : $" - {this.Title}")}.cbz";
|
||||
return
|
||||
$"{ParentManga.Name} - Vol.{VolumeNumber ?? 0} Ch.{ChapterNumber}{(Title is null ? "" : $" - {Title}")}.cbz";
|
||||
}
|
||||
|
||||
private MoveFileOrFolderJob? UpdateArchiveFileName()
|
||||
{
|
||||
string oldPath = GetArchiveFilePath();
|
||||
this.ArchiveFileName = BuildArchiveFileName();
|
||||
if (Downloaded)
|
||||
{
|
||||
return new MoveFileOrFolderJob(oldPath, GetArchiveFilePath());
|
||||
}
|
||||
ArchiveFileName = BuildArchiveFileName();
|
||||
if (Downloaded) return new MoveFileOrFolderJob(oldPath, GetArchiveFilePath());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -89,8 +100,8 @@ public class Chapter : IComparable<Chapter>
|
||||
|
||||
private static int CompareChapterNumbers(string ch1, string ch2)
|
||||
{
|
||||
var ch1Arr = ch1.Split('.').Select(c => int.Parse(c)).ToArray();
|
||||
var ch2Arr = ch2.Split('.').Select(c => int.Parse(c)).ToArray();
|
||||
int[] ch1Arr = ch1.Split('.').Select(c => int.Parse(c)).ToArray();
|
||||
int[] ch2Arr = ch2.Split('.').Select(c => int.Parse(c)).ToArray();
|
||||
|
||||
int i = 0, j = 0;
|
||||
|
||||
@ -107,27 +118,15 @@ public class Chapter : IComparable<Chapter>
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int CompareTo(Chapter? other)
|
||||
{
|
||||
if(other is not { } otherChapter)
|
||||
throw new ArgumentException($"{other} can not be compared to {this}");
|
||||
return this.VolumeNumber?.CompareTo(otherChapter.VolumeNumber) switch
|
||||
{
|
||||
<0 => -1,
|
||||
>0 => 1,
|
||||
_ => CompareChapterNumbers(this.ChapterNumber, otherChapter.ChapterNumber)
|
||||
};
|
||||
}
|
||||
|
||||
internal string GetComicInfoXmlString()
|
||||
{
|
||||
XElement comicInfo = new XElement("ComicInfo",
|
||||
XElement comicInfo = new("ComicInfo",
|
||||
new XElement("Tags", string.Join(',', ParentManga.Tags.Select(tag => tag.Tag))),
|
||||
new XElement("LanguageISO", ParentManga.OriginalLanguage),
|
||||
new XElement("Title", this.Title),
|
||||
new XElement("Title", Title),
|
||||
new XElement("Writer", string.Join(',', ParentManga.Authors.Select(author => author.AuthorName))),
|
||||
new XElement("Volume", this.VolumeNumber),
|
||||
new XElement("Number", this.ChapterNumber)
|
||||
new XElement("Volume", VolumeNumber),
|
||||
new XElement("Number", ChapterNumber)
|
||||
);
|
||||
return comicInfo.ToString();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using API.Schema;
|
||||
using API.Schema.Jobs;
|
||||
using API.Schema.NotificationConnectors;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
|
||||
@ -20,9 +21,9 @@ public static class Tranga
|
||||
private static void NotificationSender(object? pgsqlContext)
|
||||
{
|
||||
if (pgsqlContext is null) return;
|
||||
var context = (PgsqlContext)pgsqlContext;
|
||||
PgsqlContext context = (PgsqlContext)pgsqlContext;
|
||||
|
||||
var staleNotifications =
|
||||
IQueryable<Notification> staleNotifications =
|
||||
context.Notifications.Where(n => n.Urgency < NotificationUrgency.Normal);
|
||||
context.Notifications.RemoveRange(staleNotifications);
|
||||
context.SaveChanges();
|
||||
@ -39,14 +40,14 @@ public static class Tranga
|
||||
|
||||
private static void SendNotifications(PgsqlContext context, NotificationUrgency urgency)
|
||||
{
|
||||
var notifications = context.Notifications.Where(n => n.Urgency == urgency).ToList();
|
||||
List<Notification> notifications = context.Notifications.Where(n => n.Urgency == urgency).ToList();
|
||||
if (notifications.Any())
|
||||
{
|
||||
var max = notifications.MaxBy(n => n.Date)!.Date;
|
||||
DateTime max = notifications.MaxBy(n => n.Date)!.Date;
|
||||
if (DateTime.Now.Subtract(max) > TrangaSettings.NotificationUrgencyDelay(urgency))
|
||||
{
|
||||
foreach (var notificationConnector in context.NotificationConnectors)
|
||||
foreach (var notification in notifications)
|
||||
foreach (NotificationConnector notificationConnector in context.NotificationConnectors)
|
||||
foreach (Notification notification in notifications)
|
||||
notificationConnector.SendNotification(notification.Title, notification.Message);
|
||||
context.Notifications.RemoveRange(notifications);
|
||||
}
|
||||
@ -58,15 +59,15 @@ public static class Tranga
|
||||
private static void JobStarter(object? pgsqlContext)
|
||||
{
|
||||
if (pgsqlContext is null) return;
|
||||
var context = (PgsqlContext)pgsqlContext;
|
||||
PgsqlContext context = (PgsqlContext)pgsqlContext;
|
||||
|
||||
var TRANGA =
|
||||
string TRANGA =
|
||||
"\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
||||
Log.Info(TRANGA);
|
||||
while (true)
|
||||
{
|
||||
var completedJobs = context.Jobs.Where(j => j.state == JobState.Completed).ToList();
|
||||
foreach (var job in completedJobs)
|
||||
List<Job> completedJobs = context.Jobs.Where(j => j.state == JobState.Completed).ToList();
|
||||
foreach (Job job in completedJobs)
|
||||
if (job.RecurrenceMs <= 0)
|
||||
{
|
||||
context.Jobs.Remove(job);
|
||||
@ -80,7 +81,7 @@ public static class Tranga
|
||||
|
||||
List<Job> runJobs = context.Jobs.Where(j => j.state <= JobState.Running).AsEnumerable()
|
||||
.Where(j => j.NextExecution < DateTime.UtcNow).ToList();
|
||||
foreach (var job in runJobs)
|
||||
foreach (Job job in runJobs)
|
||||
{
|
||||
// If the job is already running, skip it
|
||||
if (RunningJobs.Values.Any(j => j.JobId == job.JobId)) continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user