[postgres-Server-V2] Add parameter array to token gen

This commit is contained in:
Alessandro Benetton 2025-01-31 21:24:35 +01:00
parent a713a006dd
commit d6018b60ae
No known key found for this signature in database
GPG Key ID: ED63A304CE2C0303
11 changed files with 15 additions and 15 deletions

View File

@ -18,7 +18,7 @@ public class Chapter : IComparable<Chapter>
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;

View File

@ -12,7 +12,7 @@ using static System.IO.UnixFileMode;
namespace API.Schema.Jobs;
public class DownloadMangaCoverJob(string chapterId, string? parentJobId = null, ICollection<string>? 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;

View File

@ -4,7 +4,7 @@ using API.Schema.MangaConnectors;
namespace API.Schema.Jobs;
public class DownloadNewChaptersJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection<string>? 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;

View File

@ -12,7 +12,7 @@ using static System.IO.UnixFileMode;
namespace API.Schema.Jobs;
public class DownloadSingleChapterJob(string chapterId, string? parentJobId = null, ICollection<string>? 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;

View File

@ -1,7 +1,7 @@
namespace API.Schema.Jobs;
public class MoveFileOrFolderJob(string fromLocation, string toLocation, string? parentJobId = null, ICollection<string>? 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;

View File

@ -4,7 +4,7 @@ using API.Schema.MangaConnectors;
namespace API.Schema.Jobs;
public class UpdateMetadataJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection<string>? 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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);