[FA-5] Adds image support with proper S3 upload and replacement after upload
This commit is contained in:
36
AGENTS.md
Normal file
36
AGENTS.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Repository Guidelines
|
||||||
|
|
||||||
|
## Project Structure & Module Organization
|
||||||
|
- `FictionArchive.sln` ties together the gateway and all subgraph services.
|
||||||
|
- `FictionArchive.API`: Fusion gateway host; GraphQL endpoint at `/graphql`, health at `/healthz`, gateway configuration in `gateway.fgp`, and helper script `build_gateway.py`.
|
||||||
|
- `FictionArchive.Service.*`: GraphQL subgraphs (`AuthenticationService`, `FileService`, `NovelService`, `SchedulerService`, `TranslationService`, `UserService`) plus shared helpers in `FictionArchive.Service.Shared`.
|
||||||
|
- `FictionArchive.Common`: shared enums and hosting extensions used across services.
|
||||||
|
- Environment/config files live beside each service (`appsettings*.json`, `Properties/launchSettings.json`); build outputs under `bin/` and `obj/` should stay untracked.
|
||||||
|
|
||||||
|
## Build, Test, and Development Commands
|
||||||
|
- `dotnet restore` then `dotnet build FictionArchive.sln` (Debug by default) to validate all projects compile.
|
||||||
|
- Run the gateway: `dotnet run --project FictionArchive.API` (serves HTTPS; ensure certificates are trusted locally).
|
||||||
|
- Run a subgraph locally: `dotnet run --project FictionArchive.Service.NovelService` (or any other service) to debug a single domain.
|
||||||
|
- Rebuild the Fusion gateway config after subgraph changes: `python FictionArchive.API/build_gateway.py` (requires Python 3 and the `fusion` CLI on PATH; uses `gateway_skip.txt` to omit services).
|
||||||
|
- If tests are added, prefer `dotnet test FictionArchive.sln` to cover the whole solution.
|
||||||
|
|
||||||
|
## Coding Style & Naming Conventions
|
||||||
|
- Target .NET 8/C# 12; use 4-space indentation and file-scoped namespaces where practical.
|
||||||
|
- PascalCase for classes, records, interfaces, and public members; camelCase for locals/parameters; suffix async methods with `Async`.
|
||||||
|
- Favor dependency injection and extension methods for service wiring (see `Program.cs` files and `FictionArchive.Service.Shared/Extensions`).
|
||||||
|
- Keep GraphQL schema files and other generated artifacts out of commits unless intentionally versioned.
|
||||||
|
|
||||||
|
## Testing Guidelines
|
||||||
|
- No dedicated test projects exist yet; when adding tests, create `*.Tests` projects aligned to each service (e.g., `FictionArchive.Service.NovelService.Tests`) and name test files `*Tests.cs`.
|
||||||
|
- Prefer xUnit with fluent assertions; aim for coverage on controllers/resolvers, integration events, and critical extension methods.
|
||||||
|
- Use in-memory fakes or test containers for external dependencies to keep tests deterministic.
|
||||||
|
|
||||||
|
## Commit & Pull Request Guidelines
|
||||||
|
- Follow the observed pattern: `[FA-123] Short, imperative summary` (reference the tracker ID and keep scope focused).
|
||||||
|
- Keep commits small and self-contained; include relevant config/schema updates produced by the gateway build script when behavior changes.
|
||||||
|
- PRs should describe the problem, the solution, and any follow-up work; link to issues, attach GraphQL schema diffs or sample queries when applicable, and note any manual steps (migrations, secrets).
|
||||||
|
|
||||||
|
## Security & Configuration Tips
|
||||||
|
- Do not commit secrets; use user secrets or environment variables for API keys and connection strings referenced in `appsettings*.json`.
|
||||||
|
- Verify HTTPS is enabled locally; adjust `launchSettings.json` only when necessary and document non-default ports.
|
||||||
|
- Regenerate `gateway.fgp` after changing subgraph schemas to avoid stale compositions.
|
||||||
@@ -21,6 +21,11 @@
|
|||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- Builds the Fusion graph file before building the application itself -->
|
||||||
|
<Target Name="RunFusionBuild" BeforeTargets="BeforeBuild">
|
||||||
|
<Exec Command="python build_gateway.py" WorkingDirectory="$(ProjectDir)" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="..\.dockerignore">
|
<Content Include="..\.dockerignore">
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Export GraphQL schemas, pack subgraphs and compose the gateway (PowerShell).
|
|
||||||
.DESCRIPTION
|
|
||||||
- Searches for FictionArchive.Service.* folders one directory above this script.
|
|
||||||
- Reads skip-projects.txt next to the script.
|
|
||||||
- Builds each service (Release).
|
|
||||||
- Runs `dotnet run --no-build --no-launch-profile -- schema export` in each service to avoid running the web host.
|
|
||||||
- Packs subgraphs.
|
|
||||||
- Composes the gateway from FictionArchive.API.
|
|
||||||
#>
|
|
||||||
|
|
||||||
[CmdletBinding()]
|
|
||||||
param()
|
|
||||||
|
|
||||||
function Write-ErrExit {
|
|
||||||
param($Message, $Code = 1)
|
|
||||||
Write-Error $Message
|
|
||||||
exit $Code
|
|
||||||
}
|
|
||||||
|
|
||||||
# Resolve directories
|
|
||||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
||||||
$ServicesDir = Resolve-Path -Path (Join-Path $ScriptDir '..') -ErrorAction Stop
|
|
||||||
$ApiDir = Join-Path $ServicesDir 'FictionArchive.API'
|
|
||||||
|
|
||||||
Write-Host "Script dir: $ScriptDir"
|
|
||||||
Write-Host "Services dir: $ServicesDir"
|
|
||||||
|
|
||||||
# Load skip list
|
|
||||||
$SkipFile = Join-Path $ScriptDir 'gateway_skip.txt'
|
|
||||||
$SkipList = @()
|
|
||||||
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
Write-Host " Loading skip list..."
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
|
|
||||||
if (Test-Path $SkipFile) {
|
|
||||||
$SkipList = Get-Content $SkipFile |
|
|
||||||
ForEach-Object { $_.Trim() } |
|
|
||||||
Where-Object { $_ -and -not $_.StartsWith('#') }
|
|
||||||
|
|
||||||
Write-Host "Skipping: $($SkipList -join ', ')"
|
|
||||||
} else {
|
|
||||||
Write-Warning "skip-projects.txt not found — no services will be skipped."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find service directories
|
|
||||||
Write-Host
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
Write-Host " Finding GraphQL services..."
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
|
|
||||||
$servicePattern = 'FictionArchive.Service.*'
|
|
||||||
$serviceDirs = Get-ChildItem -Path $ServicesDir -Directory -Filter 'FictionArchive.Service.*'
|
|
||||||
|
|
||||||
if (-not $serviceDirs) {
|
|
||||||
Write-ErrExit "No service folders found matching FictionArchive.Service.* under $ServicesDir"
|
|
||||||
}
|
|
||||||
|
|
||||||
$selectedServices = @()
|
|
||||||
|
|
||||||
foreach ($d in $serviceDirs) {
|
|
||||||
if ($SkipList -contains $d.Name) {
|
|
||||||
Write-Host "Skipping: $($d.Name)"
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Found: $($d.Name)"
|
|
||||||
$selectedServices += $d.FullName
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not $selectedServices) {
|
|
||||||
Write-ErrExit "All services skipped — nothing to do."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Export schemas and pack subgraphs
|
|
||||||
Write-Host
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
Write-Host " Exporting schemas & packing subgraphs..."
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
|
|
||||||
foreach ($svcPath in $selectedServices) {
|
|
||||||
$svcName = Split-Path -Leaf $svcPath
|
|
||||||
Write-Host "`nProcessing: $svcName"
|
|
||||||
|
|
||||||
Push-Location $svcPath
|
|
||||||
try {
|
|
||||||
# Build Release
|
|
||||||
Write-Host "Building $svcName..."
|
|
||||||
dotnet build -c Release
|
|
||||||
if ($LASTEXITCODE -ne 0) { Write-ErrExit "dotnet build failed for $svcName" }
|
|
||||||
|
|
||||||
# Schema export using dotnet run (no server)
|
|
||||||
Write-Host "Running schema export..."
|
|
||||||
dotnet run --no-build --no-launch-profile -- schema export --output schema.graphql
|
|
||||||
if ($LASTEXITCODE -ne 0) { Write-ErrExit "Schema export failed for $svcName" }
|
|
||||||
|
|
||||||
# Pack subgraph
|
|
||||||
Write-Host "Running fusion subgraph pack..."
|
|
||||||
fusion subgraph pack
|
|
||||||
if ($LASTEXITCODE -ne 0) { Write-ErrExit "fusion subgraph pack failed for $svcName" }
|
|
||||||
|
|
||||||
Write-Host "Completed: $svcName"
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
Pop-Location
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Compose gateway
|
|
||||||
Write-Host
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
Write-Host " Running fusion compose..."
|
|
||||||
Write-Host "----------------------------------------"
|
|
||||||
|
|
||||||
if (-not (Test-Path $ApiDir)) {
|
|
||||||
Write-ErrExit "API directory not found: $ApiDir"
|
|
||||||
}
|
|
||||||
|
|
||||||
Push-Location $ApiDir
|
|
||||||
try {
|
|
||||||
if (Test-Path "gateway.fgp") { Remove-Item "gateway.fgp" -Force }
|
|
||||||
|
|
||||||
foreach ($svcPath in $selectedServices) {
|
|
||||||
$svcName = Split-Path -Leaf $svcPath
|
|
||||||
Write-Host "Composing: $svcName"
|
|
||||||
fusion compose -p gateway.fgp -s ("..\" + $svcName)
|
|
||||||
if ($LASTEXITCODE -ne 0) { Write-ErrExit "fusion compose failed for $svcName" }
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "`nFusion build complete!"
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
Pop-Location
|
|
||||||
}
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
129
FictionArchive.API/build_gateway.py
Normal file
129
FictionArchive.API/build_gateway.py
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
|
# Helpers
|
||||||
|
# ----------------------------------------
|
||||||
|
|
||||||
|
def run(cmd, cwd=None):
|
||||||
|
"""Run a command and exit on failure."""
|
||||||
|
print(f"> {' '.join(cmd)}")
|
||||||
|
result = subprocess.run(cmd, cwd=cwd)
|
||||||
|
if result.returncode != 0:
|
||||||
|
print(f"ERROR: command failed in {cwd or os.getcwd()}")
|
||||||
|
sys.exit(result.returncode)
|
||||||
|
|
||||||
|
|
||||||
|
def load_skip_list(skip_file: Path):
|
||||||
|
if not skip_file.exists():
|
||||||
|
print(f"WARNING: skip-projects.txt not found at {skip_file}")
|
||||||
|
return set()
|
||||||
|
|
||||||
|
lines = skip_file.read_text().splitlines()
|
||||||
|
skip = {line.strip() for line in lines
|
||||||
|
if line.strip() and not line.strip().startswith("#")}
|
||||||
|
print("Skip list:", ", ".join(skip) if skip else "(none)")
|
||||||
|
return skip
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
|
# Setup paths
|
||||||
|
# ----------------------------------------
|
||||||
|
|
||||||
|
script_dir = Path(__file__).parent.resolve()
|
||||||
|
services_dir = (script_dir / "..").resolve()
|
||||||
|
api_dir = services_dir / "FictionArchive.API"
|
||||||
|
|
||||||
|
print(f"Script dir: {script_dir}")
|
||||||
|
print(f"Services dir: {services_dir}")
|
||||||
|
|
||||||
|
skip_file = script_dir / "gateway_skip.txt"
|
||||||
|
skip_list = load_skip_list(skip_file)
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
|
# Find services
|
||||||
|
# ----------------------------------------
|
||||||
|
|
||||||
|
print("\n----------------------------------------")
|
||||||
|
print(" Finding GraphQL services...")
|
||||||
|
print("----------------------------------------")
|
||||||
|
|
||||||
|
service_dirs = [
|
||||||
|
d for d in services_dir.glob("FictionArchive.Service.*")
|
||||||
|
if d.is_dir()
|
||||||
|
]
|
||||||
|
|
||||||
|
selected_services = []
|
||||||
|
|
||||||
|
for d in service_dirs:
|
||||||
|
name = d.name
|
||||||
|
if name in skip_list:
|
||||||
|
print(f"Skipping: {name}")
|
||||||
|
else:
|
||||||
|
print(f"Found: {name}")
|
||||||
|
selected_services.append(d)
|
||||||
|
|
||||||
|
if not selected_services:
|
||||||
|
print("No services to process. Exiting.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
|
# Export + pack
|
||||||
|
# ----------------------------------------
|
||||||
|
|
||||||
|
print("\n----------------------------------------")
|
||||||
|
print(" Exporting schemas & packing subgraphs...")
|
||||||
|
print("----------------------------------------")
|
||||||
|
|
||||||
|
for svc in selected_services:
|
||||||
|
name = svc.name
|
||||||
|
print(f"\nProcessing {name}")
|
||||||
|
|
||||||
|
# Build once
|
||||||
|
run(["dotnet", "build", "-c", "Release"], cwd=svc)
|
||||||
|
|
||||||
|
# Export schema
|
||||||
|
run([
|
||||||
|
"dotnet", "run",
|
||||||
|
"--no-build",
|
||||||
|
"--no-launch-profile",
|
||||||
|
"--",
|
||||||
|
"schema", "export",
|
||||||
|
"--output", "schema.graphql"
|
||||||
|
], cwd=svc)
|
||||||
|
|
||||||
|
# Pack subgraph
|
||||||
|
run(["fusion", "subgraph", "pack"], cwd=svc)
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
|
# Compose gateway
|
||||||
|
# ----------------------------------------
|
||||||
|
|
||||||
|
print("\n----------------------------------------")
|
||||||
|
print(" Running fusion compose...")
|
||||||
|
print("----------------------------------------")
|
||||||
|
|
||||||
|
if not api_dir.exists():
|
||||||
|
print(f"ERROR: FictionArchive.API not found at {api_dir}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
gateway_file = api_dir / "gateway.fgp"
|
||||||
|
if gateway_file.exists():
|
||||||
|
gateway_file.unlink()
|
||||||
|
|
||||||
|
for svc in selected_services:
|
||||||
|
name = svc.name
|
||||||
|
print(f"Composing: {name}")
|
||||||
|
|
||||||
|
run([
|
||||||
|
"fusion", "compose",
|
||||||
|
"-p", "gateway.fgp",
|
||||||
|
"-s", f"..{os.sep}{name}"
|
||||||
|
], cwd=api_dir)
|
||||||
|
|
||||||
|
print("\n----------------------------------------")
|
||||||
|
print(" Fusion build complete!")
|
||||||
|
print("----------------------------------------")
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
###############################################
|
|
||||||
# Resolve important directories
|
|
||||||
###############################################
|
|
||||||
|
|
||||||
# Directory where this script lives
|
|
||||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
|
|
||||||
# Services live one directory above the script's directory
|
|
||||||
SERVICES_DIR="$(cd "$ROOT/.." && pwd)"
|
|
||||||
|
|
||||||
###############################################
|
|
||||||
# Skip list (folder names, match exactly)
|
|
||||||
###############################################
|
|
||||||
SKIP_FILE="$ROOT/gateway_skip.txt"
|
|
||||||
SKIP_PROJECTS=()
|
|
||||||
|
|
||||||
if [[ -f "$SKIP_FILE" ]]; then
|
|
||||||
# Read non-empty lines ignoring comments
|
|
||||||
while IFS= read -r line; do
|
|
||||||
[[ -z "$line" || "$line" =~ ^# ]] && continue
|
|
||||||
SKIP_PROJECTS+=("$line")
|
|
||||||
done < "$SKIP_FILE"
|
|
||||||
else
|
|
||||||
echo "WARNING: skip-projects.txt not found — no projects will be skipped."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "----------------------------------------"
|
|
||||||
echo " Finding GraphQL services..."
|
|
||||||
echo "----------------------------------------"
|
|
||||||
|
|
||||||
SERVICE_LIST=()
|
|
||||||
|
|
||||||
# Convert skip projects into a single searchable string
|
|
||||||
SKIP_STRING=" ${SKIP_PROJECTS[*]} "
|
|
||||||
|
|
||||||
# Find service directories
|
|
||||||
shopt -s nullglob
|
|
||||||
for FOLDER in "$SERVICES_DIR"/FictionArchive.Service.*; do
|
|
||||||
[ -d "$FOLDER" ] || continue
|
|
||||||
|
|
||||||
PROJECT_NAME="$(basename "$FOLDER")"
|
|
||||||
|
|
||||||
# Skip entries that match the skip list
|
|
||||||
if [[ "$SKIP_STRING" == *" $PROJECT_NAME "* ]]; then
|
|
||||||
echo "Skipping service: $PROJECT_NAME"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Found service: $PROJECT_NAME"
|
|
||||||
SERVICE_LIST+=("$FOLDER")
|
|
||||||
done
|
|
||||||
shopt -u nullglob
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "----------------------------------------"
|
|
||||||
echo " Exporting schemas and packing subgraphs..."
|
|
||||||
echo "----------------------------------------"
|
|
||||||
|
|
||||||
for SERVICE in "${SERVICE_LIST[@]}"; do
|
|
||||||
PROJECT_NAME="$(basename "$SERVICE")"
|
|
||||||
|
|
||||||
echo "Processing service: $PROJECT_NAME"
|
|
||||||
pushd "$SERVICE" >/dev/null
|
|
||||||
|
|
||||||
echo "Building service..."
|
|
||||||
dotnet build -c Release >/dev/null
|
|
||||||
|
|
||||||
# Automatically detect built DLL in bin/Release/<TFM>/
|
|
||||||
DLL_PATH="$(find "bin/Release" -maxdepth 3 -name '*.dll' | head -n 1)"
|
|
||||||
if [[ -z "$DLL_PATH" ]]; then
|
|
||||||
echo "ERROR: Could not locate DLL for $PROJECT_NAME"
|
|
||||||
popd >/dev/null
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Running schema export..."
|
|
||||||
dotnet exec "$DLL_PATH" schema export --output schema.graphql
|
|
||||||
|
|
||||||
echo "Running subgraph pack..."
|
|
||||||
fusion subgraph pack
|
|
||||||
|
|
||||||
popd >/dev/null
|
|
||||||
echo "Completed: $PROJECT_NAME"
|
|
||||||
echo
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "----------------------------------------"
|
|
||||||
echo " Running fusion compose..."
|
|
||||||
echo "----------------------------------------"
|
|
||||||
|
|
||||||
pushd "$ROOT" >/dev/null
|
|
||||||
|
|
||||||
# Remove old composition file
|
|
||||||
rm -f gateway.fgp
|
|
||||||
|
|
||||||
for SERVICE in "${SERVICE_LIST[@]}"; do
|
|
||||||
SERVICE_NAME="$(basename "$SERVICE")"
|
|
||||||
|
|
||||||
echo "Composing subgraph: $SERVICE_NAME"
|
|
||||||
|
|
||||||
# Note: Fusion compose must reference parent dir (services live above ROOT)
|
|
||||||
fusion compose -p gateway.fgp -s "../$SERVICE_NAME"
|
|
||||||
done
|
|
||||||
|
|
||||||
popd >/dev/null
|
|
||||||
|
|
||||||
echo "----------------------------------------"
|
|
||||||
echo " Fusion build complete!"
|
|
||||||
echo "----------------------------------------"
|
|
||||||
@@ -2,6 +2,8 @@ using Amazon.Runtime;
|
|||||||
using Amazon.S3;
|
using Amazon.S3;
|
||||||
using FictionArchive.Common.Extensions;
|
using FictionArchive.Common.Extensions;
|
||||||
using FictionArchive.Service.FileService.Models;
|
using FictionArchive.Service.FileService.Models;
|
||||||
|
using FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||||
|
using FictionArchive.Service.FileService.Services.EventHandlers;
|
||||||
using FictionArchive.Service.Shared.Extensions;
|
using FictionArchive.Service.Shared.Extensions;
|
||||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -27,7 +29,8 @@ public class Program
|
|||||||
builder.Services.AddRabbitMQ(opt =>
|
builder.Services.AddRabbitMQ(opt =>
|
||||||
{
|
{
|
||||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||||
});
|
})
|
||||||
|
.Subscribe<FileUploadRequestCreatedEvent, FileUploadRequestCreatedEventHandler>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class FileUploadRequestCreatedEventHandler : IIntegrationEventHandler<Fil
|
|||||||
var putObjectRequest = new PutObjectRequest();
|
var putObjectRequest = new PutObjectRequest();
|
||||||
putObjectRequest.BucketName = _s3Configuration.Bucket;
|
putObjectRequest.BucketName = _s3Configuration.Bucket;
|
||||||
putObjectRequest.Key = @event.FilePath;
|
putObjectRequest.Key = @event.FilePath;
|
||||||
|
putObjectRequest.UseChunkEncoding = false; // Needed to avoid an error with Garage
|
||||||
|
|
||||||
using MemoryStream memoryStream = new MemoryStream(@event.FileData);
|
using MemoryStream memoryStream = new MemoryStream(@event.FileData);
|
||||||
putObjectRequest.InputStream = memoryStream;
|
putObjectRequest.InputStream = memoryStream;
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Proxy": {
|
"ProxyConfiguration": {
|
||||||
"BaseUrl": "https://localhost:7247/api"
|
"BaseUrl": "https://localhost:7247/api"
|
||||||
},
|
},
|
||||||
"RabbitMQ": {
|
"RabbitMQ": {
|
||||||
"ConnectionString": "amqp://localhost",
|
"ConnectionString": "amqp://localhost",
|
||||||
"ClientIdentifier": "NovelService"
|
"ClientIdentifier": "FileService"
|
||||||
},
|
},
|
||||||
"S3": {
|
"S3": {
|
||||||
"Url": "https://s3.orfl.xyz",
|
"Url": "https://s3.orfl.xyz",
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.11" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||||
|
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\\FictionArchive.Service.NovelService\\FictionArchive.Service.NovelService.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.FileService.IntegrationEvents;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Enums;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Novels;
|
||||||
|
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||||
|
using FictionArchive.Service.NovelService.Services;
|
||||||
|
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
using FluentAssertions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using NSubstitute;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Tests;
|
||||||
|
|
||||||
|
public class NovelUpdateServiceTests
|
||||||
|
{
|
||||||
|
private static NovelServiceDbContext CreateDbContext()
|
||||||
|
{
|
||||||
|
var options = new DbContextOptionsBuilder<NovelServiceDbContext>()
|
||||||
|
.UseInMemoryDatabase($"NovelUpdateServiceTests-{Guid.NewGuid()}")
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
return new NovelServiceDbContext(options, NullLogger<NovelServiceDbContext>.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NovelCreateResult CreateNovelWithSingleChapter(NovelServiceDbContext dbContext, Source source)
|
||||||
|
{
|
||||||
|
var chapter = new Chapter
|
||||||
|
{
|
||||||
|
Order = 1,
|
||||||
|
Revision = 1,
|
||||||
|
Url = "http://demo/chapter-1",
|
||||||
|
Name = LocalizationKey.CreateFromText("Chapter 1", Language.En),
|
||||||
|
Body = new LocalizationKey { Texts = new List<LocalizationText>() },
|
||||||
|
Images = new List<Image>()
|
||||||
|
};
|
||||||
|
|
||||||
|
var novel = new Novel
|
||||||
|
{
|
||||||
|
Url = "http://demo/novel",
|
||||||
|
ExternalId = "demo-1",
|
||||||
|
Author = new Person { Name = LocalizationKey.CreateFromText("Author", Language.En) },
|
||||||
|
RawLanguage = Language.En,
|
||||||
|
RawStatus = NovelStatus.InProgress,
|
||||||
|
Source = source,
|
||||||
|
Name = LocalizationKey.CreateFromText("Demo Novel", Language.En),
|
||||||
|
Description = LocalizationKey.CreateFromText("Description", Language.En),
|
||||||
|
Chapters = new List<Chapter> { chapter },
|
||||||
|
Tags = new List<NovelTag>()
|
||||||
|
};
|
||||||
|
|
||||||
|
dbContext.Novels.Add(novel);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
return new NovelCreateResult(novel, chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NovelUpdateService CreateService(
|
||||||
|
NovelServiceDbContext dbContext,
|
||||||
|
ISourceAdapter adapter,
|
||||||
|
IEventBus eventBus,
|
||||||
|
string pendingImageUrl = "https://pending/placeholder.jpg")
|
||||||
|
{
|
||||||
|
var options = Options.Create(new NovelUpdateServiceConfiguration
|
||||||
|
{
|
||||||
|
PendingImageUrl = pendingImageUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, eventBus, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PullChapterContents_rewrites_images_and_publishes_requests()
|
||||||
|
{
|
||||||
|
using var dbContext = CreateDbContext();
|
||||||
|
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
||||||
|
var (novel, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||||
|
|
||||||
|
var rawHtml = "<p>Hello</p><img src=\"http://img/x1.jpg\" alt=\"first\" /><img src=\"http://img/x2.jpg\" alt=\"second\" />";
|
||||||
|
var image1 = new ImageData { Url = "http://img/x1.jpg", Data = new byte[] { 1, 2, 3 } };
|
||||||
|
var image2 = new ImageData { Url = "http://img/x2.jpg", Data = new byte[] { 4, 5, 6 } };
|
||||||
|
|
||||||
|
var adapter = Substitute.For<ISourceAdapter>();
|
||||||
|
adapter.SourceDescriptor.Returns(new SourceDescriptor { Key = "demo", Name = "Demo", Url = "http://demo" });
|
||||||
|
adapter.GetRawChapter(chapter.Url).Returns(Task.FromResult(new ChapterFetchResult
|
||||||
|
{
|
||||||
|
Text = rawHtml,
|
||||||
|
ImageData = new List<ImageData> { image1, image2 }
|
||||||
|
}));
|
||||||
|
|
||||||
|
var publishedEvents = new List<FileUploadRequestCreatedEvent>();
|
||||||
|
var eventBus = Substitute.For<IEventBus>();
|
||||||
|
eventBus.Publish(Arg.Do<FileUploadRequestCreatedEvent>(publishedEvents.Add)).Returns(Task.CompletedTask);
|
||||||
|
eventBus.Publish(Arg.Any<object>(), Arg.Any<string>()).Returns(Task.CompletedTask);
|
||||||
|
|
||||||
|
var pendingImageUrl = "https://pending/placeholder.jpg";
|
||||||
|
var service = CreateService(dbContext, adapter, eventBus, pendingImageUrl);
|
||||||
|
|
||||||
|
var updatedChapter = await service.PullChapterContents(novel.Id, chapter.Order);
|
||||||
|
|
||||||
|
updatedChapter.Images.Should().HaveCount(2);
|
||||||
|
updatedChapter.Images.Select(i => i.OriginalPath).Should().BeEquivalentTo(new[] { image1.Url, image2.Url });
|
||||||
|
updatedChapter.Images.All(i => i.Id != Guid.Empty).Should().BeTrue();
|
||||||
|
|
||||||
|
var storedHtml = updatedChapter.Body.Texts.Single().Text;
|
||||||
|
var doc = new HtmlDocument();
|
||||||
|
doc.LoadHtml(storedHtml);
|
||||||
|
var imgNodes = doc.DocumentNode.SelectNodes("//img");
|
||||||
|
imgNodes.Should().NotBeNull();
|
||||||
|
imgNodes!.Count.Should().Be(2);
|
||||||
|
imgNodes.Should().OnlyContain(node => node.GetAttributeValue("src", string.Empty) == pendingImageUrl);
|
||||||
|
imgNodes.Select(node => node.GetAttributeValue("alt", string.Empty))
|
||||||
|
.Should()
|
||||||
|
.BeEquivalentTo(updatedChapter.Images.Select(img => img.Id.ToString()));
|
||||||
|
|
||||||
|
publishedEvents.Should().HaveCount(2);
|
||||||
|
publishedEvents.Select(e => e.RequestId).Should().BeEquivalentTo(updatedChapter.Images.Select(i => i.Id));
|
||||||
|
publishedEvents.Select(e => e.FileData).Should().BeEquivalentTo(new[] { image1.Data, image2.Data });
|
||||||
|
publishedEvents.Should().OnlyContain(e => e.FilePath.StartsWith($"{novel.Id}/Images/Chapter-{updatedChapter.Id}/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PullChapterContents_adds_alt_when_missing()
|
||||||
|
{
|
||||||
|
using var dbContext = CreateDbContext();
|
||||||
|
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
||||||
|
var (novel, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||||
|
|
||||||
|
var rawHtml = "<p>Hi</p><img src=\"http://img/x1.jpg\">";
|
||||||
|
var image = new ImageData { Url = "http://img/x1.jpg", Data = new byte[] { 7, 8, 9 } };
|
||||||
|
|
||||||
|
var adapter = Substitute.For<ISourceAdapter>();
|
||||||
|
adapter.SourceDescriptor.Returns(new SourceDescriptor { Key = "demo", Name = "Demo", Url = "http://demo" });
|
||||||
|
adapter.GetRawChapter(chapter.Url).Returns(Task.FromResult(new ChapterFetchResult
|
||||||
|
{
|
||||||
|
Text = rawHtml,
|
||||||
|
ImageData = new List<ImageData> { image }
|
||||||
|
}));
|
||||||
|
|
||||||
|
var eventBus = Substitute.For<IEventBus>();
|
||||||
|
eventBus.Publish(Arg.Any<FileUploadRequestCreatedEvent>()).Returns(Task.CompletedTask);
|
||||||
|
eventBus.Publish(Arg.Any<object>(), Arg.Any<string>()).Returns(Task.CompletedTask);
|
||||||
|
|
||||||
|
var service = CreateService(dbContext, adapter, eventBus);
|
||||||
|
|
||||||
|
var updatedChapter = await service.PullChapterContents(novel.Id, chapter.Order);
|
||||||
|
|
||||||
|
var storedHtml = updatedChapter.Body.Texts.Single().Text;
|
||||||
|
var doc = new HtmlDocument();
|
||||||
|
doc.LoadHtml(storedHtml);
|
||||||
|
var imgNode = doc.DocumentNode.SelectSingleNode("//img");
|
||||||
|
imgNode.Should().NotBeNull();
|
||||||
|
imgNode!.GetAttributeValue("alt", string.Empty).Should().Be(updatedChapter.Images.Single().Id.ToString());
|
||||||
|
imgNode.GetAttributeValue("src", string.Empty).Should().Be("https://pending/placeholder.jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
private record NovelCreateResult(Novel Novel, Chapter Chapter);
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.12.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
540
FictionArchive.Service.NovelService/Migrations/20251123203953_AddImages.Designer.cs
generated
Normal file
540
FictionArchive.Service.NovelService/Migrations/20251123203953_AddImages.Designer.cs
generated
Normal file
@@ -0,0 +1,540 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FictionArchive.Service.NovelService.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using NodaTime;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(NovelServiceDbContext))]
|
||||||
|
[Migration("20251123203953_AddImages")]
|
||||||
|
partial class AddImages
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.11")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<long?>("ChapterId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("NewPath")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalPath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ChapterId");
|
||||||
|
|
||||||
|
b.ToTable("Images");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("LocalizationKeys");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("EngineId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid>("KeyRequestedForTranslationId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("TranslateTo")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("EngineId");
|
||||||
|
|
||||||
|
b.HasIndex("KeyRequestedForTranslationId");
|
||||||
|
|
||||||
|
b.ToTable("LocalizationRequests");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("Language")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid?>("LocalizationKeyId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Text")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long?>("TranslationEngineId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("LocalizationKeyId");
|
||||||
|
|
||||||
|
b.HasIndex("TranslationEngineId");
|
||||||
|
|
||||||
|
b.ToTable("LocalizationText");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<Guid>("BodyId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("NameId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<long?>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<long>("Order")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<long>("Revision")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("BodyId");
|
||||||
|
|
||||||
|
b.HasIndex("NameId");
|
||||||
|
|
||||||
|
b.HasIndex("NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("AuthorId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid?>("CoverImageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("DescriptionId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("ExternalId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("NameId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<int>("RawLanguage")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("RawStatus")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<long>("SourceId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int?>("StatusOverride")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorId");
|
||||||
|
|
||||||
|
b.HasIndex("CoverImageId");
|
||||||
|
|
||||||
|
b.HasIndex("DescriptionId");
|
||||||
|
|
||||||
|
b.HasIndex("NameId");
|
||||||
|
|
||||||
|
b.HasIndex("SourceId");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("DisplayNameId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long?>("SourceId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int>("TagType")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("DisplayNameId");
|
||||||
|
|
||||||
|
b.HasIndex("SourceId");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ExternalUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("NameId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NameId");
|
||||||
|
|
||||||
|
b.ToTable("Person");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Source", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Sources");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Key")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("TranslationEngines");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelNovelTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("NovelsId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<long>("TagsId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("NovelsId", "TagsId");
|
||||||
|
|
||||||
|
b.HasIndex("TagsId");
|
||||||
|
|
||||||
|
b.ToTable("NovelNovelTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Chapter", "Chapter")
|
||||||
|
.WithMany("Images")
|
||||||
|
.HasForeignKey("ChapterId");
|
||||||
|
|
||||||
|
b.Navigation("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "Engine")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("EngineId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "KeyRequestedForTranslation")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("KeyRequestedForTranslationId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Engine");
|
||||||
|
|
||||||
|
b.Navigation("KeyRequestedForTranslation");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", null)
|
||||||
|
.WithMany("Texts")
|
||||||
|
.HasForeignKey("LocalizationKeyId");
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "TranslationEngine")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TranslationEngineId");
|
||||||
|
|
||||||
|
b.Navigation("TranslationEngine");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Body")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("BodyId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NameId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("NovelId");
|
||||||
|
|
||||||
|
b.Navigation("Body");
|
||||||
|
|
||||||
|
b.Navigation("Name");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Person", "Author")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("AuthorId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Images.Image", "CoverImage")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CoverImageId");
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Description")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("DescriptionId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NameId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("SourceId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Author");
|
||||||
|
|
||||||
|
b.Navigation("CoverImage");
|
||||||
|
|
||||||
|
b.Navigation("Description");
|
||||||
|
|
||||||
|
b.Navigation("Name");
|
||||||
|
|
||||||
|
b.Navigation("Source");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "DisplayName")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("DisplayNameId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("SourceId");
|
||||||
|
|
||||||
|
b.Navigation("DisplayName");
|
||||||
|
|
||||||
|
b.Navigation("Source");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NameId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Name");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NovelNovelTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("NovelsId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.NovelTag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Texts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Images");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddImages : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "CoverImageId",
|
||||||
|
table: "Novels",
|
||||||
|
type: "uuid",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Images",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
OriginalPath = table.Column<string>(type: "text", nullable: false),
|
||||||
|
NewPath = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ChapterId = table.Column<long>(type: "bigint", nullable: true),
|
||||||
|
CreatedTime = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||||
|
LastUpdatedTime = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Images", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Images_Chapter_ChapterId",
|
||||||
|
column: x => x.ChapterId,
|
||||||
|
principalTable: "Chapter",
|
||||||
|
principalColumn: "Id");
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Novels_CoverImageId",
|
||||||
|
table: "Novels",
|
||||||
|
column: "CoverImageId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Images_ChapterId",
|
||||||
|
table: "Images",
|
||||||
|
column: "ChapterId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Novels_Images_CoverImageId",
|
||||||
|
table: "Novels",
|
||||||
|
column: "CoverImageId",
|
||||||
|
principalTable: "Images",
|
||||||
|
principalColumn: "Id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Novels_Images_CoverImageId",
|
||||||
|
table: "Novels");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Images");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Novels_CoverImageId",
|
||||||
|
table: "Novels");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "CoverImageId",
|
||||||
|
table: "Novels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,35 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<long?>("ChapterId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("NewPath")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalPath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ChapterId");
|
||||||
|
|
||||||
|
b.ToTable("Images");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -158,6 +187,9 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.Property<long>("AuthorId")
|
b.Property<long>("AuthorId")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid?>("CoverImageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<Instant>("CreatedTime")
|
b.Property<Instant>("CreatedTime")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
@@ -194,6 +226,8 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
|
|
||||||
b.HasIndex("AuthorId");
|
b.HasIndex("AuthorId");
|
||||||
|
|
||||||
|
b.HasIndex("CoverImageId");
|
||||||
|
|
||||||
b.HasIndex("DescriptionId");
|
b.HasIndex("DescriptionId");
|
||||||
|
|
||||||
b.HasIndex("NameId");
|
b.HasIndex("NameId");
|
||||||
@@ -335,6 +369,15 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.ToTable("NovelNovelTag");
|
b.ToTable("NovelNovelTag");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Chapter", "Chapter")
|
||||||
|
.WithMany("Images")
|
||||||
|
.HasForeignKey("ChapterId");
|
||||||
|
|
||||||
|
b.Navigation("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "Engine")
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "Engine")
|
||||||
@@ -398,6 +441,10 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("FictionArchive.Service.NovelService.Models.Images.Image", "CoverImage")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("CoverImageId");
|
||||||
|
|
||||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Description")
|
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Description")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("DescriptionId")
|
.HasForeignKey("DescriptionId")
|
||||||
@@ -418,6 +465,8 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
|
|
||||||
b.Navigation("Author");
|
b.Navigation("Author");
|
||||||
|
|
||||||
|
b.Navigation("CoverImage");
|
||||||
|
|
||||||
b.Navigation("Description");
|
b.Navigation("Description");
|
||||||
|
|
||||||
b.Navigation("Name");
|
b.Navigation("Name");
|
||||||
@@ -473,6 +522,11 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.Navigation("Texts");
|
b.Navigation("Texts");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Images");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace FictionArchive.Service.NovelService.Models.Configuration;
|
||||||
|
|
||||||
|
public class NovelUpdateServiceConfiguration
|
||||||
|
{
|
||||||
|
public string PendingImageUrl { get; set; }
|
||||||
|
}
|
||||||
13
FictionArchive.Service.NovelService/Models/Images/Image.cs
Normal file
13
FictionArchive.Service.NovelService/Models/Images/Image.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using FictionArchive.Service.NovelService.Models.Novels;
|
||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Models.Images;
|
||||||
|
|
||||||
|
public class Image : BaseEntity<Guid>
|
||||||
|
{
|
||||||
|
public string OriginalPath { get; set; }
|
||||||
|
public string? NewPath { get; set; }
|
||||||
|
|
||||||
|
// Chapter link. Even if an image appears in another chapter, we should rehost it separately.
|
||||||
|
public Chapter? Chapter { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||||
|
|
||||||
|
public class FileUploadRequestStatusUpdateEvent : IIntegrationEvent
|
||||||
|
{
|
||||||
|
public Guid RequestId { get; set; }
|
||||||
|
public RequestStatus Status { get; set; }
|
||||||
|
|
||||||
|
#region Success
|
||||||
|
|
||||||
|
public string? FileAccessUrl { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Failure
|
||||||
|
|
||||||
|
public string? ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
using FictionArchive.Service.NovelService.Models.Localization;
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
using FictionArchive.Service.Shared.Models;
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
@@ -11,4 +12,7 @@ public class Chapter : BaseEntity<uint>
|
|||||||
|
|
||||||
public LocalizationKey Name { get; set; }
|
public LocalizationKey Name { get; set; }
|
||||||
public LocalizationKey Body { get; set; }
|
public LocalizationKey Body { get; set; }
|
||||||
|
|
||||||
|
// Images appearing in this chapter.
|
||||||
|
public List<Image> Images { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using FictionArchive.Common.Enums;
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
using FictionArchive.Service.NovelService.Models.Localization;
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
using FictionArchive.Service.Shared.Models;
|
using FictionArchive.Service.Shared.Models;
|
||||||
using NovelStatus = FictionArchive.Service.NovelService.Models.Enums.NovelStatus;
|
using NovelStatus = FictionArchive.Service.NovelService.Models.Enums.NovelStatus;
|
||||||
@@ -22,4 +23,5 @@ public class Novel : BaseEntity<uint>
|
|||||||
|
|
||||||
public List<Chapter> Chapters { get; set; }
|
public List<Chapter> Chapters { get; set; }
|
||||||
public List<NovelTag> Tags { get; set; }
|
public List<NovelTag> Tags { get; set; }
|
||||||
|
public Image? CoverImage { get; set; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||||
|
|
||||||
|
public class ChapterFetchResult
|
||||||
|
{
|
||||||
|
public string Text { get; set; }
|
||||||
|
public List<ImageData> ImageData { get; set; }
|
||||||
|
}
|
||||||
@@ -6,5 +6,5 @@ public class ChapterMetadata
|
|||||||
public uint Order { get; set; }
|
public uint Order { get; set; }
|
||||||
public string? Url { get; set; }
|
public string? Url { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
public List<string> ImageUrls { get; set; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||||
|
|
||||||
|
public class ImageData
|
||||||
|
{
|
||||||
|
public string Url { get; set; }
|
||||||
|
public byte[] Data { get; set; }
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ public class NovelMetadata
|
|||||||
public string AuthorUrl { get; set; }
|
public string AuthorUrl { get; set; }
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public string ExternalId { get; set; }
|
public string ExternalId { get; set; }
|
||||||
|
public ImageData? CoverImage { get; set; }
|
||||||
|
|
||||||
public Language RawLanguage { get; set; }
|
public Language RawLanguage { get; set; }
|
||||||
public NovelStatus RawStatus { get; set; }
|
public NovelStatus RawStatus { get; set; }
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using FictionArchive.Common.Extensions;
|
||||||
using FictionArchive.Service.NovelService.GraphQL;
|
using FictionArchive.Service.NovelService.GraphQL;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||||
using FictionArchive.Service.NovelService.Services;
|
using FictionArchive.Service.NovelService.Services;
|
||||||
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||||
@@ -16,6 +18,7 @@ public class Program
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.AddLocalAppsettings();
|
||||||
|
|
||||||
builder.Services.AddMemoryCache();
|
builder.Services.AddMemoryCache();
|
||||||
|
|
||||||
@@ -27,7 +30,8 @@ public class Program
|
|||||||
})
|
})
|
||||||
.Subscribe<TranslationRequestCompletedEvent, TranslationRequestCompletedEventHandler>()
|
.Subscribe<TranslationRequestCompletedEvent, TranslationRequestCompletedEventHandler>()
|
||||||
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
||||||
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>();
|
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>()
|
||||||
|
.Subscribe<FileUploadRequestStatusUpdateEvent, FileUploadRequestStatusUpdateEventHandler>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -56,6 +60,7 @@ public class Program
|
|||||||
})
|
})
|
||||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
||||||
|
|
||||||
|
builder.Services.Configure<NovelUpdateServiceConfiguration>(builder.Configuration.GetSection("UpdateService"));
|
||||||
builder.Services.AddTransient<NovelUpdateService>();
|
builder.Services.AddTransient<NovelUpdateService>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||||
|
|
||||||
|
public class FileUploadRequestStatusUpdateEventHandler : IIntegrationEventHandler<FileUploadRequestStatusUpdateEvent>
|
||||||
|
{
|
||||||
|
private readonly ILogger<FileUploadRequestStatusUpdateEventHandler> _logger;
|
||||||
|
private readonly NovelServiceDbContext _context;
|
||||||
|
private readonly NovelUpdateService _novelUpdateService;
|
||||||
|
|
||||||
|
public FileUploadRequestStatusUpdateEventHandler(ILogger<FileUploadRequestStatusUpdateEventHandler> logger, NovelServiceDbContext context, NovelUpdateService novelUpdateService)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_context = context;
|
||||||
|
_novelUpdateService = novelUpdateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Handle(FileUploadRequestStatusUpdateEvent @event)
|
||||||
|
{
|
||||||
|
var image = await _context.Images.FindAsync(@event.RequestId);
|
||||||
|
if (image == null)
|
||||||
|
{
|
||||||
|
// Not a request we care about.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (@event.Status == RequestStatus.Failed)
|
||||||
|
{
|
||||||
|
_logger.LogError("Image upload failed for image with id {imageId}", image.Id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (@event.Status == RequestStatus.Success)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Image upload succeeded for image with id {imageId}", image.Id);
|
||||||
|
await _novelUpdateService.UpdateImage(image.Id, @event.FileAccessUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
using FictionArchive.Service.NovelService.Models.Localization;
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
using FictionArchive.Service.NovelService.Models.Novels;
|
using FictionArchive.Service.NovelService.Models.Novels;
|
||||||
using FictionArchive.Service.Shared.Services.Database;
|
using FictionArchive.Service.Shared.Services.Database;
|
||||||
@@ -14,4 +15,5 @@ public class NovelServiceDbContext(DbContextOptions options, ILogger<NovelServic
|
|||||||
public DbSet<NovelTag> Tags { get; set; }
|
public DbSet<NovelTag> Tags { get; set; }
|
||||||
public DbSet<LocalizationKey> LocalizationKeys { get; set; }
|
public DbSet<LocalizationKey> LocalizationKeys { get; set; }
|
||||||
public DbSet<LocalizationRequest> LocalizationRequests { get; set; }
|
public DbSet<LocalizationRequest> LocalizationRequests { get; set; }
|
||||||
|
public DbSet<Image> Images { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
|
using FictionArchive.Service.FileService.IntegrationEvents;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||||
using FictionArchive.Service.NovelService.Models.Enums;
|
using FictionArchive.Service.NovelService.Models.Enums;
|
||||||
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
using FictionArchive.Service.NovelService.Models.Localization;
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
using FictionArchive.Service.NovelService.Models.Novels;
|
using FictionArchive.Service.NovelService.Models.Novels;
|
||||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
using HtmlAgilityPack;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FictionArchive.Service.NovelService.Services;
|
namespace FictionArchive.Service.NovelService.Services;
|
||||||
|
|
||||||
@@ -12,12 +18,16 @@ public class NovelUpdateService
|
|||||||
private readonly NovelServiceDbContext _dbContext;
|
private readonly NovelServiceDbContext _dbContext;
|
||||||
private readonly ILogger<NovelUpdateService> _logger;
|
private readonly ILogger<NovelUpdateService> _logger;
|
||||||
private readonly IEnumerable<ISourceAdapter> _sourceAdapters;
|
private readonly IEnumerable<ISourceAdapter> _sourceAdapters;
|
||||||
|
private readonly IEventBus _eventBus;
|
||||||
|
private readonly NovelUpdateServiceConfiguration _novelUpdateServiceConfiguration;
|
||||||
|
|
||||||
public NovelUpdateService(NovelServiceDbContext dbContext, ILogger<NovelUpdateService> logger, IEnumerable<ISourceAdapter> sourceAdapters)
|
public NovelUpdateService(NovelServiceDbContext dbContext, ILogger<NovelUpdateService> logger, IEnumerable<ISourceAdapter> sourceAdapters, IEventBus eventBus, IOptions<NovelUpdateServiceConfiguration> novelUpdateServiceConfiguration)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_sourceAdapters = sourceAdapters;
|
_sourceAdapters = sourceAdapters;
|
||||||
|
_eventBus = eventBus;
|
||||||
|
_novelUpdateServiceConfiguration = novelUpdateServiceConfiguration.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Novel> ImportNovel(string novelUrl)
|
public async Task<Novel> ImportNovel(string novelUrl)
|
||||||
@@ -59,6 +69,10 @@ public class NovelUpdateService
|
|||||||
RawLanguage = metadata.RawLanguage,
|
RawLanguage = metadata.RawLanguage,
|
||||||
Url = metadata.Url,
|
Url = metadata.Url,
|
||||||
ExternalId = metadata.ExternalId,
|
ExternalId = metadata.ExternalId,
|
||||||
|
CoverImage = metadata.CoverImage != null ? new Image()
|
||||||
|
{
|
||||||
|
OriginalPath = metadata.CoverImage.Url,
|
||||||
|
} : null,
|
||||||
Chapters = metadata.Chapters.Select(chapter =>
|
Chapters = metadata.Chapters.Select(chapter =>
|
||||||
{
|
{
|
||||||
return new Chapter()
|
return new Chapter()
|
||||||
@@ -85,7 +99,18 @@ public class NovelUpdateService
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Signal request for cover image if present
|
||||||
|
if (addedNovel.Entity.CoverImage != null)
|
||||||
|
{
|
||||||
|
await _eventBus.Publish(new FileUploadRequestCreatedEvent()
|
||||||
|
{
|
||||||
|
RequestId = addedNovel.Entity.CoverImage.Id,
|
||||||
|
FileData = metadata.CoverImage.Data,
|
||||||
|
FilePath = $"Novels/{addedNovel.Entity.Id}/Images/cover.jpg"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return addedNovel.Entity;
|
return addedNovel.Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,17 +120,85 @@ public class NovelUpdateService
|
|||||||
.Include(novel => novel.Chapters)
|
.Include(novel => novel.Chapters)
|
||||||
.ThenInclude(chapter => chapter.Body)
|
.ThenInclude(chapter => chapter.Body)
|
||||||
.ThenInclude(body => body.Texts)
|
.ThenInclude(body => body.Texts)
|
||||||
.Include(novel => novel.Source)
|
.Include(novel => novel.Source).Include(novel => novel.Chapters).ThenInclude(chapter => chapter.Images)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
var chapter = novel.Chapters.Where(chapter => chapter.Order == chapterNumber).FirstOrDefault();
|
var chapter = novel.Chapters.Where(chapter => chapter.Order == chapterNumber).FirstOrDefault();
|
||||||
var adapter = _sourceAdapters.FirstOrDefault(adapter => adapter.SourceDescriptor.Key == novel.Source.Key);
|
var adapter = _sourceAdapters.FirstOrDefault(adapter => adapter.SourceDescriptor.Key == novel.Source.Key);
|
||||||
var rawChapter = await adapter.GetRawChapter(chapter.Url);
|
var rawChapter = await adapter.GetRawChapter(chapter.Url);
|
||||||
chapter.Body.Texts.Add(new LocalizationText()
|
var localizationText = new LocalizationText()
|
||||||
{
|
{
|
||||||
Text = rawChapter,
|
Text = rawChapter.Text,
|
||||||
Language = novel.RawLanguage
|
Language = novel.RawLanguage
|
||||||
});
|
};
|
||||||
|
chapter.Body.Texts.Add(localizationText);
|
||||||
|
chapter.Images = rawChapter.ImageData.Select(img => new Image()
|
||||||
|
{
|
||||||
|
OriginalPath = img.Url
|
||||||
|
}).ToList();
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Images are saved and have ids, update the chapter body to replace image tags
|
||||||
|
var chapterDoc = new HtmlDocument();
|
||||||
|
chapterDoc.LoadHtml(rawChapter.Text);
|
||||||
|
foreach (var image in chapter.Images)
|
||||||
|
{
|
||||||
|
var match = chapterDoc.DocumentNode.SelectSingleNode(@$"//img[@src='{image.OriginalPath}']");
|
||||||
|
if (match != null)
|
||||||
|
{
|
||||||
|
match.Attributes["src"].Value = _novelUpdateServiceConfiguration.PendingImageUrl;
|
||||||
|
if (match.Attributes.Contains("alt"))
|
||||||
|
{
|
||||||
|
match.Attributes["alt"].Value = image.Id.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
match.Attributes.Add("alt", image.Id.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
localizationText.Text = chapterDoc.DocumentNode.OuterHtml;
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Body was updated, raise image request
|
||||||
|
int imgCount = 0;
|
||||||
|
foreach (var image in chapter.Images)
|
||||||
|
{
|
||||||
|
var data = rawChapter.ImageData.FirstOrDefault(img => img.Url == image.OriginalPath);
|
||||||
|
await _eventBus.Publish(new FileUploadRequestCreatedEvent()
|
||||||
|
{
|
||||||
|
FileData = data.Data,
|
||||||
|
FilePath = $"{novel.Id}/Images/Chapter-{chapter.Id}/{imgCount++}.jpg",
|
||||||
|
RequestId = image.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return chapter;
|
return chapter;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public async Task UpdateImage(Guid imageId, string newUrl)
|
||||||
|
{
|
||||||
|
var image = await _dbContext.Images
|
||||||
|
.Include(img => img.Chapter)
|
||||||
|
.ThenInclude(chapter => chapter.Body)
|
||||||
|
.ThenInclude(body => body.Texts)
|
||||||
|
.FirstOrDefaultAsync(image => image.Id == imageId);
|
||||||
|
image.NewPath = newUrl;
|
||||||
|
|
||||||
|
// If this is an image from a chapter, let's update the chapter body(s)
|
||||||
|
if (image.Chapter != null)
|
||||||
|
{
|
||||||
|
foreach (var bodyText in image.Chapter.Body.Texts)
|
||||||
|
{
|
||||||
|
var chapterDoc = new HtmlDocument();
|
||||||
|
chapterDoc.LoadHtml(bodyText.Text);
|
||||||
|
var match = chapterDoc.DocumentNode.SelectSingleNode(@$"//img[@alt='{image.Id}']");
|
||||||
|
if (match != null)
|
||||||
|
{
|
||||||
|
match.Attributes["src"].Value = newUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ public interface ISourceAdapter
|
|||||||
public SourceDescriptor SourceDescriptor { get; }
|
public SourceDescriptor SourceDescriptor { get; }
|
||||||
public Task<bool> CanProcessNovel(string url);
|
public Task<bool> CanProcessNovel(string url);
|
||||||
public Task<NovelMetadata> GetMetadata(string novelUrl);
|
public Task<NovelMetadata> GetMetadata(string novelUrl);
|
||||||
public Task<string> GetRawChapter(string chapterUrl);
|
public Task<ChapterFetchResult> GetRawChapter(string chapterUrl);
|
||||||
}
|
}
|
||||||
@@ -81,6 +81,21 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
novel.AuthorName = authorMatch.Groups[2].Value;
|
novel.AuthorName = authorMatch.Groups[2].Value;
|
||||||
novel.AuthorUrl = authorMatch.Groups[2].Value;
|
novel.AuthorUrl = authorMatch.Groups[2].Value;
|
||||||
|
|
||||||
|
// Cover image URL
|
||||||
|
var coverMatch = Regex.Match(novelData, @"href=""(//images\.novelpia\.com/imagebox/cover/.+?\.file)""");
|
||||||
|
string coverImageUrl = coverMatch.Groups[1].Value;
|
||||||
|
if (string.IsNullOrEmpty(coverImageUrl))
|
||||||
|
{
|
||||||
|
coverMatch = Regex.Match(novelData, @"src=""(//images\.novelpia\.com/imagebox/cover/.+?\.file)""");
|
||||||
|
coverImageUrl = coverMatch.Groups[1].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
novel.CoverImage = new ImageData()
|
||||||
|
{
|
||||||
|
Url = coverImageUrl,
|
||||||
|
Data = await GetImageData(coverImageUrl),
|
||||||
|
};
|
||||||
|
|
||||||
// Some badge info
|
// Some badge info
|
||||||
var badgeSet = Regex.Match(novelData, @"(?s)<p\s+class=""in-badge"">(.*?)<\/p>");
|
var badgeSet = Regex.Match(novelData, @"(?s)<p\s+class=""in-badge"">(.*?)<\/p>");
|
||||||
var badgeMatches = Regex.Matches(badgeSet.Groups[1].Value, @"<span[^>]*>(.*?)<\/span>");
|
var badgeMatches = Regex.Matches(badgeSet.Groups[1].Value, @"<span[^>]*>(.*?)<\/span>");
|
||||||
@@ -160,7 +175,7 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
return novel;
|
return novel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetRawChapter(string chapterUrl)
|
public async Task<ChapterFetchResult> GetRawChapter(string chapterUrl)
|
||||||
{
|
{
|
||||||
var chapterId = uint.Parse(Regex.Match(chapterUrl, ChapterIdRegex).Groups[1].Value);
|
var chapterId = uint.Parse(Regex.Match(chapterUrl, ChapterIdRegex).Groups[1].Value);
|
||||||
var endpoint = ChapterDownloadEndpoint + chapterId;
|
var endpoint = ChapterDownloadEndpoint + chapterId;
|
||||||
@@ -171,6 +186,11 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
{
|
{
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fetchResult = new ChapterFetchResult()
|
||||||
|
{
|
||||||
|
ImageData = new List<ImageData>()
|
||||||
|
};
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
using var doc = JsonDocument.Parse(responseContent);
|
using var doc = JsonDocument.Parse(responseContent);
|
||||||
@@ -182,10 +202,20 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
foreach (JsonElement item in sArray.EnumerateArray())
|
foreach (JsonElement item in sArray.EnumerateArray())
|
||||||
{
|
{
|
||||||
string text = item.GetProperty("text").GetString();
|
string text = item.GetProperty("text").GetString();
|
||||||
|
var imageMatch = Regex.Match(text, @"<img.+?src=\""(.+?)\"".+?>");
|
||||||
if (text.Contains("cover-wrapper"))
|
if (text.Contains("cover-wrapper"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (imageMatch.Success)
|
||||||
|
{
|
||||||
|
var url = imageMatch.Groups[1].Value;
|
||||||
|
fetchResult.ImageData.Add(new ImageData()
|
||||||
|
{
|
||||||
|
Url = url,
|
||||||
|
Data = await GetImageData(url)
|
||||||
|
});
|
||||||
|
}
|
||||||
if (text.Contains("opacity: 0"))
|
if (text.Contains("opacity: 0"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -193,8 +223,24 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
|
|
||||||
builder.Append(WebUtility.HtmlDecode(text));
|
builder.Append(WebUtility.HtmlDecode(text));
|
||||||
}
|
}
|
||||||
|
fetchResult.Text = builder.ToString();
|
||||||
|
|
||||||
return builder.ToString();
|
return fetchResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<byte[]> GetImageData(string url)
|
||||||
|
{
|
||||||
|
if (!url.StartsWith("http"))
|
||||||
|
{
|
||||||
|
url = "https:" + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
var image = await _httpClient.GetAsync(url);
|
||||||
|
if (!image.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_logger.LogError("Attempting to fetch image with url {imgUrl} returned status code {code}.", url, image.StatusCode);
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
return await image.Content.ReadAsByteArrayAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,10 +52,15 @@ public class NovelpiaAuthMessageHandler : DelegatingHandler
|
|||||||
var response = await _httpClient.SendAsync(loginMessage);
|
var response = await _httpClient.SendAsync(loginMessage);
|
||||||
using (var streamReader = new StreamReader(response.Content.ReadAsStream()))
|
using (var streamReader = new StreamReader(response.Content.ReadAsStream()))
|
||||||
{
|
{
|
||||||
if (streamReader.ReadToEnd().Contains(LoginSuccessMessage))
|
var message = await streamReader.ReadToEndAsync();
|
||||||
|
if (message.Contains(LoginSuccessMessage))
|
||||||
{
|
{
|
||||||
_cache.Set(CacheKey, loginKey);
|
_cache.Set(CacheKey, loginKey);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("An error occured while retrieving the login key. Message: " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
"Username": "REPLACE_ME",
|
"Username": "REPLACE_ME",
|
||||||
"Password": "REPLACE_ME"
|
"Password": "REPLACE_ME"
|
||||||
},
|
},
|
||||||
|
"UpdateService": {
|
||||||
|
"PendingImageUrl": "https://localhost:7247/api/pendingupload.png"
|
||||||
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Host=localhost;Database=FictionArchive_NovelService;Username=postgres;password=postgres"
|
"DefaultConnection": "Host=localhost;Database=FictionArchive_NovelService;Username=postgres;password=postgres"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.Auth
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.FileService", "FictionArchive.Service.FileService\FictionArchive.Service.FileService.csproj", "{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.FileService", "FictionArchive.Service.FileService\FictionArchive.Service.FileService.csproj", "{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.NovelService.Tests", "FictionArchive.Service.NovelService.Tests\FictionArchive.Service.NovelService.Tests.csproj", "{166E645E-9DFB-44E8-8CC8-FA249A11679F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -60,5 +62,9 @@ Global
|
|||||||
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{166E645E-9DFB-44E8-8CC8-FA249A11679F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{166E645E-9DFB-44E8-8CC8-FA249A11679F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{166E645E-9DFB-44E8-8CC8-FA249A11679F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{166E645E-9DFB-44E8-8CC8-FA249A11679F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user