mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-22 23:30:13 +01:00
[postgres-Server-V2] Add parameter array to token gen
This commit is contained in:
parent
a713a006dd
commit
d6018b60ae
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user