Compare commits

..

13 Commits

Author SHA1 Message Date
13b7306ca2 Syosetu single chapter novel support, closes #1
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-03 14:33:08 -04:00
0903278f14 Cleaning up tags and url regexes, closes #6
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-03 12:44:04 -04:00
d4c4f521ec Fix for syosetu author names, closes #8
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-03 11:14:28 -04:00
050ea7aa80 Added start of completion status scraping and fixed kakuyomu date posted lookup
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-21 11:39:15 -04:00
ceb8a0db8e Refactor and novel18 support (added cookie support in general to AbstractScraper.cs
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-20 22:04:13 -04:00
12a1f48fbd Fix up times and remove extraneous api inject from NovelList.razor
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-17 22:26:22 -04:00
cbf5ec076d Forgot to remove webapi test
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-17 22:08:47 -04:00
a5737a510d Add logging when api request comes in bad 2022-07-17 22:08:14 -04:00
2e9a3108f4 Try and fix a postgres datetime issue
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-17 21:40:57 -04:00
9c58bc2948 More https cleanup since we're behind a traefik proxy
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-17 21:08:33 -04:00
edfc18d7f4 Possible fix for incorrect auth redirect location
All checks were successful
continuous-integration/drone/push Build is passing
2022-07-17 20:55:28 -04:00
3fbaec1fb6 Forgot to fix single scrapes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-07-17 20:35:34 -04:00
b5c4146d4d Finished adding user support and ability to update specific novels or set your last read chapter 2022-07-17 20:34:06 -04:00
73 changed files with 1036 additions and 355 deletions

View File

@@ -1,17 +1,22 @@
using System.Net.Mime; using System.Net.Mime;
using System.Text; using System.Text;
using Common.Models;
using Microsoft.AspNetCore.WebUtilities; using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Treestar.Shared.Models;
namespace Treestar.Shared.AccessLayers; namespace Common.AccessLayers;
public abstract class ApiAccessLayer public abstract class ApiAccessLayer
{ {
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;
private readonly IAccessLayerAuthenticationProvider _authenticationProvider;
protected readonly ILogger Logger;
protected ApiAccessLayer(string apiBaseUrl) protected ApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider, ILogger logger)
{ {
_authenticationProvider = authenticationProvider;
Logger = logger;
var handler = new HttpClientHandler() var handler = new HttpClientHandler()
{ {
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
@@ -22,7 +27,12 @@ public abstract class ApiAccessLayer
private async Task<HttpResponseWrapper> SendRequest(HttpRequestMessage message) private async Task<HttpResponseWrapper> SendRequest(HttpRequestMessage message)
{ {
await _authenticationProvider.AddAuthentication(message);
var response = await _httpClient.SendAsync(message); var response = await _httpClient.SendAsync(message);
if (!response.IsSuccessStatusCode)
{
Logger.LogError("Response returned status code {statusCode} with reason {reason} and content {content}", response.StatusCode, response.ReasonPhrase, await response.Content.ReadAsStringAsync());
}
return new HttpResponseWrapper() return new HttpResponseWrapper()
{ {
HttpResponseMessage = response HttpResponseMessage = response

View File

@@ -0,0 +1,6 @@
namespace Common.AccessLayers;
public interface IAccessLayerAuthenticationProvider
{
Task AddAuthentication(HttpRequestMessage request);
}

View File

@@ -0,0 +1,32 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
namespace Common.Authentication.JwtBearer;
public static class JWTAuthenticationExtension
{
public static void AddJwtBearerAuth(this IServiceCollection services, IConfiguration configuration)
{
var jwtAuthOptions = configuration.GetRequiredSection(JwtBearerAuthenticationOptions.ConfigrationSection)
.Get<JwtBearerAuthenticationOptions>();
services.AddAuthentication(opt =>
{
opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(opt =>
{
opt.Authority = jwtAuthOptions.Authority;
opt.Audience = jwtAuthOptions.Audience;
opt.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.Name,
ValidateAudience = !string.IsNullOrEmpty(jwtAuthOptions.Audience),
ValidateIssuer = true,
ValidateIssuerSigningKey = true,
ValidateLifetime = true
};
});
}
}

View File

@@ -0,0 +1,8 @@
namespace Common.Authentication.JwtBearer;
public class JwtBearerAuthenticationOptions
{
public const string ConfigrationSection = "JwtBearerAuthOptions";
public string Authority { get; set; } = null!;
public string? Audience { get; set; }
}

View File

@@ -0,0 +1,45 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using WebNovelPortal.Authentication;
namespace Common.Authentication.OIDC;
public static class AuthenticationExtension
{
public static void AddOIDCAuth(this IServiceCollection services, IConfiguration configuration)
{
var oidcConfig = configuration.GetRequiredSection(OpenIdConnectAuthenticationOptions.ConfigurationSection)
.Get<OpenIdConnectAuthenticationOptions>();
services.AddAuthentication(opt =>
{
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(opt =>
{
opt.Authority = oidcConfig.Authority;
opt.ClientId = oidcConfig.ClientId;
opt.ClientSecret = oidcConfig.ClientSecret;
opt.ResponseType = OpenIdConnectResponseType.Code;
opt.GetClaimsFromUserInfoEndpoint = false;
opt.SaveTokens = true;
opt.UseTokenLifetime = true;
foreach (var scope in oidcConfig.Scopes.Split(" "))
{
opt.Scope.Add(scope);
}
opt.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.Name
};
});
}
}

View File

@@ -0,0 +1,10 @@
namespace WebNovelPortal.Authentication;
public class OpenIdConnectAuthenticationOptions
{
public const string ConfigurationSection = "OIDCAuthOptions";
public string Authority { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string Scopes { get; set; }
}

32
Common/Common.csproj Normal file
View File

@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="BlazorComponents" />
<Folder Include="Interfaces" />
<Folder Include="Utility" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions">
<HintPath>..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\6.0.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
<HintPath>..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\6.0.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Treestar.Shared.Models.DBDomain namespace Common.Models.DBDomain
{ {
public class Author : BaseEntity public class Author : BaseEntity
{ {

View File

@@ -1,4 +1,4 @@
namespace Treestar.Shared.Models.DBDomain namespace Common.Models.DBDomain
{ {
public abstract class BaseEntity public abstract class BaseEntity
{ {

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Treestar.Shared.Models.DBDomain namespace Common.Models.DBDomain
{ {
public class Chapter : BaseEntity public class Chapter : BaseEntity
{ {

View File

@@ -1,8 +1,8 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Common.Models.Enums;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Treestar.Shared.Models.Enums;
namespace Treestar.Shared.Models.DBDomain namespace Common.Models.DBDomain
{ {
[Index(nameof(Guid))] [Index(nameof(Guid))]
public class Novel : BaseEntity public class Novel : BaseEntity
@@ -17,5 +17,23 @@ namespace Treestar.Shared.Models.DBDomain
public NovelStatus Status { get; set; } public NovelStatus Status { get; set; }
public DateTime LastUpdated { get; set; } public DateTime LastUpdated { get; set; }
public DateTime DatePosted { 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

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Treestar.Shared.Models.DBDomain namespace Common.Models.DBDomain
{ {
public class Tag : BaseEntity public class Tag : BaseEntity
{ {
@@ -27,5 +27,20 @@ namespace Treestar.Shared.Models.DBDomain
{ {
return TagValue.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 = "meta: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

@@ -1,4 +1,4 @@
namespace Treestar.Shared.Models.DTO.Requests; namespace Common.Models.DTO.Requests;
public class ScrapeNovelRequest public class ScrapeNovelRequest
{ {

View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Treestar.Shared.Models.DTO.Requests; namespace Common.Models.DTO.Requests;
public class ScrapeNovelsRequest public class ScrapeNovelsRequest
{ {

View File

@@ -1,6 +1,6 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace Treestar.Shared.Models.DTO.Responses; namespace Common.Models.DTO.Responses;
public class ScrapeNovelsResponse public class ScrapeNovelsResponse
{ {

View File

@@ -1,4 +1,4 @@
namespace Treestar.Shared.Models.Enums; namespace Common.Models.Enums;
public enum NovelStatus public enum NovelStatus
{ {

View File

@@ -1,4 +1,4 @@
namespace Treestar.Shared.Models; namespace Common.Models;
public class HttpResponseWrapper<T> : HttpResponseWrapper public class HttpResponseWrapper<T> : HttpResponseWrapper
{ {

View File

@@ -3,7 +3,7 @@ using DBConnection.ModelBuilders;
using DBConnection.Seeders; using DBConnection.Seeders;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Contexts; namespace DBConnection.Contexts;
@@ -46,9 +46,9 @@ public abstract class AppDbContext : DbContext
foreach(var entry in entries) { foreach(var entry in entries) {
if (entry.State == EntityState.Added) if (entry.State == EntityState.Added)
{ {
((BaseEntity)entry.Entity).DateCreated = DateTime.Now; ((BaseEntity)entry.Entity).DateCreated = DateTime.UtcNow;
} }
((BaseEntity)entry.Entity).DateModified = DateTime.Now; ((BaseEntity)entry.Entity).DateModified = DateTime.UtcNow;
} }
} }

View File

@@ -24,7 +24,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Treestar.Shared\Treestar.Shared.csproj" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -39,7 +39,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -59,7 +59,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -103,7 +103,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -140,7 +140,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("text"); .HasColumnType("text");
@@ -156,7 +156,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -179,7 +179,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("text"); .HasColumnType("text");
@@ -199,46 +199,46 @@ namespace DBConnection.Migrations.PostgresSql
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -249,17 +249,17 @@ namespace DBConnection.Migrations.PostgresSql
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -39,7 +39,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -59,7 +59,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -103,7 +103,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -142,7 +142,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("text"); .HasColumnType("text");
@@ -158,7 +158,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -181,7 +181,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("text"); .HasColumnType("text");
@@ -201,46 +201,46 @@ namespace DBConnection.Migrations.PostgresSql
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -251,17 +251,17 @@ namespace DBConnection.Migrations.PostgresSql
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -39,7 +39,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -59,7 +59,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -103,7 +103,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -142,7 +142,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("text"); .HasColumnType("text");
@@ -158,7 +158,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -183,7 +183,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("text"); .HasColumnType("text");
@@ -203,22 +203,22 @@ namespace DBConnection.Migrations.PostgresSql
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -227,24 +227,24 @@ namespace DBConnection.Migrations.PostgresSql
b.Navigation("Novel"); b.Navigation("Novel");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -255,17 +255,17 @@ namespace DBConnection.Migrations.PostgresSql
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -37,7 +37,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -57,7 +57,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -101,7 +101,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("text"); .HasColumnType("text");
@@ -140,7 +140,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("text"); .HasColumnType("text");
@@ -156,7 +156,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -181,7 +181,7 @@ namespace DBConnection.Migrations.PostgresSql
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("text"); .HasColumnType("text");
@@ -201,22 +201,22 @@ namespace DBConnection.Migrations.PostgresSql
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -225,24 +225,24 @@ namespace DBConnection.Migrations.PostgresSql
b.Navigation("Novel"); b.Navigation("Novel");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -253,17 +253,17 @@ namespace DBConnection.Migrations.PostgresSql
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -34,7 +34,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -54,7 +54,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -98,7 +98,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -135,7 +135,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -151,7 +151,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -172,7 +172,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -192,46 +192,46 @@ namespace DBConnection.Migrations.Sqlite
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -242,17 +242,17 @@ namespace DBConnection.Migrations.Sqlite
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -34,7 +34,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -54,7 +54,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -98,7 +98,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -137,7 +137,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -153,7 +153,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -174,7 +174,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -194,46 +194,46 @@ namespace DBConnection.Migrations.Sqlite
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -244,17 +244,17 @@ namespace DBConnection.Migrations.Sqlite
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -34,7 +34,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -54,7 +54,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -98,7 +98,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -137,7 +137,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -153,7 +153,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -176,7 +176,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -196,22 +196,22 @@ namespace DBConnection.Migrations.Sqlite
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -220,24 +220,24 @@ namespace DBConnection.Migrations.Sqlite
b.Navigation("Novel"); b.Navigation("Novel");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -248,17 +248,17 @@ namespace DBConnection.Migrations.Sqlite
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -32,7 +32,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("NovelTag"); b.ToTable("NovelTag");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -52,7 +52,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Authors"); b.ToTable("Authors");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -96,7 +96,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Chapters"); b.ToTable("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Property<string>("Url") b.Property<string>("Url")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -135,7 +135,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Novels"); b.ToTable("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Tag", b => modelBuilder.Entity("Common.Models.DBDomain.Tag", b =>
{ {
b.Property<string>("TagValue") b.Property<string>("TagValue")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -151,7 +151,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Tags"); b.ToTable("Tags");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@@ -174,7 +174,7 @@ namespace DBConnection.Migrations.Sqlite
b.ToTable("Users"); b.ToTable("Users");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.Property<string>("NovelUrl") b.Property<string>("NovelUrl")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@@ -194,22 +194,22 @@ namespace DBConnection.Migrations.Sqlite
modelBuilder.Entity("NovelTag", b => modelBuilder.Entity("NovelTag", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", null) b.HasOne("Common.Models.DBDomain.Novel", null)
.WithMany() .WithMany()
.HasForeignKey("NovelsUrl") .HasForeignKey("NovelsUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.Tag", null) b.HasOne("Common.Models.DBDomain.Tag", null)
.WithMany() .WithMany()
.HasForeignKey("TagsTagValue") .HasForeignKey("TagsTagValue")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Chapter", b => modelBuilder.Entity("Common.Models.DBDomain.Chapter", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany("Chapters") .WithMany("Chapters")
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -218,24 +218,24 @@ namespace DBConnection.Migrations.Sqlite
b.Navigation("Novel"); b.Navigation("Novel");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Author", "Author") b.HasOne("Common.Models.DBDomain.Author", "Author")
.WithMany("Novels") .WithMany("Novels")
.HasForeignKey("AuthorUrl"); .HasForeignKey("AuthorUrl");
b.Navigation("Author"); b.Navigation("Author");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.UserNovel", b => modelBuilder.Entity("Common.Models.DBDomain.UserNovel", b =>
{ {
b.HasOne("Treestar.Shared.Models.DBDomain.Novel", "Novel") b.HasOne("Common.Models.DBDomain.Novel", "Novel")
.WithMany() .WithMany()
.HasForeignKey("NovelUrl") .HasForeignKey("NovelUrl")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Treestar.Shared.Models.DBDomain.User", "User") b.HasOne("Common.Models.DBDomain.User", "User")
.WithMany("WatchedNovels") .WithMany("WatchedNovels")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
@@ -246,17 +246,17 @@ namespace DBConnection.Migrations.Sqlite
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Author", b => modelBuilder.Entity("Common.Models.DBDomain.Author", b =>
{ {
b.Navigation("Novels"); b.Navigation("Novels");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.Novel", b => modelBuilder.Entity("Common.Models.DBDomain.Novel", b =>
{ {
b.Navigation("Chapters"); b.Navigation("Chapters");
}); });
modelBuilder.Entity("Treestar.Shared.Models.DBDomain.User", b => modelBuilder.Entity("Common.Models.DBDomain.User", b =>
{ {
b.Navigation("WatchedNovels"); b.Navigation("WatchedNovels");
}); });

View File

@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.ModelBuilders; namespace DBConnection.ModelBuilders;

View File

@@ -1,7 +1,7 @@
using DBConnection.Contexts; using DBConnection.Contexts;
using DBConnection.Repositories.Interfaces; using DBConnection.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories; namespace DBConnection.Repositories;

View File

@@ -3,7 +3,7 @@ using DBConnection.Contexts;
using DBConnection.Repositories.Interfaces; using DBConnection.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NuGet.Configuration; using NuGet.Configuration;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories; namespace DBConnection.Repositories;
@@ -84,8 +84,18 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
return GetAllIncludedQueryable().FirstOrDefault(predicate); return GetAllIncludedQueryable().FirstOrDefault(predicate);
} }
public virtual async Task<IEnumerable<TEntityType?>> GetWhereIncluded(IEnumerable<TEntityType> entities)
{
return await GetWhereIncluded(entities.Contains);
}
public virtual async Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate) public virtual async Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate)
{ {
return GetAllIncludedQueryable().AsEnumerable().Where(predicate); return GetAllIncludedQueryable().AsEnumerable().Where(predicate);
} }
public virtual async Task PersistChanges()
{
await DbContext.SaveChangesAsync();
}
} }

View File

@@ -1,7 +1,7 @@
using DBConnection.Contexts; using DBConnection.Contexts;
using DBConnection.Repositories.Interfaces; using DBConnection.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories; namespace DBConnection.Repositories;

View File

@@ -1,4 +1,4 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories.Interfaces; namespace DBConnection.Repositories.Interfaces;

View File

@@ -1,4 +1,4 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories.Interfaces; namespace DBConnection.Repositories.Interfaces;

View File

@@ -1,4 +1,4 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories.Interfaces; namespace DBConnection.Repositories.Interfaces;

View File

@@ -1,4 +1,4 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories.Interfaces; namespace DBConnection.Repositories.Interfaces;
@@ -16,4 +16,6 @@ public interface IRepository<TEntityType> : IRepository where TEntityType : Base
Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate); Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate);
Task<IEnumerable<TEntityType>> GetAllIncluded(); Task<IEnumerable<TEntityType>> GetAllIncluded();
Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true); Task<IEnumerable<TEntityType>> UpsertMany(IEnumerable<TEntityType> entities, bool saveAfter=true);
Task PersistChanges();
Task<IEnumerable<TEntityType?>> GetWhereIncluded(IEnumerable<TEntityType> entities);
} }

View File

@@ -1,4 +1,4 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories.Interfaces; namespace DBConnection.Repositories.Interfaces;

View File

@@ -0,0 +1,9 @@
using Common.Models.DBDomain;
namespace DBConnection.Repositories.Interfaces;
public interface IUserRepository : IRepository<User>
{
Task<User> AssignNovelsToUser(User user, List<Novel> novels);
Task<User> UpdateLastChapterRead(User user, Novel novel, int chapterRead);
}

View File

@@ -1,7 +1,7 @@
using DBConnection.Contexts; using DBConnection.Contexts;
using DBConnection.Repositories.Interfaces; using DBConnection.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories; namespace DBConnection.Repositories;
@@ -25,11 +25,10 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
{ {
entity.Author = await _authorRepository.Upsert(entity.Author, false); entity.Author = await _authorRepository.Upsert(entity.Author, false);
} }
//Tags //Tags
var newTags = await _tagRepository.UpsertMany(entity.Tags, false); var newTags = await _tagRepository.UpsertMany(entity.Tags, false);
//chapters are getting deleted now that their required... //chapters
var newChapters = await _chapterRepository.UpsertMany(entity.Chapters, false); var newChapters = await _chapterRepository.UpsertMany(entity.Chapters, false);
// update in db // update in db

View File

@@ -1,7 +1,7 @@
using DBConnection.Contexts; using DBConnection.Contexts;
using DBConnection.Repositories.Interfaces; using DBConnection.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace DBConnection.Repositories; namespace DBConnection.Repositories;

View File

@@ -0,0 +1,49 @@
using DBConnection.Contexts;
using DBConnection.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
using Common.Models.DBDomain;
namespace DBConnection.Repositories;
public class UserRepository : BaseRepository<User>, IUserRepository
{
private readonly INovelRepository _novelRepository;
public UserRepository(AppDbContext dbContext, INovelRepository novelRepository) : base(dbContext)
{
_novelRepository = novelRepository;
}
protected override IQueryable<User> GetAllIncludedQueryable()
{
return DbContext.Users.Include(u => u.WatchedNovels);
}
public async Task<User> AssignNovelsToUser(User user, List<Novel> novels)
{
var dbUser = await GetIncluded(user);
if (dbUser == null)
{
return user;
}
var dbNovels = await _novelRepository.GetWhereIncluded(novels);
var newNovels = dbNovels.Except(dbUser.WatchedNovels.Select(un => un.Novel));
var newUserNovels = newNovels.Select(n => new UserNovel
{
Novel = n,
User = dbUser
});
dbUser.WatchedNovels.AddRange(newUserNovels);
await DbContext.SaveChangesAsync();
return dbUser;
}
public async Task<User> UpdateLastChapterRead(User user, Novel novel, int chapterRead)
{
var dbUser = await GetIncluded(user);
var userNovel = dbUser.WatchedNovels.FirstOrDefault(i => i.NovelUrl == novel.Url);
userNovel.LastChapterRead = chapterRead;
await DbContext.SaveChangesAsync();
return dbUser;
}
}

View File

@@ -1,14 +0,0 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
namespace Treestar.Shared.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; }
}
}

View File

@@ -1,14 +0,0 @@
using Newtonsoft.Json;
namespace Treestar.Shared.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; }
}
}

View File

@@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Interfaces" />
<Folder Include="Utility" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="6.0.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

View File

@@ -4,7 +4,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebNovelPortal", "WebNovelP
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebNovelPortalAPI", "WebNovelPortalAPI\WebNovelPortalAPI.csproj", "{D24E3BBA-EAA1-4515-9060-56E673CC7FAA}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebNovelPortalAPI", "WebNovelPortalAPI\WebNovelPortalAPI.csproj", "{D24E3BBA-EAA1-4515-9060-56E673CC7FAA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Treestar.Shared", "Treestar.Shared\Treestar.Shared.csproj", "{639F52AF-9D62-4341-BEE6-0E9243020FC5}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{639F52AF-9D62-4341-BEE6-0E9243020FC5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBConnection", "DBConnection\DBConnection.csproj", "{CD895518-DA05-4886-BE14-3E04D62FA2F7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBConnection", "DBConnection\DBConnection.csproj", "{CD895518-DA05-4886-BE14-3E04D62FA2F7}"
EndProject EndProject

View File

@@ -1,20 +1,20 @@
using Treestar.Shared.AccessLayers; using Common.AccessLayers;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
using Treestar.Shared.Models.DTO; using Common.Models.DTO;
using Treestar.Shared.Models.DTO.Requests; using Common.Models.DTO.Requests;
using Treestar.Shared.Models.DTO.Responses; using Common.Models.DTO.Responses;
namespace WebNovelPortal.AccessLayers; namespace WebNovelPortal.AccessLayers;
public class WebApiAccessLayer : ApiAccessLayer public class WebApiAccessLayer : ApiAccessLayer
{ {
public WebApiAccessLayer(string apiBaseUrl) : base(apiBaseUrl) public WebApiAccessLayer(string apiBaseUrl, IAccessLayerAuthenticationProvider authenticationProvider, ILogger<WebApiAccessLayer> logger) : base(apiBaseUrl, authenticationProvider, logger)
{ {
} }
public async Task<List<Novel>?> GetNovels() public async Task<List<UserNovel>?> GetNovels()
{ {
return (await SendRequest<List<Novel>>("novel", HttpMethod.Get)).ResponseObject; return (await SendRequest<List<UserNovel>>("novel", HttpMethod.Get)).ResponseObject;
} }
public async Task<Novel?> RequestNovelScrape(string url) public async Task<Novel?> RequestNovelScrape(string url)
@@ -23,9 +23,9 @@ public class WebApiAccessLayer : ApiAccessLayer
new ScrapeNovelRequest {NovelUrl = url})).ResponseObject; new ScrapeNovelRequest {NovelUrl = url})).ResponseObject;
} }
public async Task<Novel?> GetNovel(string guid) public async Task<UserNovel?> GetNovel(string guid)
{ {
return (await SendRequest<Novel?>($"novel/{guid}", HttpMethod.Get)).ResponseObject; return (await SendRequest<UserNovel?>($"novel/{guid}", HttpMethod.Get)).ResponseObject;
} }
public async Task<ScrapeNovelsResponse?> ScrapeNovels(List<string> novelUrls) public async Task<ScrapeNovelsResponse?> ScrapeNovels(List<string> novelUrls)
@@ -33,4 +33,13 @@ public class WebApiAccessLayer : ApiAccessLayer
return (await SendRequest<ScrapeNovelsResponse>("novel/scrapeNovels", HttpMethod.Post, null, return (await SendRequest<ScrapeNovelsResponse>("novel/scrapeNovels", HttpMethod.Post, null,
new ScrapeNovelsRequest {NovelUrls = novelUrls})).ResponseObject; new ScrapeNovelsRequest {NovelUrls = novelUrls})).ResponseObject;
} }
public async Task UpdateLastChapterRead(Novel novel, int chapter)
{
await SendRequest("novel/updateLastChapterRead", HttpMethod.Patch, new Dictionary<string, string>
{
{"novelGuid", novel.Guid.ToString()},
{"chapter", chapter.ToString()}
}, null);
}
} }

View File

@@ -1,6 +1,7 @@
<Router AppAssembly="@typeof(App).Assembly"> <CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData"> <Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/> <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/> <FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found> </Found>
<NotFound> <NotFound>
@@ -10,3 +11,4 @@
</LayoutView> </LayoutView>
</NotFound> </NotFound>
</Router> </Router>
</CascadingAuthenticationState>

View File

@@ -0,0 +1,29 @@
using System.Net.Http.Headers;
using System.Text.Json;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Common.AccessLayers;
namespace WebNovelPortal.Authentication;
public class BlazorAccessLayerAuthProvider : IAccessLayerAuthenticationProvider
{
private readonly IHttpContextAccessor _httpContextAccessor;
public BlazorAccessLayerAuthProvider(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public async Task AddAuthentication(HttpRequestMessage request)
{
var idToken = await _httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken);
if (!string.IsNullOrEmpty(idToken))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", idToken);
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -13,17 +14,22 @@ namespace WebNovelPortal.Controllers
public class AccountController : ControllerBase public class AccountController : ControllerBase
{ {
[HttpGet] [HttpGet]
[Route("account/login")] [Route("login")]
public async Task Login() public async Task Login(string redirect="/")
{ {
await HttpContext.ChallengeAsync(); await HttpContext.ChallengeAsync(new AuthenticationProperties
{
RedirectUri = redirect,
});
} }
[HttpGet] [HttpGet]
[Route("account/logout")] [Route("logout")]
public async Task Logout() public async Task Logout()
{ {
await HttpContext.SignOutAsync(); await HttpContext.SignOutAsync();
Response.Redirect("/");
} }
} }
} }

View File

@@ -6,7 +6,7 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src WORKDIR /src
COPY ["WebNovelPortal/WebNovelPortal.csproj", "WebNovelPortal/"] COPY ["WebNovelPortal/WebNovelPortal.csproj", "WebNovelPortal/"]
COPY ["Treestar.Shared/Treestar.Shared.csproj", "Treestar.Shared/"] COPY ["Common/Common.csproj", "Common/"]
RUN dotnet restore "WebNovelPortal/WebNovelPortal.csproj" RUN dotnet restore "WebNovelPortal/WebNovelPortal.csproj"
COPY . . COPY . .
WORKDIR "/src/WebNovelPortal" WORKDIR "/src/WebNovelPortal"

View File

@@ -0,0 +1,17 @@
@page "/Auth0InfoDump"
@using Microsoft.AspNetCore.Authentication
@using Microsoft.IdentityModel.Protocols.OpenIdConnect
<h3>Auth0InfoDump</h3>
<b>IdToken: </b> @IdToken
@code {
[Inject] private IHttpContextAccessor _contextAccessor { get; set; }
private string IdToken { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
var context = _contextAccessor.HttpContext;
IdToken = await context.GetTokenAsync(OpenIdConnectParameterNames.IdToken);
}
}

View File

@@ -7,20 +7,35 @@
<LoadingDisplay/> <LoadingDisplay/>
return; return;
} }
@if (!authenticated)
{
<div>you must login</div>
return;
}
<input @bind="NovelUrl" disabled="@awaitingRequest"/><button disabled="@IsDisabled()" onclick="@(() => RequestNovelScrape(NovelUrl))">Scrape</button><br/> <input @bind="NovelUrl" disabled="@awaitingRequest"/><button disabled="@IsDisabled()" onclick="@(() => RequestNovelScrape(NovelUrl))">Scrape</button><br/>
<button onclick="@UpdateNovels" disabled="@IsDisabled()">Update Novels</button> <button onclick="@UpdateNovels" disabled="@IsDisabled()">Update Novels</button>
<NovelList Novels="@novels"/> <NovelList Novels="@novels" InputDisabled="awaitingRequest" HandleUpdateNovelRequest="UpdateNovel"/>
@code { @code {
[Inject] [Inject]
WebApiAccessLayer api { get; set; } WebApiAccessLayer api { get; set; }
[CascadingParameter]
Task<AuthenticationState> AuthenticationStateTask { get; set; }
string NovelUrl { get; set; } string NovelUrl { get; set; }
List<Novel> novels = new List<Novel>(); List<UserNovel> novels = new List<UserNovel>();
protected bool loading = true; protected bool loading = true;
protected bool awaitingRequest = false; protected bool awaitingRequest = false;
protected bool authenticated = false;
protected override async Task OnInitializedAsync()
{
authenticated = (await AuthenticationStateTask).User.Identity.IsAuthenticated;
SetLoading(authenticated);
}
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (firstRender) if (firstRender && authenticated)
{ {
await RefreshNovels(); await RefreshNovels();
} }
@@ -45,9 +60,17 @@
async Task UpdateNovels() async Task UpdateNovels()
{ {
SetAwaitingRequest(true); SetAwaitingRequest(true);
var res = await api.ScrapeNovels(novels.Select(i => i.Url).ToList()); var res = await api.ScrapeNovels(novels.Select(i => i.Novel.Url).ToList());
SetAwaitingRequest(false);
await RefreshNovels(); await RefreshNovels();
SetAwaitingRequest(false);
}
async Task UpdateNovel(Novel novel)
{
SetAwaitingRequest(true);
var res = await api.RequestNovelScrape(novel.Url);
await RefreshNovels();
SetAwaitingRequest(false);
} }
bool IsDisabled() bool IsDisabled()

View File

@@ -7,20 +7,24 @@
} }
else else
{ {
<h3><a href="@Novel.Url">@(Novel.Title)</a></h3> <h3><a href="@Novel.Novel.Url">@(Novel.Novel.Title)</a></h3>
<h4>Author: <a href="@Novel.Author?.Url">@(Novel.Author?.Name ?? "Anonymous")</a></h4> <h4>Author: <a href="@Novel.Novel.Author?.Url">@(Novel.Novel.Author?.Name ?? "Anonymous")</a></h4>
<h4>Date Posted: @Novel.DatePosted</h4> <h4>Date Posted: @Novel.Novel.DatePosted</h4>
<h4>Date Updated: @Novel.LastUpdated</h4> <h4>Date Updated: @Novel.Novel.LastUpdated</h4>
<h4>Tags</h4> <h4>Tags</h4>
<ul> <ul>
@foreach (var tag in Novel.Tags) @foreach (var tag in Novel.Novel.Tags)
{ {
<li>@tag.TagValue</li> <li>@tag.TagValue</li>
} }
</ul> </ul>
<h4>Chapters</h4> <h4>Chapters (Read <input @bind="currentLastChapter" /> / @Novel.Novel.Chapters.Count())</h4>
@if (currentLastChapter != originalLastChapter)
{
<button disabled="@awaitingRequest" @onclick="@UpdateLastReadChapter">Save</button>
}
<ol> <ol>
@foreach (var chapter in Novel.Chapters.OrderBy(i => i.ChapterNumber)) @foreach (var chapter in Novel.Novel.Chapters.OrderBy(i => i.ChapterNumber))
{ {
<li><a href="@chapter.Url">@chapter.Name</a></li> <li><a href="@chapter.Url">@chapter.Name</a></li>
} }
@@ -32,16 +36,40 @@ else
public string? NovelId { get; set; } public string? NovelId { get; set; }
[Inject] [Inject]
public WebApiAccessLayer api { get; set; } public WebApiAccessLayer api { get; set; }
Novel? Novel { get; set; } UserNovel? Novel { get; set; }
int originalLastChapter;
int currentLastChapter;
bool awaitingRequest;
protected override async Task OnAfterRenderAsync(bool firstRender) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (firstRender) if (firstRender)
{ {
Novel = await api.GetNovel(NovelId); await UpdateNovelDetails();
StateHasChanged();
} }
await base.OnAfterRenderAsync(firstRender); await base.OnAfterRenderAsync(firstRender);
} }
private async Task UpdateNovelDetails()
{
Novel = await api.GetNovel(NovelId);
originalLastChapter = Novel.LastChapterRead;
currentLastChapter = originalLastChapter;
StateHasChanged();
}
private async Task UpdateLastReadChapter()
{
SetAwaitingRequest(true);
await api.UpdateLastChapterRead(Novel.Novel, currentLastChapter);
await UpdateNovelDetails();
SetAwaitingRequest(false);
}
private void SetAwaitingRequest(bool enabled)
{
awaitingRequest = enabled;
StateHasChanged();
}
} }

View File

@@ -1,21 +1,33 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.HttpOverrides;
using Newtonsoft.Json; using Newtonsoft.Json;
using Common.AccessLayers;
using Common.Authentication.OIDC;
using WebNovelPortal.AccessLayers; using WebNovelPortal.AccessLayers;
using WebNovelPortal.Authentication;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"])); builder.Services.AddScoped<IAccessLayerAuthenticationProvider, BlazorAccessLayerAuthProvider>();
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"], fac.GetRequiredService<IAccessLayerAuthenticationProvider>(), fac.GetRequiredService<ILogger<WebApiAccessLayer>>()));
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor(); builder.Services.AddServerSideBlazor();
builder.Services.AddHttpContextAccessor();
builder.Services.AddControllers().AddNewtonsoftJson(opt => builder.Services.AddControllers().AddNewtonsoftJson(opt =>
{ {
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
}); });
builder.Services.AddOIDCAuth(builder.Configuration);
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedHost | ForwardedHeaders.XForwardedProto;
});
var app = builder.Build(); var app = builder.Build();
app.UseForwardedHeaders();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {
@@ -23,13 +35,20 @@ if (!app.Environment.IsDevelopment())
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
else
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection(); //app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapBlazorHub(); app.MapBlazorHub();
app.MapFallbackToPage("/_Host"); app.MapFallbackToPage("/_Host");
app.MapControllers(); app.MapControllers();

View File

@@ -0,0 +1,21 @@
<AuthorizeView>
<Authorized>
Hello, @(LoggedInName)!
<a href="api/Account/logout">Log out</a>
</Authorized>
<NotAuthorized>
<a href="api/account/login?redirect=/">Log in</a>
</NotAuthorized>
</AuthorizeView>
@code {
[CascadingParameter]
Task<AuthenticationState> AuthenticationState { get; set; }
private string LoggedInName { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
LoggedInName = (await AuthenticationState).User.Identity.Name;
}
}

View File

@@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Components @using Microsoft.AspNetCore.Components
@using WebNovelPortal.AccessLayers
<h1>Novels</h1> <h1>Novels</h1>
<table> <table>
@@ -12,16 +13,19 @@
{ {
<tr> <tr>
<td> <td>
<a href="@($"/novel/{novel.Guid}")">@novel.Title</a> <a href="@($"/novel/{novel.Novel.Guid}")">@novel.Novel.Title</a>
</td> </td>
<td> <td>
<a href="@novel.Author?.Url">@(novel.Author?.Name ?? "Anonymous")</a> <a href="@novel.Novel.Author?.Url">@(novel.Novel.Author?.Name ?? "Anonymous")</a>
</td> </td>
<td> <td>
@novel.Chapters.Count @novel.Novel.Chapters.Count
</td> </td>
<td> <td>
@novel.LastUpdated @novel.Novel.LastUpdated
</td>
<td>
<button disabled="@InputDisabled" @onclick="@(()=>HandleUpdateNovelRequest.InvokeAsync(novel.Novel))">Update</button>
</td> </td>
</tr> </tr>
} }
@@ -29,5 +33,10 @@
@code { @code {
[Parameter] [Parameter]
public List<Novel> Novels { get; set; } public List<UserNovel> Novels { get; set; }
[Parameter]
public EventCallback<Novel> HandleUpdateNovelRequest { get; set; }
[Parameter]
public bool InputDisabled { get; set; }
} }

View File

@@ -9,7 +9,7 @@
<main> <main>
<div class="top-row px-4"> <div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a> <LoginDisplay/>
</div> </div>
<article class="content px-4"> <article class="content px-4">

View File

@@ -7,6 +7,7 @@
article { article {
flex: 1 1 auto; flex: 1 1 auto;
width: 100%;
} }
main { main {

View File

@@ -5,19 +5,20 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>32b7cf85-871e-439d-88a2-f8ff5186dafd</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Authentication" />
<Folder Include="Controllers" /> <Folder Include="Controllers" />
<Folder Include="Data" /> <Folder Include="Data" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Treestar.Shared\Treestar.Shared.csproj" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.7" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.7" />
</ItemGroup> </ItemGroup>

View File

@@ -11,4 +11,4 @@
@using WebNovelPortal.Shared.Layouts @using WebNovelPortal.Shared.Layouts
@using WebNovelPortal.Shared.Components.Layout @using WebNovelPortal.Shared.Components.Layout
@using WebNovelPortal.Shared.Components.Display @using WebNovelPortal.Shared.Components.Display
@using Treestar.Shared.Models.DBDomain @using Common.Models.DBDomain

View File

@@ -5,6 +5,12 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"OIDCAuthOptions": {
"Authority": "authority_here",
"ClientId": "clientid_here",
"ClientSecret": "clientsecret_here",
"Scopes": "openid profile email"
},
"AllowedHosts": "*", "AllowedHosts": "*",
"WebAPIUrl": "https://localhost:7137/api/" "WebAPIUrl": "https://localhost:7137/api/"
} }

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Common.Models.DBDomain;
using WebNovelPortalAPI.Middleware;
namespace WebNovelPortalAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class AuthorizedController : ControllerBase
{
protected int UserId
{
get
{
return (int) (HttpContext.Items[EnsureUserCreatedMiddleware.UserIdItemName] ?? 0);
}
}
public AuthorizedController()
{
}
}
}

View File

@@ -5,12 +5,13 @@ using System.Threading.Tasks;
using DBConnection; using DBConnection;
using DBConnection.Repositories; using DBConnection.Repositories;
using DBConnection.Repositories.Interfaces; using DBConnection.Repositories.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
using Treestar.Shared.Models.DTO; using Common.Models.DTO;
using Treestar.Shared.Models.DTO.Requests; using Common.Models.DTO.Requests;
using Treestar.Shared.Models.DTO.Responses; using Common.Models.DTO.Responses;
using WebNovelPortalAPI.Exceptions; using WebNovelPortalAPI.Exceptions;
using WebNovelPortalAPI.Scrapers; using WebNovelPortalAPI.Scrapers;
@@ -18,15 +19,18 @@ namespace WebNovelPortalAPI.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class NovelController : ControllerBase [Authorize]
public class NovelController : AuthorizedController
{ {
private readonly INovelRepository _novelRepository; private readonly INovelRepository _novelRepository;
private readonly IUserRepository _userRepository;
private readonly IEnumerable<IScraper> _scrapers; private readonly IEnumerable<IScraper> _scrapers;
public NovelController(IEnumerable<IScraper> scrapers, INovelRepository novelRepository) public NovelController(IEnumerable<IScraper> scrapers, INovelRepository novelRepository, IUserRepository userRepository)
{ {
_scrapers = scrapers; _scrapers = scrapers;
_novelRepository = novelRepository; _novelRepository = novelRepository;
_userRepository = userRepository;
} }
private async Task<Novel?> ScrapeNovel(string url) private async Task<Novel?> ScrapeNovel(string url)
@@ -36,7 +40,7 @@ namespace WebNovelPortalAPI.Controllers
{ {
throw new NoMatchingScraperException(url); throw new NoMatchingScraperException(url);
} }
var novel = scraper.ScrapeNovel(url); var novel = await scraper.ScrapeNovel(url);
return novel; return novel;
} }
@@ -45,17 +49,27 @@ namespace WebNovelPortalAPI.Controllers
return _scrapers.FirstOrDefault(i => i.MatchesUrl(novelUrl)); return _scrapers.FirstOrDefault(i => i.MatchesUrl(novelUrl));
} }
[HttpGet] private async Task<User> GetUser()
[Route("{guid:guid}")]
public async Task<Novel?> GetNovel(Guid guid)
{ {
return await _novelRepository.GetNovel(guid); return await _userRepository.GetIncluded(u => u.Id == UserId);
} }
[HttpGet] [HttpGet]
public async Task<List<Novel>> GetNovels() [Route("{guid:guid}")]
public async Task<UserNovel?> GetNovel(Guid guid)
{ {
return (await _novelRepository.GetAllIncluded()).ToList(); var user = await GetUser();
var novel = await _novelRepository.GetNovel(guid);
return user.WatchedNovels.FirstOrDefault(un => un.NovelUrl == novel.Url);
}
[HttpGet]
public async Task<List<UserNovel>> GetNovels()
{
var user = await GetUser();
var novels = user.WatchedNovels.Select(i => i.Novel);
(await _novelRepository.GetWhereIncluded(novels)).ToList();
return user.WatchedNovels.ToList();
} }
[HttpPost] [HttpPost]
@@ -75,11 +89,12 @@ namespace WebNovelPortalAPI.Controllers
failures[novelUrl] = e; failures[novelUrl] = e;
} }
} }
List<Novel> successfulUploads;
IEnumerable<Novel> successfulUploads;
try try
{ {
successfulUploads = await _novelRepository.UpsertMany(successfulScrapes); successfulUploads = (await _novelRepository.UpsertMany(successfulScrapes, true)).ToList();
var user = await GetUser();
await _userRepository.AssignNovelsToUser(user, successfulUploads);
} }
catch (Exception e) catch (Exception e)
{ {
@@ -99,7 +114,9 @@ namespace WebNovelPortalAPI.Controllers
try try
{ {
var novel = await ScrapeNovel(request.NovelUrl); var novel = await ScrapeNovel(request.NovelUrl);
var dbNovel = await _novelRepository.Upsert(novel); var dbNovel = await _novelRepository.Upsert(novel, true);
var user = await GetUser();
await _userRepository.AssignNovelsToUser(user, new List<Novel> {novel});
return Ok(dbNovel); return Ok(dbNovel);
} }
catch (NoMatchingScraperException e) catch (NoMatchingScraperException e)
@@ -111,5 +128,15 @@ namespace WebNovelPortalAPI.Controllers
return StatusCode(500, e); return StatusCode(500, e);
} }
} }
[HttpPatch]
[Route("updateLastChapterRead")]
public async Task<IActionResult> UpdateLastChapterRead(Guid novelGuid, int chapter)
{
var user = await GetUser();
var novel = await _novelRepository.GetNovel(novelGuid);
await _userRepository.UpdateLastChapterRead(user, novel, chapter);
return Ok();
}
} }
} }

View File

@@ -7,7 +7,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src WORKDIR /src
COPY ["WebNovelPortalAPI/WebNovelPortalAPI.csproj", "WebNovelPortalAPI/"] COPY ["WebNovelPortalAPI/WebNovelPortalAPI.csproj", "WebNovelPortalAPI/"]
COPY ["DBConnection/DBConnection.csproj", "DBConnection/"] COPY ["DBConnection/DBConnection.csproj", "DBConnection/"]
COPY ["Treestar.Shared/Treestar.Shared.csproj", "Treestar.Shared/"] COPY ["Common/Common.csproj", "Common/"]
RUN dotnet restore "WebNovelPortalAPI/WebNovelPortalAPI.csproj" RUN dotnet restore "WebNovelPortalAPI/WebNovelPortalAPI.csproj"
COPY . . COPY . .
WORKDIR "/src/WebNovelPortalAPI" WORKDIR "/src/WebNovelPortalAPI"

View File

@@ -0,0 +1,32 @@
using System.Security.Claims;
using DBConnection.Repositories.Interfaces;
using Microsoft.AspNetCore.Mvc.Filters;
using Common.Models.DBDomain;
namespace WebNovelPortalAPI.Middleware;
public class EnsureUserCreatedMiddleware : IMiddleware
{
private readonly IUserRepository _userRepository;
public const string UserIdItemName = "userId";
public EnsureUserCreatedMiddleware(IUserRepository userRepository)
{
_userRepository = userRepository;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (!context.User.Identity.IsAuthenticated)
{
await next(context);
return;
}
var userEmail = context.User.Claims.FirstOrDefault(i => i.Type == ClaimTypes.Email)?.Value;
var dbUser = await _userRepository.GetIncluded(u => u.Email == userEmail) ?? await _userRepository.Upsert(new User
{
Email = userEmail
});
context.Items[UserIdItemName] = dbUser.Id;
await next(context);
}
}

View File

@@ -2,8 +2,11 @@ using DBConnection;
using DBConnection.Contexts; using DBConnection.Contexts;
using DBConnection.Extensions; using DBConnection.Extensions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
using Common.Authentication.JwtBearer;
using WebNovelPortalAPI.Extensions; using WebNovelPortalAPI.Extensions;
using WebNovelPortalAPI.Middleware;
using WebNovelPortalAPI.Scrapers; using WebNovelPortalAPI.Scrapers;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -11,13 +14,40 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddDbServices(builder.Configuration); builder.Services.AddDbServices(builder.Configuration);
builder.Services.AddScrapers(); builder.Services.AddScrapers();
builder.Services.AddJwtBearerAuth(builder.Configuration);
builder.Services.AddScoped<EnsureUserCreatedMiddleware>();
builder.Services.AddControllers().AddNewtonsoftJson(opt => builder.Services.AddControllers().AddNewtonsoftJson(opt =>
{ {
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
}); });
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen(opt =>
{
opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Bearer token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "bearer"
});
opt.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
var app = builder.Build(); var app = builder.Build();
app.UpdateDatabase<AppDbContext>(); app.UpdateDatabase<AppDbContext>();
@@ -30,8 +60,9 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseMiddleware<EnsureUserCreatedMiddleware>();
app.MapControllers(); app.MapControllers();
app.Run(); app.Run();

View File

@@ -1,11 +1,32 @@
using System.Net;
using System.Net.Http.Headers;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using HtmlAgilityPack; using HtmlAgilityPack;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
using Common.Models.Enums;
namespace WebNovelPortalAPI.Scrapers; namespace WebNovelPortalAPI.Scrapers;
public abstract class AbstractScraper : IScraper public abstract class AbstractScraper : IScraper
{ {
protected AbstractScraper()
{
var cookieContainer = new CookieContainer();
var handler = new HttpClientHandler
{
CookieContainer = cookieContainer
};
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Chrome","96.0.4664.110"));
foreach (var cookie in RequestCookies())
{
cookieContainer.Add(cookie);
}
HttpClient = client;
}
protected HttpClient HttpClient { get; }
protected abstract string UrlMatchPattern { get; } protected abstract string UrlMatchPattern { get; }
protected abstract string BaseUrlPattern { get; } protected abstract string BaseUrlPattern { get; }
protected virtual string? WorkTitlePattern { get; } protected virtual string? WorkTitlePattern { get; }
@@ -18,6 +39,15 @@ public abstract class AbstractScraper : IScraper
protected virtual string? TagPattern { get; } protected virtual string? TagPattern { get; }
protected virtual string? DatePostedPattern { get; } protected virtual string? DatePostedPattern { get; }
protected virtual string? DateUpdatedPattern { get; } protected virtual string? DateUpdatedPattern { get; }
protected virtual NovelStatus DefaultStatus => NovelStatus.Unknown;
protected async Task<HtmlDocument> GetPage(string url)
{
var response = await HttpClient.GetAsync(url);
var doc = new HtmlDocument();
doc.LoadHtml(await response.Content.ReadAsStringAsync());
return doc;
}
protected virtual (DateTime? Posted, DateTime? Updated) GetDateTimeForChapter(HtmlNode linkNode, HtmlNode baseNode, protected virtual (DateTime? Posted, DateTime? Updated) GetDateTimeForChapter(HtmlNode linkNode, HtmlNode baseNode,
string baseUrl, string novelUrl) string baseUrl, string novelUrl)
@@ -72,8 +102,8 @@ public abstract class AbstractScraper : IScraper
ChapterNumber = i + 1, ChapterNumber = i + 1,
Url = $"{baseUrl}{node.Attributes["href"].Value}", Url = $"{baseUrl}{node.Attributes["href"].Value}",
Name = node.SelectSingleNode(namexpath).InnerText, Name = node.SelectSingleNode(namexpath).InnerText,
DatePosted = dates.Posted, DatePosted = dates.Posted?.ToUniversalTime(),
DateUpdated = dates.Updated DateUpdated = dates.Updated?.ToUniversalTime()
}; };
}); });
@@ -87,32 +117,39 @@ public abstract class AbstractScraper : IScraper
return nodes.Select(node => new Tag return nodes.Select(node => new Tag
{ {
TagValue = node.InnerText TagValue = node.InnerText
}).ToList(); }).Union(GetMetadataTags(document, baseUrl, novelUrl)).ToList();
} }
protected virtual DateTime GetPostedDate(HtmlDocument document, string baseUrl, string novelUrl) protected virtual DateTime GetPostedDate(HtmlDocument document, string baseUrl, string novelUrl)
{ {
var xpath = DatePostedPattern; var xpath = DatePostedPattern;
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText); return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText).ToUniversalTime();
} }
protected virtual DateTime GetLastUpdatedDate(HtmlDocument document, string baseUrl, string novelUrl) protected virtual DateTime GetLastUpdatedDate(HtmlDocument document, string baseUrl, string novelUrl)
{ {
var xpath = DateUpdatedPattern; var xpath = DateUpdatedPattern;
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText); return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText).ToUniversalTime();
} }
public Novel ScrapeNovel(string url) protected virtual List<Cookie> RequestCookies()
{ {
var web = new HtmlWeb(); return new List<Cookie>();
var doc = web.Load(url); }
if (doc == null)
protected abstract IEnumerable<Tag> GetMetadataTags(HtmlDocument document, string baseUrl, string novelUrl);
public virtual async Task<Novel> ScrapeNovel(string url)
{
var baseUrl = new Regex(BaseUrlPattern, RegexOptions.IgnoreCase).Match(url).Value;
var novelUrl = new Regex(UrlMatchPattern, RegexOptions.IgnoreCase).Match(url).Value;
var doc = await GetPage(novelUrl);
if (string.IsNullOrEmpty(doc.Text))
{ {
throw new Exception("Error parsing document"); throw new Exception("Error parsing document");
} }
var baseUrl = new Regex(BaseUrlPattern).Match(url).Value;
var novelUrl = new Regex(UrlMatchPattern).Match(url).Value;
return new Novel return new Novel
{ {
Author = GetAuthor(doc, baseUrl, novelUrl), Author = GetAuthor(doc, baseUrl, novelUrl),
@@ -121,11 +158,12 @@ public abstract class AbstractScraper : IScraper
LastUpdated = GetLastUpdatedDate(doc, baseUrl, novelUrl), LastUpdated = GetLastUpdatedDate(doc, baseUrl, novelUrl),
Tags = GetTags(doc, baseUrl, novelUrl), Tags = GetTags(doc, baseUrl, novelUrl),
Title = GetNovelTitle(doc, baseUrl, novelUrl), Title = GetNovelTitle(doc, baseUrl, novelUrl),
Url = novelUrl Url = novelUrl,
Status = DefaultStatus
}; };
} }
public string? ScrapeChapterContent(string chapterUrl) public Task<string?> ScrapeChapterContent(string chapterUrl)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -1,11 +1,11 @@
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
namespace WebNovelPortalAPI.Scrapers; namespace WebNovelPortalAPI.Scrapers;
public interface IScraper public interface IScraper
{ {
public bool MatchesUrl(string url); public bool MatchesUrl(string url);
public Novel ScrapeNovel(string url); public Task<Novel> ScrapeNovel(string url);
public string? ScrapeChapterContent(string chapterUrl); public Task<string?> ScrapeChapterContent(string chapterUrl);
} }

View File

@@ -1,12 +1,13 @@
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Common.Models.DBDomain;
using HtmlAgilityPack; using HtmlAgilityPack;
namespace WebNovelPortalAPI.Scrapers; namespace WebNovelPortalAPI.Scrapers;
public class KakuyomuScraper : AbstractScraper public class KakuyomuScraper : AbstractScraper
{ {
protected override string UrlMatchPattern => @"https?:\/\/kakuyomu\.jp\/works\/\d+\/?"; protected override string UrlMatchPattern => @"https?:\/\/kakuyomu\.jp\/works\/\d+";
protected override string BaseUrlPattern => @"https?:\/\/kakuyomu\.jp"; protected override string BaseUrlPattern => @"https?:\/\/kakuyomu\.jp";
@@ -24,7 +25,7 @@ public class KakuyomuScraper : AbstractScraper
protected override string? TagPattern => @"//span[@itemprop='keywords']/a"; protected override string? TagPattern => @"//span[@itemprop='keywords']/a";
protected override string? DatePostedPattern => @"//time[@itemprop='datePublished']"; protected override string? DatePostedPattern => @"//section[@id='work-information']//time[@itemprop='datePublished']";
protected override string? DateUpdatedPattern => @"//time[@itemprop='dateModified']"; protected override string? DateUpdatedPattern => @"//time[@itemprop='dateModified']";
@@ -32,6 +33,15 @@ public class KakuyomuScraper : AbstractScraper
string novelUrl) string novelUrl)
{ {
var datePosted = linkNode.SelectSingleNode(ChapterPostedPattern).Attributes["datetime"].Value; var datePosted = linkNode.SelectSingleNode(ChapterPostedPattern).Attributes["datetime"].Value;
return (DateTime.Parse(datePosted), null); return (DateTime.Parse(datePosted).ToUniversalTime(), null);
}
protected override IEnumerable<Tag> GetMetadataTags(HtmlDocument document, string baseUrl, string novelUrl)
{
return new List<Tag>
{
Tag.GetSiteTag(baseUrl),
Tag.GetOriginalWorkTag()
};
} }
} }

View File

@@ -1,19 +1,21 @@
using System.Net;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using HtmlAgilityPack; using HtmlAgilityPack;
using Treestar.Shared.Models.DBDomain; using Common.Models.DBDomain;
using Common.Models.Enums;
namespace WebNovelPortalAPI.Scrapers; namespace WebNovelPortalAPI.Scrapers;
public class SyosetuScraper : AbstractScraper public class SyosetuScraper : AbstractScraper
{ {
protected override string UrlMatchPattern => @"https?:\/\/\w+\.syosetu\.com\/\w+\/?"; protected override string UrlMatchPattern => @"https?:\/\/(\w+)\.syosetu\.com\/n\w+";
protected override string BaseUrlPattern => @"https?:\/\/\w+\.syosetu\.com"; protected override string BaseUrlPattern => @"https?:\/\/(\w+)\.syosetu\.com";
protected override string? WorkTitlePattern => @"//p[@class='novel_title']"; protected override string? WorkTitlePattern => @"//p[@class='novel_title']";
protected override string? AuthorNamePattern => @"//div[@class='novel_writername']/a | //div[@class='novel_writername']"; protected override string? AuthorNamePattern => @"//div[@class='novel_writername']/a";
protected override string? AuthorLinkPattern => @"//div[@class='novel_writername']/a"; protected override string? AuthorLinkPattern => @"//div[@class='novel_writername']/a";
@@ -27,22 +29,37 @@ public class SyosetuScraper : AbstractScraper
protected override string? DatePostedPattern => @"//th[text()='掲載日']/following-sibling::td"; protected override string? DatePostedPattern => @"//th[text()='掲載日']/following-sibling::td";
protected override string? DateUpdatedPattern => @"//th[contains(text(),'掲載日')]/following-sibling::td"; protected override string? DateUpdatedPattern => @"//th[contains(text(),'掲載日')]/following-sibling::td | //th[contains(text(),'最終更新日')]/following-sibling::td";
private HtmlDocument? GetInfoPage(string baseUrl, string novelUrl) private async Task<HtmlDocument> GetInfoPage(string baseUrl, string novelUrl)
{ {
string novelInfoBase = $"/novelview/infotop/ncode/"; string novelInfoBase = $"/novelview/infotop/ncode/";
string novelRegex = @"https?:\/\/\w+\.syosetu\.com\/(\w+)\/?"; string novelRegex = @"https?:\/\/\w+\.syosetu\.com\/(\w+)\/?";
string novelCode = new Regex(novelRegex).Match(novelUrl).Groups[1].Value; string novelCode = new Regex(novelRegex, RegexOptions.IgnoreCase).Match(novelUrl).Groups[1].Value;
string novelInfoPage = $"{baseUrl}{novelInfoBase}{novelCode}"; string novelInfoPage = $"{baseUrl}{novelInfoBase}{novelCode}";
var web = new HtmlWeb(); return await GetPage(novelInfoPage);
return web.Load(novelInfoPage);
} }
protected override List<Chapter> GetChapters(HtmlDocument document, string baseUrl, string novelUrl) protected List<Chapter> GetChapters(HtmlDocument document, string baseUrl, string novelUrl, string novelName, DateTime novelPostedDate, DateTime novelUpdatedDate)
{ {
string dateUpdatedRegex = @"\d\d\d\d\/\d\d\/\d\d \d\d:\d\d"; string dateUpdatedRegex = @"\d\d\d\d\/\d\d\/\d\d \d\d:\d\d";
var nodes = document.DocumentNode.SelectNodes(ChapterUrlPattern); var nodes = document.DocumentNode.SelectNodes(ChapterUrlPattern);
// single chapter syosetu novel
if (nodes == null)
{
return new List<Chapter>
{
new Chapter
{
ChapterNumber = 1,
Name = novelName,
Url = novelUrl,
DatePosted = novelPostedDate,
DateUpdated = novelUpdatedDate
}
};
}
return nodes.Select((node,i) => return nodes.Select((node,i) =>
{ {
var datePostedNode = node.ParentNode.SelectSingleNode(ChapterPostedPattern); var datePostedNode = node.ParentNode.SelectSingleNode(ChapterPostedPattern);
@@ -62,8 +79,8 @@ public class SyosetuScraper : AbstractScraper
Name = node.InnerText, Name = node.InnerText,
Url = baseUrl + node.Attributes["href"].Value, Url = baseUrl + node.Attributes["href"].Value,
ChapterNumber = i+1, ChapterNumber = i+1,
DatePosted = datePosted, DatePosted = datePosted.ToUniversalTime(),
DateUpdated = dateUpdated DateUpdated = dateUpdated.ToUniversalTime()
}; };
}).ToList(); }).ToList();
} }
@@ -85,35 +102,92 @@ public class SyosetuScraper : AbstractScraper
protected override DateTime GetPostedDate(HtmlDocument document, string baseUrl, string novelUrl) protected override DateTime GetPostedDate(HtmlDocument document, string baseUrl, string novelUrl)
{ {
var doc = GetInfoPage(baseUrl, novelUrl); var node = document.DocumentNode.SelectSingleNode(DatePostedPattern);
if (doc == null) return DateTime.Parse(node.InnerText).ToUniversalTime();
{
return DateTime.MinValue;
}
var node = doc.DocumentNode.SelectSingleNode(DatePostedPattern);
return DateTime.Parse(node.InnerText);
} }
protected override DateTime GetLastUpdatedDate(HtmlDocument document, string baseUrl, string novelUrl) protected override DateTime GetLastUpdatedDate(HtmlDocument document, string baseUrl, string novelUrl)
{ {
var doc = GetInfoPage(baseUrl, novelUrl); return DateTime.Parse(document.DocumentNode.SelectNodes(DateUpdatedPattern).Last().InnerText).ToUniversalTime();
if (doc == null)
{
return DateTime.MinValue;
}
return DateTime.Parse(doc.DocumentNode.SelectNodes(DateUpdatedPattern)[1].InnerText);
} }
protected override List<Tag> GetTags(HtmlDocument document, string baseUrl, string novelUrl) protected override List<Tag> GetTags(HtmlDocument document, string baseUrl, string novelUrl)
{ {
var doc = GetInfoPage(baseUrl, novelUrl); var tags = document.DocumentNode.SelectSingleNode(TagPattern).InnerText.Replace("\n", "").Replace("&nbsp;", " ").Split(' ');
if (doc == null) return tags.Select(i => new Tag {TagValue = i}).Union(GetMetadataTags(document, baseUrl, novelUrl)).ToList();
{
return new List<Tag>();
} }
var tags = doc.DocumentNode.SelectSingleNode(TagPattern).InnerText.Replace("\n", "").Replace("&nbsp;", " ").Split(' '); protected override List<Cookie> RequestCookies()
return tags.Select(i => new Tag {TagValue = i}).ToList(); {
var domain = ".syosetu.com";
return new List<Cookie>
{
new Cookie
{
Domain = domain,
Name = "over18",
Value = "yes"
}
};
}
protected override IEnumerable<Tag> GetMetadataTags(HtmlDocument document, string baseUrl, string novelUrl)
{
bool nsfw = Regex.Match(baseUrl, BaseUrlPattern).Groups[1].Value == "novel18";
var tags = new List<Tag>
{
Tag.GetSiteTag(baseUrl),
Tag.GetOriginalWorkTag()
};
if (nsfw)
{
tags.Add(Tag.GetNsfwTag());
}
return tags;
}
public override async Task<Novel> ScrapeNovel(string url)
{
var baseUrl = new Regex(BaseUrlPattern, RegexOptions.IgnoreCase).Match(url).Value;
var novelUrl = new Regex(UrlMatchPattern, RegexOptions.IgnoreCase).Match(url).Value;
HtmlDocument baseDoc;
HtmlDocument novelInfoPage;
try
{
baseDoc = await GetPage(novelUrl);
novelInfoPage = await GetInfoPage(baseUrl, novelUrl);
}
catch (Exception e)
{
throw new Exception("Error parsing document");
}
var novelName = GetNovelTitle(baseDoc,
baseUrl,
novelUrl);
var lastUpdated = GetLastUpdatedDate(novelInfoPage, baseUrl, novelUrl);
var datePosted = GetPostedDate(novelInfoPage,
baseUrl,
novelUrl);
return new Novel
{
Title = novelName,
Author = GetAuthor(baseDoc,
baseUrl,
novelUrl),
Chapters = GetChapters(baseDoc,
baseUrl,
novelUrl,
novelName,
datePosted,
lastUpdated),
LastUpdated = lastUpdated,
Tags = GetTags(novelInfoPage,
baseUrl,
novelUrl),
DatePosted = datePosted,
Url = novelUrl
};
} }
} }

View File

@@ -5,10 +5,12 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>dd5e7c53-e576-4442-ae30-c496ec2070a5</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.43" /> <PackageReference Include="HtmlAgilityPack" Version="1.11.43" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.7" />
@@ -22,7 +24,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DBConnection\DBConnection.csproj" /> <ProjectReference Include="..\DBConnection\DBConnection.csproj" />
<ProjectReference Include="..\Treestar.Shared\Treestar.Shared.csproj" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -9,6 +9,10 @@
"Sqlite": "Data Source=test_db", "Sqlite": "Data Source=test_db",
"PostgresSql": "placeholder" "PostgresSql": "placeholder"
}, },
"JwtBearerAuthOptions": {
"Authority": "placeholder",
"Audience": ""
},
"DatabaseProvider": "Sqlite", "DatabaseProvider": "Sqlite",
"AllowedHosts": "*" "AllowedHosts": "*"
} }