This commit is contained in:
32
.drone.yml
Normal file
32
.drone.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
|
||||
commands:
|
||||
- dotnet restore *.sln
|
||||
- mkdir build
|
||||
- mkdir publish
|
||||
- mkdir publish/api
|
||||
- mkdir publish/frontend
|
||||
- mkdir dist
|
||||
- dotnet build *.sln -c Release -o build
|
||||
- dotnet publish WebNovelPortalAPI/*.csproj -c Release -o publish/api
|
||||
- dotnet publish WebNovelPortal/*.csproj -c Release -o publish/frontend
|
||||
- tar -czvf dist/API.tar.gz publish/api/*
|
||||
- tar -czvf dist/Frontend.tar.gz publish/frontend/*
|
||||
|
||||
|
||||
|
||||
- name: gitea_release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: gitea-api-key
|
||||
base_url: https://git.orfl.xyz
|
||||
files:
|
||||
- dist/*
|
||||
when:
|
||||
event: tag
|
||||
253
DBConnection/Migrations/20220715040739_AddLastContentFetch.Designer.cs
generated
Normal file
253
DBConnection/Migrations/20220715040739_AddLastContentFetch.Designer.cs
generated
Normal file
@@ -0,0 +1,253 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715040739_AddLastContentFetch")]
|
||||
partial class AddLastContentFetch
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ChapterNumber")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastContentFetch")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AuthorUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LastChapterRead")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("NovelUrl", "UserId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserNovels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Novel");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
public partial class AddLastContentFetch : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters");
|
||||
}
|
||||
}
|
||||
}
|
||||
253
DBConnection/Migrations/20220715135707_make some chapter fields optional.Designer.cs
generated
Normal file
253
DBConnection/Migrations/20220715135707_make some chapter fields optional.Designer.cs
generated
Normal file
@@ -0,0 +1,253 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715135707_make some chapter fields optional")]
|
||||
partial class makesomechapterfieldsoptional
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ChapterNumber")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("LastContentFetch")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AuthorUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LastChapterRead")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("NovelUrl", "UserId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserNovels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Novel");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
public partial class makesomechapterfieldsoptional : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DateUpdated",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DatePosted",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "LastContentFetch",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DateUpdated",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "DatePosted",
|
||||
table: "Chapters",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
257
DBConnection/Migrations/20220715143230_add id for novels.Designer.cs
generated
Normal file
257
DBConnection/Migrations/20220715143230_add id for novels.Designer.cs
generated
Normal file
@@ -0,0 +1,257 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DBConnection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20220715143230_add id for novels")]
|
||||
partial class addidfornovels
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.7");
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ChapterNumber")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("LastContentFetch")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RawContent")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("AuthorUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
{
|
||||
b.Property<string>("TagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("DateCreated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
{
|
||||
b.Property<string>("NovelUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("LastChapterRead")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("NovelUrl", "UserId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserNovels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.Property<string>("NovelsUrl")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagsTagValue")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("NovelsUrl", "TagsTagValue");
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelUrl");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Author", "Author")
|
||||
.WithMany("Novels")
|
||||
.HasForeignKey("AuthorUrl");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", "Novel")
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.User", "User")
|
||||
.WithMany("WatchedNovels")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Novel");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
{
|
||||
b.HasOne("DBConnection.Models.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsUrl")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DBConnection.Models.Tag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsTagValue")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Author", b =>
|
||||
{
|
||||
b.Navigation("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
{
|
||||
b.Navigation("WatchedNovels");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
27
DBConnection/Migrations/20220715143230_add id for novels.cs
Normal file
27
DBConnection/Migrations/20220715143230_add id for novels.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DBConnection.Migrations
|
||||
{
|
||||
public partial class addidfornovels : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "Guid",
|
||||
table: "Novels",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Guid",
|
||||
table: "Novels");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasKey("Url");
|
||||
|
||||
b.ToTable("Authors");
|
||||
b.ToTable("Authors", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
@@ -54,10 +54,13 @@ namespace DBConnection.Migrations
|
||||
b.Property<DateTime>("DateModified")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DatePosted")
|
||||
b.Property<DateTime?>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("DateUpdated")
|
||||
b.Property<DateTime?>("DateUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("LastContentFetch")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
@@ -74,7 +77,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("Chapters");
|
||||
b.ToTable("Chapters", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Novel", b =>
|
||||
@@ -94,6 +97,10 @@ namespace DBConnection.Migrations
|
||||
b.Property<DateTime>("DatePosted")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastUpdated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
@@ -105,7 +112,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("AuthorUrl");
|
||||
|
||||
b.ToTable("Novels");
|
||||
b.ToTable("Novels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Tag", b =>
|
||||
@@ -121,7 +128,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasKey("TagValue");
|
||||
|
||||
b.ToTable("Tags");
|
||||
b.ToTable("Tags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.User", b =>
|
||||
@@ -142,7 +149,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
b.ToTable("Users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.UserNovel", b =>
|
||||
@@ -160,7 +167,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserNovels");
|
||||
b.ToTable("UserNovels", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelTag", b =>
|
||||
@@ -175,7 +182,7 @@ namespace DBConnection.Migrations
|
||||
|
||||
b.HasIndex("TagsTagValue");
|
||||
|
||||
b.ToTable("NovelTag");
|
||||
b.ToTable("NovelTag", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DBConnection.Models.Chapter", b =>
|
||||
|
||||
@@ -10,6 +10,7 @@ public class Chapter : BaseEntity
|
||||
public string? RawContent { get; set; }
|
||||
[Key]
|
||||
public string Url { get; set; }
|
||||
public DateTime DatePosted { get; set; }
|
||||
public DateTime DateUpdated { get; set; }
|
||||
public DateTime? DatePosted { get; set; }
|
||||
public DateTime? DateUpdated { get; set; }
|
||||
public DateTime? LastContentFetch { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DBConnection.Models;
|
||||
|
||||
@@ -6,6 +7,7 @@ public class Novel : BaseEntity
|
||||
{
|
||||
[Key]
|
||||
public string Url { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Author Author { get; set; }
|
||||
public List<Tag> Tags { get; set; }
|
||||
|
||||
@@ -47,6 +47,11 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
|
||||
return entity;
|
||||
}
|
||||
|
||||
public virtual async Task<IEnumerable<TEntityType>> GetAllIncluded()
|
||||
{
|
||||
return await GetWhereIncluded(i => true);
|
||||
}
|
||||
|
||||
public virtual async Task<TEntityType?> GetIncluded(TEntityType entity)
|
||||
{
|
||||
return await GetIncluded(dbEntity => GetPrimaryKey(dbEntity).SequenceEqual(GetPrimaryKey(entity)));
|
||||
|
||||
@@ -4,5 +4,5 @@ namespace DBConnection.Repositories.Interfaces;
|
||||
|
||||
public interface INovelRepository : IRepository<Novel>
|
||||
{
|
||||
|
||||
Task<Novel?> GetNovel(Guid guid);
|
||||
}
|
||||
@@ -14,4 +14,5 @@ public interface IRepository<TEntityType> : IRepository where TEntityType : Base
|
||||
Task<TEntityType?> GetIncluded(TEntityType entity);
|
||||
Task<TEntityType?> GetIncluded(Func<TEntityType, bool> predicate);
|
||||
Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate);
|
||||
Task<IEnumerable<TEntityType>> GetAllIncluded();
|
||||
}
|
||||
@@ -17,16 +17,38 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
|
||||
public override async Task<Novel> Upsert(Novel entity)
|
||||
{
|
||||
var dbEntity = await GetIncluded(entity) ?? entity;
|
||||
// Author
|
||||
dbEntity.Author = await _authorRepository.GetIncluded(entity.Author) ?? entity.Author;
|
||||
//Tags
|
||||
List<Tag> newTags = new List<Tag>();
|
||||
foreach (var tag in dbEntity.Tags)
|
||||
foreach (var tag in entity.Tags)
|
||||
{
|
||||
newTags.Add(await _tagRepository.GetIncluded(tag) ?? tag);
|
||||
}
|
||||
dbEntity.Tags.Clear();
|
||||
dbEntity.Tags = newTags;
|
||||
//chapters
|
||||
var newChapters = new List<Chapter>();
|
||||
foreach (var chapter in entity.Chapters.ToList())
|
||||
{
|
||||
var existingChapter = await DbContext.Chapters.FindAsync(chapter.Url);
|
||||
if (existingChapter == null)
|
||||
{
|
||||
newChapters.Add(chapter);
|
||||
}
|
||||
else
|
||||
{
|
||||
existingChapter.Name = chapter.Name;
|
||||
existingChapter.DateUpdated = chapter.DateUpdated;
|
||||
newChapters.Add(existingChapter);
|
||||
}
|
||||
}
|
||||
dbEntity.Chapters.Clear();
|
||||
dbEntity.Chapters = newChapters;
|
||||
// update in db
|
||||
if (DbContext.Entry(dbEntity).State == EntityState.Detached)
|
||||
{
|
||||
dbEntity.Guid = Guid.NewGuid();
|
||||
DbContext.Add(dbEntity);
|
||||
}
|
||||
|
||||
@@ -42,6 +64,11 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
|
||||
.Include(i => i.Tags);
|
||||
}
|
||||
|
||||
public async Task<Novel?> GetNovel(Guid guid)
|
||||
{
|
||||
return await GetIncluded(i => i.Guid == guid);
|
||||
}
|
||||
|
||||
public async Task<Novel?> GetNovel(string url)
|
||||
{
|
||||
return await GetIncluded(i => i.Url == url);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Newtonsoft.Json;
|
||||
using Shared.Models;
|
||||
@@ -10,8 +12,12 @@ public abstract class ApiAccessLayer
|
||||
|
||||
protected ApiAccessLayer(string apiBaseUrl)
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.BaseAddress = new Uri(apiBaseUrl);
|
||||
var handler = new HttpClientHandler()
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
||||
};
|
||||
_httpClient = new HttpClient(handler);
|
||||
_httpClient.BaseAddress = new Uri(apiBaseUrl, UriKind.Absolute);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseWrapper> SendRequest(HttpRequestMessage message)
|
||||
@@ -53,12 +59,11 @@ public abstract class ApiAccessLayer
|
||||
{
|
||||
uri = QueryHelpers.AddQueryString(endpoint, queryParams);
|
||||
}
|
||||
|
||||
message.RequestUri = new Uri(uri);
|
||||
message.RequestUri = new Uri(uri, UriKind.Relative);
|
||||
message.Method = method;
|
||||
if (data != null)
|
||||
{
|
||||
message.Content = new StringContent(JsonConvert.SerializeObject(data));
|
||||
message.Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||
}
|
||||
|
||||
return message;
|
||||
|
||||
28
WebNovelPortal/AccessLayers/WebApiAccessLayer.cs
Normal file
28
WebNovelPortal/AccessLayers/WebApiAccessLayer.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using DBConnection.Models;
|
||||
using Shared.AccessLayers;
|
||||
using WebNovelPortalAPI.DTO;
|
||||
|
||||
namespace WebNovelPortal.AccessLayers;
|
||||
|
||||
public class WebApiAccessLayer : ApiAccessLayer
|
||||
{
|
||||
public WebApiAccessLayer(string apiBaseUrl) : base(apiBaseUrl)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<Novel>?> GetNovels()
|
||||
{
|
||||
return (await SendRequest<List<Novel>>("novel", HttpMethod.Get)).ResponseObject;
|
||||
}
|
||||
|
||||
public async Task<Novel?> RequestNovelScrape(string url)
|
||||
{
|
||||
return (await SendRequest<Novel>("novel/scrapeNovel", HttpMethod.Post, null,
|
||||
new ScrapeNovelRequest {NovelUrl = url})).ResponseObject;
|
||||
}
|
||||
|
||||
public async Task<Novel?> GetNovel(string guid)
|
||||
{
|
||||
return (await SendRequest<Novel?>($"novel/{guid}", HttpMethod.Get)).ResponseObject;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,56 @@
|
||||
@page "/"
|
||||
@using DBConnection.Models
|
||||
@using WebNovelPortal.AccessLayers
|
||||
|
||||
<PageTitle>Index</PageTitle>
|
||||
<h1>Novels</h1>
|
||||
<input @bind="NovelUrl"/><button onclick="@(() => RequestNovelScrape(NovelUrl))">Scrape</button>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Author</th>
|
||||
<th>Chapter Count</th>
|
||||
</tr>
|
||||
@foreach (var novel in novels)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<a href="@($"/novel/{novel.Guid}")">@novel.Title</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="@novel.Author.Url">@novel.Author.Name</a>
|
||||
</td>
|
||||
<td>
|
||||
@novel.Chapters.Count
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
@code {
|
||||
[Inject]
|
||||
WebApiAccessLayer api { get; set; }
|
||||
string NovelUrl { get; set; }
|
||||
List<Novel> novels = new List<Novel>();
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await RefreshNovels();
|
||||
}
|
||||
}
|
||||
|
||||
async Task RequestNovelScrape(string url)
|
||||
{
|
||||
await api.RequestNovelScrape(url);
|
||||
await RefreshNovels();
|
||||
}
|
||||
|
||||
async Task RefreshNovels()
|
||||
{
|
||||
novels = await api.GetNovels();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
47
WebNovelPortal/Pages/NovelDetails.razor
Normal file
47
WebNovelPortal/Pages/NovelDetails.razor
Normal file
@@ -0,0 +1,47 @@
|
||||
@page "/novel/{NovelId}"
|
||||
@using WebNovelPortal.AccessLayers
|
||||
@using DBConnection.Models
|
||||
@if (Novel == null)
|
||||
{
|
||||
<h3>Loading...</h3>
|
||||
}
|
||||
else
|
||||
{
|
||||
<h3><a href="@Novel.Url">@(Novel.Title)</a></h3>
|
||||
<h4>Author: <a href="@Novel.Author.Url">(@Novel.Author.Name)</a></h4>
|
||||
<h4>Date Posted: @Novel.DatePosted</h4>
|
||||
<h4>Date Updated: @Novel.LastUpdated</h4>
|
||||
<h4>Tags</h4>
|
||||
<ul>
|
||||
@foreach (var tag in Novel.Tags)
|
||||
{
|
||||
<li>@tag.TagValue</li>
|
||||
}
|
||||
</ul>
|
||||
<h4>Chapters</h4>
|
||||
<ol>
|
||||
@foreach (var chapter in Novel.Chapters)
|
||||
{
|
||||
<li><a href="@chapter.Url">@chapter.Name</a></li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? NovelId { get; set; }
|
||||
[Inject]
|
||||
public WebApiAccessLayer api { get; set; }
|
||||
Novel? Novel { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
Novel = await api.GetNovel(NovelId);
|
||||
StateHasChanged();
|
||||
}
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using WebNovelPortal.AccessLayers;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddScoped(fac => new WebApiAccessLayer(builder.Configuration["WebAPIUrl"]));
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
.page {
|
||||
.page {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
.main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ main {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.top-row, article {
|
||||
.main > div {
|
||||
padding-left: 2rem !important;
|
||||
padding-right: 1.5rem !important;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Shared\Components\Layout\NavMenu.razor.css" />
|
||||
<Content Include="Shared\Layouts\MainLayout.razor.css" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DBConnection\DBConnection.csproj" />
|
||||
<ProjectReference Include="..\Shared\Shared.csproj" />
|
||||
<ProjectReference Include="..\WebNovelPortalAPI\WebNovelPortalAPI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"WebAPIUrl": "https://localhost:7137/api/"
|
||||
}
|
||||
|
||||
@@ -31,6 +31,19 @@ namespace WebNovelPortalAPI.Controllers
|
||||
return _scrapers.FirstOrDefault(i => i.MatchesUrl(novelUrl));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{guid:guid}")]
|
||||
public async Task<Novel?> GetNovel(Guid guid)
|
||||
{
|
||||
return await _novelRepository.GetNovel(guid);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<List<Novel>> GetNovels()
|
||||
{
|
||||
return (await _novelRepository.GetAllIncluded()).ToList();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("scrapeNovel")]
|
||||
public async Task<IActionResult> ScrapeNovel(ScrapeNovelRequest request)
|
||||
|
||||
17
WebNovelPortalAPI/Extensions/DBUpdateExtensions.cs
Normal file
17
WebNovelPortalAPI/Extensions/DBUpdateExtensions.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace WebNovelPortalAPI.Extensions;
|
||||
|
||||
public static class DBUpdateExtensions
|
||||
{
|
||||
public static void UpdateDatabase<T>(this IApplicationBuilder app) where T : DbContext
|
||||
{
|
||||
using var serviceScope = app.ApplicationServices.CreateScope();
|
||||
using var context = serviceScope.ServiceProvider.GetService<T>();
|
||||
|
||||
if (context.Database.GetPendingMigrations().Any())
|
||||
{
|
||||
context.Database.Migrate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public static class ScraperExtensions
|
||||
public static void AddScrapers(this IServiceCollection services)
|
||||
{
|
||||
Type[] types = Assembly.GetExecutingAssembly().GetTypes().Where(t =>
|
||||
t.IsClass && typeof(IScraper).IsAssignableFrom(t) && (t.Namespace?.Contains(nameof(Scrapers)) ?? false))
|
||||
t.IsClass && typeof(IScraper).IsAssignableFrom(t) && !t.IsAbstract && (t.Namespace?.Contains(nameof(Scrapers)) ?? false))
|
||||
.ToArray();
|
||||
foreach (var t in types)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UpdateDatabase<AppDbContext>();
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
||||
113
WebNovelPortalAPI/Scrapers/AbstractScraper.cs
Normal file
113
WebNovelPortalAPI/Scrapers/AbstractScraper.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using DBConnection.Models;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace WebNovelPortalAPI.Scrapers;
|
||||
|
||||
public abstract class AbstractScraper : IScraper
|
||||
{
|
||||
protected abstract string UrlMatchPattern { get; }
|
||||
protected abstract string BaseUrlPattern { get; }
|
||||
protected virtual string? WorkTitlePattern { get; }
|
||||
protected virtual string? AuthorNamePattern { get; }
|
||||
protected virtual string? AuthorLinkPattern { get; }
|
||||
protected virtual string? ChapterUrlPattern { get; }
|
||||
protected virtual string? ChapterNamePattern { get; }
|
||||
protected virtual string? ChapterPostedPattern { get; }
|
||||
protected virtual string? ChapterUpdatedPattern { get; }
|
||||
protected virtual string? TagPattern { get; }
|
||||
protected virtual string? DatePostedPattern { get; }
|
||||
protected virtual string? DateUpdatedPattern { get; }
|
||||
|
||||
public virtual bool MatchesUrl(string url)
|
||||
{
|
||||
var regex = new Regex(UrlMatchPattern, RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(url);
|
||||
}
|
||||
|
||||
protected virtual string GetNovelTitle(HtmlDocument document)
|
||||
{
|
||||
var xpath = WorkTitlePattern;
|
||||
return document.DocumentNode.SelectSingleNode(xpath).InnerText;
|
||||
}
|
||||
|
||||
protected virtual Author GetAuthor(HtmlDocument document, string baseUrl)
|
||||
{
|
||||
var nameXPath = AuthorNamePattern;
|
||||
var urlXPath = AuthorLinkPattern;
|
||||
var authorName = document.DocumentNode.SelectSingleNode(nameXPath).InnerText;
|
||||
var authorUrl = document.DocumentNode.SelectSingleNode(urlXPath).Attributes["href"].Value;
|
||||
Author author = new Author
|
||||
{
|
||||
Name = authorName,
|
||||
Url = $"{baseUrl + authorUrl}"
|
||||
};
|
||||
return author;
|
||||
|
||||
}
|
||||
|
||||
protected virtual List<Chapter> GetChapters(HtmlDocument document, string baseUrl)
|
||||
{
|
||||
var urlxpath = ChapterUrlPattern;
|
||||
var namexpath = ChapterNamePattern;
|
||||
var urlnodes = document.DocumentNode.SelectNodes(urlxpath);
|
||||
var chapters = urlnodes.Select((node, i) => new Chapter
|
||||
{
|
||||
ChapterNumber = i + 1,
|
||||
Url = $"{baseUrl}{node.Attributes["href"].Value}",
|
||||
Name = node.SelectSingleNode(namexpath).InnerText
|
||||
});
|
||||
|
||||
return chapters.ToList();
|
||||
}
|
||||
|
||||
protected virtual List<Tag> GetTags(HtmlDocument document)
|
||||
{
|
||||
var xpath = TagPattern;
|
||||
var nodes = document.DocumentNode.SelectNodes(xpath);
|
||||
return nodes.Select(node => new Tag
|
||||
{
|
||||
TagValue = node.InnerText
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
protected virtual DateTime GetPostedDate(HtmlDocument document)
|
||||
{
|
||||
var xpath = DatePostedPattern;
|
||||
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText);
|
||||
}
|
||||
|
||||
protected virtual DateTime GetLastUpdatedDate(HtmlDocument document)
|
||||
{
|
||||
var xpath = DateUpdatedPattern;
|
||||
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText);
|
||||
}
|
||||
|
||||
public Novel ScrapeNovel(string url)
|
||||
{
|
||||
var web = new HtmlWeb();
|
||||
var doc = web.Load(url);
|
||||
if (doc == null)
|
||||
{
|
||||
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
|
||||
{
|
||||
Author = GetAuthor(doc, baseUrl),
|
||||
Chapters = GetChapters(doc, baseUrl),
|
||||
DatePosted = GetPostedDate(doc),
|
||||
LastUpdated = GetLastUpdatedDate(doc),
|
||||
Tags = GetTags(doc),
|
||||
Title = GetNovelTitle(doc),
|
||||
Url = novelUrl
|
||||
};
|
||||
}
|
||||
|
||||
public string? ScrapeChapterContent(string chapterUrl)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -5,95 +5,29 @@ using HtmlAgilityPack;
|
||||
|
||||
namespace WebNovelPortalAPI.Scrapers;
|
||||
|
||||
public class KakuyomuScraper : IScraper
|
||||
public class KakuyomuScraper : AbstractScraper
|
||||
{
|
||||
private const string UrlPattern = @"https?:\/\/kakuyomu\.jp\/works\/\d+\/?";
|
||||
private const string BaseUrl = "https://kakuyomu.jp";
|
||||
public bool MatchesUrl(string url)
|
||||
{
|
||||
var regex = new Regex(UrlPattern, RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(url);
|
||||
}
|
||||
protected override string UrlMatchPattern => @"https?:\/\/kakuyomu\.jp\/works\/\d+\/?";
|
||||
|
||||
private string GetNovelTitle(HtmlDocument document)
|
||||
{
|
||||
var xpath = @"//*[@id='workTitle']/a";
|
||||
return document.DocumentNode.SelectSingleNode(xpath).InnerText;
|
||||
}
|
||||
protected override string BaseUrlPattern => @"https?:\/\/kakuyomu\.jp";
|
||||
|
||||
private Author GetAuthor(HtmlDocument document)
|
||||
{
|
||||
var nameXPath = @"//*[@id='workAuthor-activityName']/a";
|
||||
var urlXPath = @"//*[@id='workAuthor-activityName']/a";
|
||||
var authorName = document.DocumentNode.SelectSingleNode(nameXPath).InnerText;
|
||||
var authorUrl = document.DocumentNode.SelectSingleNode(urlXPath).Attributes["href"].Value;
|
||||
Author author = new Author
|
||||
{
|
||||
Name = authorName,
|
||||
Url = $"{BaseUrl + authorUrl}"
|
||||
};
|
||||
return author;
|
||||
protected override string? WorkTitlePattern => @"//*[@id='workTitle']/a";
|
||||
protected override string? AuthorNamePattern => @"//*[@id='workAuthor-activityName']/a";
|
||||
protected override string? AuthorLinkPattern => @"//*[@id='workAuthor-activityName']/a";
|
||||
|
||||
}
|
||||
protected override string? ChapterUrlPattern => @"//a[@class='widget-toc-episode-episodeTitle']";
|
||||
|
||||
private List<Chapter> GetChapters(HtmlDocument document)
|
||||
{
|
||||
var urlxpath = @"//a[@class='widget-toc-episode-episodeTitle']";
|
||||
var namexpath = @"span";
|
||||
var urlnodes = document.DocumentNode.SelectNodes(urlxpath);
|
||||
var chapters = urlnodes.Select((node, i) => new Chapter
|
||||
{
|
||||
ChapterNumber = i + 1,
|
||||
Url = $"{BaseUrl}{node.Attributes["href"].Value}",
|
||||
Name = node.SelectSingleNode(namexpath).InnerText
|
||||
});
|
||||
protected override string? ChapterNamePattern => @"span";
|
||||
|
||||
return chapters.ToList();
|
||||
}
|
||||
protected override string? ChapterPostedPattern => base.ChapterPostedPattern;
|
||||
|
||||
private List<Tag> GetTags(HtmlDocument document)
|
||||
{
|
||||
var xpath = @"//span[@itemprop='keywords']/a";
|
||||
var nodes = document.DocumentNode.SelectNodes(xpath);
|
||||
return nodes.Select(node => new Tag
|
||||
{
|
||||
TagValue = node.InnerText
|
||||
}).ToList();
|
||||
}
|
||||
protected override string? ChapterUpdatedPattern => base.ChapterUpdatedPattern;
|
||||
|
||||
private DateTime GetPostedDate(HtmlDocument document)
|
||||
{
|
||||
var xpath = @"//time[@itemprop='datePublished']";
|
||||
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText);
|
||||
}
|
||||
protected override string? TagPattern => @"//span[@itemprop='keywords']/a";
|
||||
|
||||
private DateTime GetLastUpdatedDate(HtmlDocument document)
|
||||
{
|
||||
var xpath = @"//time[@itemprop='dateModified']";
|
||||
return DateTime.Parse(document.DocumentNode.SelectSingleNode(xpath).InnerText);
|
||||
}
|
||||
protected override string? DatePostedPattern => @"//time[@itemprop='datePublished']";
|
||||
|
||||
public Novel ScrapeNovel(string url)
|
||||
{
|
||||
Novel novel = new Novel();
|
||||
var web = new HtmlWeb();
|
||||
var doc = web.Load(url);
|
||||
if (doc == null)
|
||||
{
|
||||
throw new Exception("Error parsing document");
|
||||
}
|
||||
|
||||
return new Novel
|
||||
{
|
||||
Author = GetAuthor(doc),
|
||||
Chapters = GetChapters(doc),
|
||||
DatePosted = GetPostedDate(doc),
|
||||
LastUpdated = GetLastUpdatedDate(doc),
|
||||
Tags = GetTags(doc),
|
||||
Title = GetNovelTitle(doc),
|
||||
Url = url
|
||||
};
|
||||
}
|
||||
protected override string? DateUpdatedPattern => @"//time[@itemprop='dateModified']";
|
||||
|
||||
public string? ScrapeChapterContent(string chapterUrl)
|
||||
{
|
||||
|
||||
28
WebNovelPortalAPI/Scrapers/SyosetuScraper.cs
Normal file
28
WebNovelPortalAPI/Scrapers/SyosetuScraper.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace WebNovelPortalAPI.Scrapers;
|
||||
|
||||
public class SyosetuScraper : AbstractScraper
|
||||
{
|
||||
protected override string UrlMatchPattern => @"https?:\/\/\w+\.syosetu\.com\/\w+\/?";
|
||||
|
||||
protected override string BaseUrlPattern => @"https?:\/\/\w+\.syosetu\.com\/?";
|
||||
|
||||
protected override string? WorkTitlePattern => @"//p[@class='novel_title']";
|
||||
|
||||
protected override string? AuthorNamePattern => @"//div[@class='novel_writername']/a | //div[@class='novel_writername']";
|
||||
|
||||
protected override string? AuthorLinkPattern => @"//div[@class='novel_writername']/a";
|
||||
|
||||
protected override string? ChapterUrlPattern => @"//dl[@class='novel_sublist2']//a";
|
||||
|
||||
protected override string? ChapterNamePattern => @"//dl[@class='novel_sublist2']//a";
|
||||
|
||||
protected override string? ChapterPostedPattern => base.ChapterPostedPattern;
|
||||
|
||||
protected override string? ChapterUpdatedPattern => base.ChapterUpdatedPattern;
|
||||
|
||||
protected override string? TagPattern => base.TagPattern;
|
||||
|
||||
protected override string? DatePostedPattern => base.DatePostedPattern;
|
||||
|
||||
protected override string? DateUpdatedPattern => base.DateUpdatedPattern;
|
||||
}
|
||||
Reference in New Issue
Block a user