Refactor and novel18 support (added cookie support in general to AbstractScraper.cs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-07-20 22:04:13 -04:00
parent 12a1f48fbd
commit ceb8a0db8e
59 changed files with 353 additions and 240 deletions

View File

@@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace Common.Models.DBDomain
{
public class Author : BaseEntity
{
[Key]
public string Url { get; set; }
public string Name { get; set; }
[JsonIgnore]
public List<Novel> Novels { get; set; }
protected bool Equals(Author other)
{
return Url == other.Url;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Author) obj);
}
public override int GetHashCode()
{
return Url.GetHashCode();
}
}
}

View File

@@ -0,0 +1,8 @@
namespace Common.Models.DBDomain
{
public abstract class BaseEntity
{
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using System.ComponentModel.DataAnnotations;
namespace Common.Models.DBDomain
{
public class Chapter : BaseEntity
{
public int ChapterNumber { get; set; }
public string Name { get; set; }
public string? Content { get; set; }
public string? RawContent { get; set; }
[Key]
public string Url { get; set; }
public DateTime? DatePosted { get; set; }
public DateTime? DateUpdated { get; set; }
public DateTime? LastContentFetch { get; set; }
[Required]
public Novel Novel { get; set; }
protected bool Equals(Chapter other)
{
return Url == other.Url;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Chapter) obj);
}
public override int GetHashCode()
{
return Url.GetHashCode();
}
}
}

View File

@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
using Common.Models.Enums;
using Microsoft.EntityFrameworkCore;
namespace Common.Models.DBDomain
{
[Index(nameof(Guid))]
public class Novel : BaseEntity
{
[Key]
public string Url { get; set; }
public Guid Guid { get; set; }
public string Title { get; set; }
public Author? Author { get; set; }
public List<Tag> Tags { get; set; }
public List<Chapter> Chapters { get; set; }
public NovelStatus Status { get; set; }
public DateTime LastUpdated { get; set; }
public DateTime DatePosted { get; set; }
protected bool Equals(Novel other)
{
return Url == other.Url;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Novel) obj);
}
public override int GetHashCode()
{
return Url.GetHashCode();
}
}
}

View File

@@ -0,0 +1,46 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace Common.Models.DBDomain
{
public class Tag : BaseEntity
{
[Key]
public string TagValue { get; set; }
[JsonIgnore]
public List<Novel> Novels { get; set; }
protected bool Equals(Tag other)
{
return TagValue == other.TagValue;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Tag) obj);
}
public override int GetHashCode()
{
return TagValue.GetHashCode();
}
public static Tag GetSiteTag(string siteUrl)
{
return new Tag {TagValue = $"site:{siteUrl.TrimEnd('/')}"};
}
public static Tag GetOriginalWorkTag()
{
return new Tag {TagValue = "original_work"};
}
public static Tag GetNsfwTag()
{
return new Tag {TagValue = "NSFW"};
}
}
}

View File

@@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace Common.Models.DBDomain
{
[Index(nameof(Email))]
public class User : BaseEntity
{
[Key]
public int Id { get; set; }
public string Email { get; set; }
public List<UserNovel> WatchedNovels { get; set; }
protected bool Equals(User other)
{
return Id == other.Id;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((User) obj);
}
public override int GetHashCode()
{
return Id;
}
}
}

View File

@@ -0,0 +1,32 @@
using Newtonsoft.Json;
namespace Common.Models.DBDomain
{
public class UserNovel
{
public int UserId { get; set; }
public string NovelUrl { get; set; }
public Novel Novel { get; set; }
[JsonIgnore]
public User User { get; set; }
public int LastChapterRead { get; set; }
protected bool Equals(UserNovel other)
{
return UserId == other.UserId && NovelUrl == other.NovelUrl;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((UserNovel) obj);
}
public override int GetHashCode()
{
return HashCode.Combine(UserId, NovelUrl);
}
}
}

View File

@@ -0,0 +1,6 @@
namespace Common.Models.DTO.Requests;
public class ScrapeNovelRequest
{
public string NovelUrl { get; set; }
}

View File

@@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace Common.Models.DTO.Requests;
public class ScrapeNovelsRequest
{
[JsonProperty("novelUrls")]
public List<string> NovelUrls { get; set; }
}

View File

@@ -0,0 +1,9 @@
using Common.Models.DBDomain;
namespace Common.Models.DTO.Responses;
public class ScrapeNovelsResponse
{
public List<Novel> SuccessfulNovels { get; set; }
public Dictionary<string, Exception> Failures { get; set; }
}

View File

@@ -0,0 +1,9 @@
namespace Common.Models.Enums;
public enum NovelStatus
{
Unknown,
InProgress,
Completed,
Hiatus
}

View File

@@ -0,0 +1,11 @@
namespace Common.Models;
public class HttpResponseWrapper<T> : HttpResponseWrapper
{
public T? ResponseObject { get; set; }
}
public class HttpResponseWrapper
{
public HttpResponseMessage HttpResponseMessage { get; set; }
}