Commit b2ca9e40 authored by JoyJ's avatar JoyJ

添加项目文件。

parents
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
\ No newline at end of file
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixivNovelServer", "PixivNovelServer\PixivNovelServer.csproj", "{68CDE663-EB8C-496A-A062-88B1247F54F5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68CDE663-EB8C-496A-A062-88B1247F54F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68CDE663-EB8C-496A-A062-88B1247F54F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68CDE663-EB8C-496A-A062-88B1247F54F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68CDE663-EB8C-496A-A062-88B1247F54F5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.0",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="PixivNovelServer.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>
</html>
@inherits LayoutComponentBase
<div class="page" style="max-height:100vh; max-width:100vw;">
<div>
<NavMenu />
</div>
<div style="overflow:scroll; width:100%" id="scroll_to_top_find">
@Body
<MudScrollToTop Selector="#scroll_to_top_find">
<MudFab Color="Color.Primary" StartIcon="@Icons.Material.Filled.ArrowCircleUp" />
</MudScrollToTop>
</div>
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<MudThemeProvider />
<MudPopoverProvider />
<MudDialogProvider />
<MudSnackbarProvider />
\ No newline at end of file
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
<div style="position:sticky; top:0; min-width:150px;">
<MudNavMenu Color="Color.Primary" Rounded="true">
<MudNavLink Href="" Icon="@Icons.Material.Filled.Info" Match="NavLinkMatch.All">简介</MudNavLink>
<MudNavLink Href="search" Icon="@Icons.Material.Filled.Search">搜索</MudNavLink>
<MudNavLink Href="novel" Icon="@Icons.Material.Filled.MenuBook" ForceLoad="true">阅读</MudNavLink>
</MudNavMenu>
</div>
.navbar-toggler {
appearance: none;
cursor: pointer;
width: 3.5rem;
height: 2.5rem;
color: white;
position: absolute;
top: 0.5rem;
right: 1rem;
border: 1px solid rgba(255, 255, 255, 0.1);
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
}
.navbar-toggler:checked {
background-color: rgba(255, 255, 255, 0.5);
}
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}
.navbar-brand {
font-size: 1.1rem;
}
.bi {
display: inline-block;
position: relative;
width: 1.25rem;
height: 1.25rem;
margin-right: 0.75rem;
top: -1px;
background-size: cover;
}
.bi-house-door-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
}
.bi-plus-square-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
}
.bi-list-nested-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item ::deep .nav-link {
color: #d7d7d7;
background: none;
border: none;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
width: 100%;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
}
.nav-item ::deep .nav-link:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.nav-scrollable {
display: none;
}
.navbar-toggler:checked ~ .nav-scrollable {
display: block;
}
@media (min-width: 641px) {
.navbar-toggler {
display: none;
}
.nav-scrollable {
/* Never collapse the sidebar for wide screens */
display: block;
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
overflow-y: auto;
}
}
@page "/Error"
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}
@page "/"
<PageTitle>简介</PageTitle>
<h1>系统简介</h1>
<MudText Style="white-space:pre-line">
资源来自PTT<MudLink Href="https://www.pttime.org/details.php?id=64258&hit=1">(点这里前往原址)</MudLink>,
由JoyJ@KamePT花两小时随便摸了个界面做了整合。
毕竟只有16W的体量,所以直接拼的sql字符串——姑且做了简单反注入。
P站的小说几乎都是分章节发布,想连续看的话请按作者检索。
【原文地址】键点进去404是正常的——没人能保证原文现在还活在P站上……
直接点左边的【阅读】则为随机选一篇小说阅读。
类似[uploadedimage:XXXXX]的东西是插图,有梯子的话就尝试着点进原文去看吧。
</MudText>
@inject IJSRuntime jsRuntime
@page "/novel/{id?}"
<PageTitle>@pageTitle</PageTitle>
<MudPaper>
<h1>
@title
</h1>
<p>
<MudButton Target="_blank" Variant="Variant.Outlined" Href="@($"search/u/{user}")">@($"{user} 著")</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Outlined" OnClick="()=>{show_desc = !show_desc;}">@(description == "" ? "无简介" : (show_desc ? "隐藏" : "显示")+"简介")</MudButton>
<MudButton Target="_blank"
Href="@url" Color="Color.Primary" Variant="Variant.Outlined">
原文地址
</MudButton>
<MudPaper Style="@(show_desc ? "" : "display:none;" + "position:relative;")">
<MudText>@description</MudText>
</MudPaper>
</p>
<p>
@foreach (var tag in tagList)
{
if (tag == "")
{
continue;
}
<MudButton Target="_blank" Color="Color.Primary" Variant="Variant.Outlined" Href="@($"search/t/{tag}")">@($"#{tag}")</MudButton>
}
</p>
</MudPaper>
<MudPaper Style="white-space: pre-line;">
<MudText>
@novel
</MudText>
</MudPaper>
@code {
bool show_desc { get; set; } = false;
void ChangeShowDesc()
{
show_desc = !show_desc;
}
[Parameter]
public string? Id { get; set; }
int showId = 0;
string title = "";
List<string> tagList = new();
string user = "";
string novel = "";
string url = "";
string description = "";
string showingId = "";
string pageTitle {
get{
if (title != "")
{
return $"阅读 - {title} ({user} 著)";
}
return "正在跳转到随机文章……";
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (Id == null)
{
var maxReader = GetReader("SELECT COUNT(id) FROM novels");
maxReader?.Read();
if (maxReader == null || !maxReader.HasRows)
{
maxReader?.Close();
return;
}
int max = Convert.ToInt32(maxReader.GetValue(0));
maxReader?.Close();
Id = Random.Shared.Next(1, max).ToString();
await jsRuntime.InvokeVoidAsync("eval", $"window.location.href='novel/{Id}'");
return;
}
if (!firstRender)
{
if (showingId == Id)
{
return;
}
}
int.TryParse(Id.ToString(), out showId);
var reader = GetReader("SELECT title,tags,user,novel,description,url FROM novels WHERE id=@p1", showId);
if (reader == null)
{
return;
}
if (!await reader.ReadAsync())
{
return;
}
#if DEBUG
Console.WriteLine($"Loading novel {Id}");
#endif
title = reader.GetValue(0)?.ToString() ?? "";
string tags = reader.GetValue(1)?.ToString() ?? "";
user = reader.GetValue(2)?.ToString() ?? "";
novel = reader.GetValue(3)?.ToString() ?? "";
description = reader.GetValue(4)?.ToString() ?? "";
url = reader.GetValue(5)?.ToString() ?? "";
tags = tags.Replace("[", "").Replace("]", " ");
tagList.AddRange(tags.Split(' '));
reader?.Close();
showingId = Id;
await Task.Delay(1);
StateHasChanged();
await base.OnAfterRenderAsync(firstRender);
}
}
@page "/search"
@page "/search/u/{puser?}"
@page "/search/t/{ptag?}"
@page "/search/{ptitle?}"
<PageTitle>搜索</PageTitle>
<h1>文章搜索</h1>
<MudTextField Style="width:100%" T="string" @ref=searchTitle Placeholder="按标题检索(以空格分隔)"></MudTextField>
<MudSwitch Color="Color.Primary" @bind-Value="useANDAtTitle">要求包含全部关键词</MudSwitch>
<MudTextField Style="width:100%" T="string" @ref=searchUser Placeholder="按作者检索(精确匹配)"></MudTextField>
<MudTextField Style="width:100%" T="string" @ref=searchTag Placeholder="按Tag检索(以空格分隔)"></MudTextField>
<MudSwitch Color="Color.Primary" @bind-Value="useANDAtTag">要求包含全部关键词</MudSwitch>
<MudButton OnClick="SearchNow" Variant="Variant.Filled" Color="Color.Primary">搜索</MudButton>
@if (results.Count > 0)
{
<MudDivider></MudDivider>
@foreach (var res in showingResult)
{
<p>
<MudButton Variant="Variant.Outlined" Target="_blank" Href="@($"novel/{res.Id}")">@($"{res.Title}")</MudButton>
<MudButton Variant="Variant.Outlined" Target="_blank" Href="@($"search/u/{res.User}")">@($"【{res.User} 著】")</MudButton>
</p>
}
<MudDivider></MudDivider>
<MudPagination Color="Color.Primary" Count="@allPages" @bind-Selected="currentPage"></MudPagination>
}
<MudOverlay Visible="loading" DarkBackground="true">
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
</MudOverlay>
@code {
bool useANDAtTitle = true;
bool useANDAtTag = true;
bool loading = false;
MudTextField<string> searchTitle { get; set; }
MudTextField<string> searchUser { get; set; }
MudTextField<string> searchTag { get; set; }
private async void SearchNow()
{
loading = true;
StateHasChanged();
await Task.Delay(1);
currentPage = 1;
results.Clear();
List<object> parameters = new();
int i = 1;
string titleSearch = "";
string userSearch = "";
string tagSearch = "";
if (!string.IsNullOrEmpty(searchTitle?.Text))
{
if (useANDAtTitle)
{
titleSearch = "1=1";
foreach (var s in searchTitle.Text.Split(' '))
{
titleSearch += $" AND title LIKE @p{i}";
parameters.Add($"%{s}%");
i++;
}
}
else
{
titleSearch = "1=2";
foreach (var s in searchTitle.Text.Split(' '))
{
titleSearch += $" OR title LIKE @p{i}";
parameters.Add($"%{s}%");
i++;
}
}
}
else
{
titleSearch = "1=1";
}
if (!string.IsNullOrEmpty(searchUser?.Text))
{
userSearch += $"user=@p{i}";
parameters.Add(searchUser.Text);
i++;
}
else
{
userSearch = "1=1";
}
if (!string.IsNullOrEmpty(searchTag?.Text))
{
if (useANDAtTag)
{
tagSearch = "1=1";
foreach (var s in searchTag.Text.Split(' '))
{
tagSearch += $" AND tags LIKE @p{i}";
parameters.Add($"%{s}%");
i++;
}
}
else
{
tagSearch = "1=2";
foreach (var s in searchTag.Text.Split(' '))
{
tagSearch += $" OR title LIKE @p{i}";
parameters.Add($"%{s}%");
i++;
}
}
}
else
{
tagSearch = "1=1";
}
string sql = $@"SELECT id,title,user FROM novels WHERE (
{titleSearch}) AND ({tagSearch}) AND ({userSearch}) LIMIT 10000";
#if DEBUG
Console.WriteLine($"Searching with {sql}");
#endif
var reader = GetReader(sql, parameters.ToArray());
if (reader == null)
{
return;
}
while(reader.Read())
{
results.Add(new((long)reader.GetValue(0), (string)reader.GetValue(1), (string)reader.GetValue(2)));
}
await reader.CloseAsync();
loading = false;
currentPage = 0;
await Task.Delay(1);
currentPage = 1;
StateHasChanged();
}
List<NovelResult> results = new();
int currentPage = 1;
int allPages { get{
int page = results.Count / PER_PAGE;
if (results.Count % PER_PAGE > 0)
{
page++;
}
return page;
} }
IEnumerable<NovelResult> showingResult {get{
int start = ((currentPage - 1) * PER_PAGE);
int end = Math.Min(start + PER_PAGE, results.Count);
if (start > end || start < 0 || end <= 0 || start >= results.Count || end > results.Count)
{
return [];
}
return results[start .. end];
}}
[Parameter]
public string? pUser { get; set; }
[Parameter]
public string? pTag { get; set; }
[Parameter]
public string? pTitle { get; set; }
protected override Task OnAfterRenderAsync(bool firstRender)
{
bool shouldSearch = false;
if (firstRender)
{
if (pUser != null)
{
searchUser.SetText(pUser);
shouldSearch = true;
}
if (pTag != null)
{
searchTag.SetText(pTag);
shouldSearch = true;
}
if (pTitle != null)
{
searchTag.SetText(pTitle);
shouldSearch = true;
}
if(shouldSearch)
{
SearchNow();
}
}
return base.OnAfterRenderAsync(firstRender);
}
int PER_PAGE = 10;
class NovelResult
{
public long Id;
public string Title;
public string User;
public NovelResult(long id, string title, string user)
{
Id = id;
Title = title;
User = user;
}
}
}
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using PixivNovelServer
@using PixivNovelServer.Components
@using MudBlazor
@using static SqliteService
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" />
<PackageReference Include="MudBlazor" Version="7.15.0" />
</ItemGroup>
</Project>
using MudBlazor.Services;
using PixivNovelServer.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddMudServices();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// 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.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:7313",
"sslPort": 44350
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"externalUrlConfiguration": true,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7052;http://localhost:5116",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
using Microsoft.Data.Sqlite;
namespace PixivNovelServer
{
public static class SqliteService
{
public static string Server = "novel.db";
public static bool Inited = false;
public static string LastError = "";
static SqliteTransaction? clientTransaction = null;
static SqliteConnection? client = null;
static public void ChangeDatabase(string database)
{
if (client == null)
{
Inited = true;
client = GetConnection();
}
client!.ChangeDatabase(database);
}
static public SqliteTransaction BeginTransaction()
{
client = GetConnection();
var conn = clientTransaction?.Connection;
try
{
clientTransaction?.Dispose();
conn?.Dispose();
}
catch { }
clientTransaction = client.BeginTransaction();
return clientTransaction;
}
static public void Setting(string server, int port, string user, string password, string database)
{
Server = server;
client = GetConnection();
Inited = true;
}
static public SqliteConnection GetConnection()
{
var c = new SqliteConnection($"Data Source={Server};");
c.Open();
return c;
}
public static void Execute(string cmd, params object[] args)
{
try
{
using SqliteConnection conn = GetConnection();
using SqliteCommand command = new(cmd, conn);
foreach (var par in args)
{
SqliteParameter p = new()
{
Value = par
};
command.Parameters.Add(p);
}
command.ExecuteNonQuery();
}
catch (Exception ex)
{
LastError = ex.ToString();
}
}
public static async Task<int> ExecuteAsync(string cmd, params object[] args)
{
try
{
using SqliteConnection conn = GetConnection();
using SqliteCommand command = new(cmd, conn);
foreach (var par in args)
{
SqliteParameter p = new()
{
Value = par
};
command.Parameters.Add(p);
}
return await command.ExecuteNonQueryAsync();
}
catch (Exception ex)
{
LastError = ex.ToString();
}
return 0;
}
public static void ExecuteTrans(string cmd, SqliteTransaction trans, params object[] args)
{
try
{
using SqliteCommand command = new(cmd, trans.Connection, trans);
foreach (var par in args)
{
SqliteParameter p = new()
{
Value = par
};
command.Parameters.Add(p);
}
command.ExecuteNonQuery();
}
catch (Exception ex)
{
LastError = ex.ToString();
}
}
public async static Task<bool> ExecuteTransAsync(string cmd, SqliteTransaction trans, params object[] args)
{
try
{
using SqliteCommand command = new(cmd, trans.Connection, trans);
int i = 1;
foreach (var par in args)
{
SqliteParameter p = new()
{
Value = par
};
command.Parameters.AddWithValue($"@p{i}", par);
i++;
}
await command.ExecuteNonQueryAsync();
}
catch (Exception ex)
{
LastError = ex.ToString();
return false;
}
return true;
}
public static async void DisposeReader(SqliteDataReader? reader)
{
if (reader == null)
{
return;
}
await reader.DisposeAsync();
if (readerDic.ContainsKey(reader))
{
var conn = readerDic[reader];
await reader.DisposeAsync();
await conn.DisposeAsync();
}
}
static Dictionary<SqliteDataReader, SqliteConnection> readerDic = new();
public static SqliteDataReader? GetReader(string sqlCommand, params object[] pars)
{
try
{
SqliteConnection conn = GetConnection();
SqliteCommand command = new(sqlCommand, conn);
int index = 1;
if (pars.Length > 0)
{
command.Parameters.Clear();
foreach (var par in pars)
{
command.Parameters.AddWithValue($"@p{index}",par);
index++;
}
}
var reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
readerDic[reader] = conn;
return reader;
}
catch (Exception ex)
{
LastError = ex.ToString();
}
return null;
}
public static object? GetValue(string sqlCommand, params object[] pars)
{
try
{
using SqliteConnection conn = GetConnection();
using SqliteCommand command = new(sqlCommand, conn);
if (pars.Length > 0)
{
command.Parameters.Clear();
foreach (var par in pars)
{
command.Parameters.Add(new SqliteParameter() { Value = par });
}
}
var reader = command.ExecuteReader();
if (!reader.Read())
{
return null;
}
var result = reader.GetValue(0);
reader.Dispose();
command.Dispose();
conn.Dispose();
return result;
}
catch (Exception ex)
{
LastError = ex.ToString();
}
return null;
}
public static async Task<object?> GetValueAsync(string sqlCommand, params object[] pars)
{
try
{
using SqliteConnection conn = GetConnection();
using SqliteCommand command = new(sqlCommand, conn);
if (pars.Length > 0)
{
command.Parameters.Clear();
foreach (var par in pars)
{
command.Parameters.Add(new SqliteParameter() { Value = par });
}
}
var reader = await command.ExecuteReaderAsync();
if (!await reader.ReadAsync())
{
return null;
}
var result = reader.GetValue(0);
await reader.DisposeAsync();
await command.DisposeAsync();
await conn.DisposeAsync();
return result;
}
catch (Exception ex)
{
LastError = ex.ToString();
}
return null;
}
static public SqliteDataReader? GetTransReader(string sqlCommand, SqliteTransaction trans, params object[] pars)
{
try
{
using SqliteCommand command = new(sqlCommand, trans.Connection, trans);
if (pars.Length > 0)
{
command.Parameters.Clear();
foreach (var par in pars)
{
command.Parameters.Add(new SqliteParameter() { Value = par });
}
}
return command.ExecuteReader();
}
catch (Exception ex)
{
LastError = ex.ToString();
}
return null;
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5000"
}
}
},
"DetailedErrors": true
}
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
a, .btn-link {
color: #006bb7;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}
.content {
padding-top: 1.1rem;
}
h1:focus {
outline: none;
}
.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}
.invalid {
outline: 1px solid #e50000;
}
.validation-message {
color: #e50000;
}
.blazor-error-boundary {
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
padding: 1rem 1rem 1rem 3.7rem;
color: white;
}
.blazor-error-boundary::after {
content: "An error has occurred."
}
.darker-border-checkbox.form-check-input {
border-color: #929292;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment