Tranga-Website/Tranga/Publication.cs

71 lines
2.3 KiB
C#
Raw Normal View History

using Newtonsoft.Json;
2023-05-18 20:26:47 +02:00
namespace Tranga;
2023-05-19 19:53:59 +02:00
/// <summary>
/// Contains information on a Publication (Manga)
/// </summary>
public struct Publication
{
public string sortName { get; }
[JsonIgnore]public string[,] altTitles { get; }
2023-05-18 15:47:05 +02:00
public string? description { get; }
public string[] tags { get; }
2023-05-18 18:55:11 +02:00
public string? posterUrl { get; }
[JsonIgnore]public string[,]? links { get; }
2023-05-18 15:47:05 +02:00
public int? year { get; }
public string? originalLanguage { get; }
public string status { get; }
2023-05-18 19:54:40 +02:00
public string folderName { get; }
2023-05-18 15:47:05 +02:00
public string downloadUrl { get; }
public Publication(string sortName, string? description, string[,] altTitles, string[] tags, string? posterUrl, string[,]? links, int? year, string? originalLanguage, string status, string downloadUrl)
{
this.sortName = sortName;
this.description = description;
2023-05-18 15:47:05 +02:00
this.altTitles = altTitles;
this.tags = tags;
this.posterUrl = posterUrl;
2023-05-18 15:47:05 +02:00
this.links = links;
this.year = year;
this.originalLanguage = originalLanguage;
this.status = status;
this.downloadUrl = downloadUrl;
2023-05-18 19:54:40 +02:00
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars()));
}
2023-05-18 20:26:47 +02:00
2023-05-19 19:53:59 +02:00
/// <summary>
///
/// </summary>
/// <returns>Serialized JSON String for series.json</returns>
2023-05-18 20:26:47 +02:00
public string GetSeriesInfo()
{
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
return System.Text.Json.JsonSerializer.Serialize(si);
2023-05-18 20:26:47 +02:00
}
2023-05-19 19:53:59 +02:00
//Only for series.json
private struct SeriesInfo
2023-05-18 20:26:47 +02:00
{
2023-05-18 21:08:09 +02:00
[JsonRequired]public Metadata metadata { get; }
2023-05-18 20:26:47 +02:00
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
}
2023-05-19 19:53:59 +02:00
//Only for series.json
private struct Metadata
2023-05-18 20:26:47 +02:00
{
2023-05-18 21:08:09 +02:00
[JsonRequired]public string name { get; }
[JsonRequired]public string year { get; }
[JsonRequired]public string status { get; }
2023-05-18 20:26:47 +02:00
// ReSharper disable twice InconsistentNaming
2023-05-18 21:08:09 +02:00
[JsonRequired]public string description_text { get; }
2023-05-18 20:26:47 +02:00
public Metadata(string name, string year, string status, string description_text)
{
this.name = name;
this.year = year;
this.status = status;
this.description_text = description_text;
}
}
}