From d6018b60ae43f1cd64dabfdc6d63e4968bb185c7 Mon Sep 17 00:00:00 2001 From: Alessandro Benetton Date: Fri, 31 Jan 2025 21:24:35 +0100 Subject: [PATCH] [postgres-Server-V2] Add parameter array to token gen --- API/Schema/Chapter.cs | 2 +- API/Schema/Jobs/DownloadMangaCoverJob.cs | 2 +- API/Schema/Jobs/DownloadNewChaptersJob.cs | 2 +- API/Schema/Jobs/DownloadSingleChapterJob.cs | 2 +- API/Schema/Jobs/MoveFileOrFolderJob.cs | 2 +- API/Schema/Jobs/UpdateMetadataJob.cs | 2 +- API/Schema/Link.cs | 2 +- API/Schema/Manga.cs | 4 ++-- API/Schema/MangaAltTitle.cs | 2 +- API/Schema/Notification.cs | 2 +- API/TokenGen.cs | 8 ++++---- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/API/Schema/Chapter.cs b/API/Schema/Chapter.cs index 5c9ce27..46771c0 100644 --- a/API/Schema/Chapter.cs +++ b/API/Schema/Chapter.cs @@ -18,7 +18,7 @@ public class Chapter : IComparable public Chapter(string parentMangaId, string url, string chapterNumber, int? volumeNumber = null, string? title = null) { - ChapterId = TokenGen.CreateToken(typeof(Chapter), string.Join(parentMangaId, volumeNumber ?? 0, chapterNumber)); + ChapterId = TokenGen.CreateToken(typeof(Chapter), parentMangaId, (volumeNumber ?? 0).ToString(), chapterNumber); ParentMangaId = parentMangaId; Url = url; ChapterNumber = chapterNumber; diff --git a/API/Schema/Jobs/DownloadMangaCoverJob.cs b/API/Schema/Jobs/DownloadMangaCoverJob.cs index e6ef6d0..56e630a 100644 --- a/API/Schema/Jobs/DownloadMangaCoverJob.cs +++ b/API/Schema/Jobs/DownloadMangaCoverJob.cs @@ -12,7 +12,7 @@ using static System.IO.UnixFileMode; namespace API.Schema.Jobs; public class DownloadMangaCoverJob(string chapterId, string? parentJobId = null, ICollection? dependsOnJobsIds = null) - : Job(TokenGen.CreateToken(typeof(DownloadMangaCoverJob), ""), JobType.DownloadMangaCoverJob, 0, parentJobId, dependsOnJobsIds) + : Job(TokenGen.CreateToken(typeof(DownloadMangaCoverJob)), JobType.DownloadMangaCoverJob, 0, parentJobId, dependsOnJobsIds) { [MaxLength(64)] public string ChapterId { get; init; } = chapterId; diff --git a/API/Schema/Jobs/DownloadNewChaptersJob.cs b/API/Schema/Jobs/DownloadNewChaptersJob.cs index b090d0b..6cc82b8 100644 --- a/API/Schema/Jobs/DownloadNewChaptersJob.cs +++ b/API/Schema/Jobs/DownloadNewChaptersJob.cs @@ -4,7 +4,7 @@ using API.Schema.MangaConnectors; namespace API.Schema.Jobs; public class DownloadNewChaptersJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection? dependsOnJobsIds = null) - : Job(TokenGen.CreateToken(typeof(DownloadNewChaptersJob), ""), JobType.DownloadNewChaptersJob, recurrenceMs, parentJobId, dependsOnJobsIds) + : Job(TokenGen.CreateToken(typeof(DownloadNewChaptersJob)), JobType.DownloadNewChaptersJob, recurrenceMs, parentJobId, dependsOnJobsIds) { [MaxLength(64)] public string MangaId { get; init; } = mangaId; diff --git a/API/Schema/Jobs/DownloadSingleChapterJob.cs b/API/Schema/Jobs/DownloadSingleChapterJob.cs index 257666f..e6cee60 100644 --- a/API/Schema/Jobs/DownloadSingleChapterJob.cs +++ b/API/Schema/Jobs/DownloadSingleChapterJob.cs @@ -12,7 +12,7 @@ using static System.IO.UnixFileMode; namespace API.Schema.Jobs; public class DownloadSingleChapterJob(string chapterId, string? parentJobId = null, ICollection? dependsOnJobsIds = null) - : Job(TokenGen.CreateToken(typeof(DownloadSingleChapterJob), ""), JobType.DownloadSingleChapterJob, 0, parentJobId, dependsOnJobsIds) + : Job(TokenGen.CreateToken(typeof(DownloadSingleChapterJob)), JobType.DownloadSingleChapterJob, 0, parentJobId, dependsOnJobsIds) { [MaxLength(64)] public string ChapterId { get; init; } = chapterId; diff --git a/API/Schema/Jobs/MoveFileOrFolderJob.cs b/API/Schema/Jobs/MoveFileOrFolderJob.cs index 123ff92..956dd7c 100644 --- a/API/Schema/Jobs/MoveFileOrFolderJob.cs +++ b/API/Schema/Jobs/MoveFileOrFolderJob.cs @@ -1,7 +1,7 @@ namespace API.Schema.Jobs; public class MoveFileOrFolderJob(string fromLocation, string toLocation, string? parentJobId = null, ICollection? dependsOnJobsIds = null) - : Job(TokenGen.CreateToken(typeof(MoveFileOrFolderJob), ""), JobType.MoveFileOrFolderJob, 0, parentJobId, dependsOnJobsIds) + : Job(TokenGen.CreateToken(typeof(MoveFileOrFolderJob)), JobType.MoveFileOrFolderJob, 0, parentJobId, dependsOnJobsIds) { public string FromLocation { get; init; } = fromLocation; public string ToLocation { get; init; } = toLocation; diff --git a/API/Schema/Jobs/UpdateMetadataJob.cs b/API/Schema/Jobs/UpdateMetadataJob.cs index a04074b..c5706e8 100644 --- a/API/Schema/Jobs/UpdateMetadataJob.cs +++ b/API/Schema/Jobs/UpdateMetadataJob.cs @@ -4,7 +4,7 @@ using API.Schema.MangaConnectors; namespace API.Schema.Jobs; public class UpdateMetadataJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection? dependsOnJobsIds = null) - : Job(TokenGen.CreateToken(typeof(UpdateMetadataJob), ""), JobType.UpdateMetaDataJob, recurrenceMs, parentJobId, dependsOnJobsIds) + : Job(TokenGen.CreateToken(typeof(UpdateMetadataJob)), JobType.UpdateMetaDataJob, recurrenceMs, parentJobId, dependsOnJobsIds) { [MaxLength(64)] public string MangaId { get; init; } = mangaId; diff --git a/API/Schema/Link.cs b/API/Schema/Link.cs index fd415ad..af08155 100644 --- a/API/Schema/Link.cs +++ b/API/Schema/Link.cs @@ -7,7 +7,7 @@ namespace API.Schema; public class Link(string linkProvider, string linkUrl) { [MaxLength(64)] - public string LinkId { get; init; } = TokenGen.CreateToken(typeof(Link), string.Join(linkProvider, linkUrl)); + public string LinkId { get; init; } = TokenGen.CreateToken(typeof(Link), linkProvider, linkUrl); public string LinkProvider { get; init; } = linkProvider; public string LinkUrl { get; init; } = linkUrl; diff --git a/API/Schema/Manga.cs b/API/Schema/Manga.cs index 543b885..6b58fa9 100644 --- a/API/Schema/Manga.cs +++ b/API/Schema/Manga.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Runtime.InteropServices; using System.Text.RegularExpressions; @@ -57,7 +57,7 @@ public class Manga string? coverFileNameInCache, uint year, string? originalLanguage, MangaReleaseStatus releaseStatus, float ignoreChapterBefore, string mangaConnectorId) { - MangaId = TokenGen.CreateToken(typeof(Manga), string.Join(MangaConnectorId, ConnectorId)); + MangaId = TokenGen.CreateToken(typeof(Manga), MangaConnectorId, ConnectorId); ConnectorId = connectorId; Name = name; Description = description; diff --git a/API/Schema/MangaAltTitle.cs b/API/Schema/MangaAltTitle.cs index 4c75834..54a8144 100644 --- a/API/Schema/MangaAltTitle.cs +++ b/API/Schema/MangaAltTitle.cs @@ -8,7 +8,7 @@ namespace API.Schema; public class MangaAltTitle(string language, string title) { [MaxLength(64)] - public string AltTitleId { get; init; } = TokenGen.CreateToken("AltTitle", string.Join(language, title)); + public string AltTitleId { get; init; } = TokenGen.CreateToken("AltTitle", language, title); [MaxLength(8)] public string Language { get; init; } = language; public string Title { get; set; } = title; diff --git a/API/Schema/Notification.cs b/API/Schema/Notification.cs index f913951..959b2e8 100644 --- a/API/Schema/Notification.cs +++ b/API/Schema/Notification.cs @@ -7,7 +7,7 @@ namespace API.Schema; public class Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null) { [MaxLength(64)] - public string NotificationId { get; init; } = TokenGen.CreateToken("Notification", ""); + public string NotificationId { get; init; } = TokenGen.CreateToken("Notification"); public NotificationUrgency Urgency { get; init; } = urgency; diff --git a/API/TokenGen.cs b/API/TokenGen.cs index 947c482..3f3d2ae 100644 --- a/API/TokenGen.cs +++ b/API/TokenGen.cs @@ -9,9 +9,9 @@ public static class TokenGen private const int MaximumLength = 64; private const string Chars = "abcdefghijklmnopqrstuvwxyz0123456789"; - public static string CreateToken(Type t, string identifier) => CreateToken(t.Name, identifier); + public static string CreateToken(Type t, params string[] identifiers) => CreateToken(t.Name, identifiers); - public static string CreateToken(string prefix, string identifier) + public static string CreateToken(string prefix, params string[] identifiers) { @@ -20,7 +20,7 @@ public static class TokenGen int tokenLength = MaximumLength - prefix.Length - 1; - if (string.IsNullOrWhiteSpace(identifier)) + if (identifiers.Length == 0) { // No identifier, just create a random token byte[] rng = new byte[tokenLength]; @@ -31,7 +31,7 @@ public static class TokenGen } // Identifier provided, create a token based on the identifier hashed - byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(identifier)); + byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(string.Join("", identifiers))); string token = Convert.ToHexStringLower(hash); return string.Join('-', prefix, token);