Compare commits
7 Commits
feature/FA
...
feature/FA
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdf2ff7c1b | ||
|
|
e8596b67c4 | ||
|
|
16ed16ff62 | ||
|
|
573a0f6e3f | ||
|
|
1adbb955cf | ||
|
|
71e27b5dbb | ||
| 708f1a5338 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -135,3 +135,8 @@ _NCrunch*
|
||||
|
||||
# Local user appsettings
|
||||
appsettings.Local.json
|
||||
|
||||
# Fusion Builds
|
||||
schema.graphql
|
||||
*.fsp
|
||||
gateway.fgp
|
||||
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.
|
||||
@@ -22,6 +22,11 @@
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||
</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>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
|
||||
@@ -21,14 +21,25 @@ public class Program
|
||||
|
||||
#endregion
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAllOrigins",
|
||||
builder =>
|
||||
{
|
||||
builder.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors("AllowAllOrigins");
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.Run();
|
||||
app.RunWithGraphQLCommands(args);
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set ROOT=%~dp0
|
||||
|
||||
for %%A in ("%ROOT%..") do set SERVICES_DIR=%%~fA\
|
||||
|
||||
REM ----------------------------------------
|
||||
REM List of project names to skip
|
||||
REM (space-separated, match folder names exactly)
|
||||
REM ----------------------------------------
|
||||
set SKIP_PROJECTS=FictionArchive.Service.Shared FictionArchive.Service.AuthenticationService
|
||||
|
||||
echo ----------------------------------------
|
||||
echo Finding GraphQL services...
|
||||
echo ----------------------------------------
|
||||
|
||||
set SERVICE_LIST=
|
||||
|
||||
for /d %%F in ("%SERVICES_DIR%FictionArchive.Service.*") do (
|
||||
set "PROJECT_NAME=%%~nxF"
|
||||
set "SKIP=0"
|
||||
|
||||
REM Check if this project name is in the skip list
|
||||
for %%X in (%SKIP_PROJECTS%) do (
|
||||
if /I "!PROJECT_NAME!"=="%%X" (
|
||||
set "SKIP=1"
|
||||
)
|
||||
)
|
||||
|
||||
if !SKIP!==0 (
|
||||
echo Found service: !PROJECT_NAME!
|
||||
set SERVICE_LIST=!SERVICE_LIST! %%F
|
||||
) else (
|
||||
echo Skipping service: !PROJECT_NAME!
|
||||
)
|
||||
)
|
||||
|
||||
echo:
|
||||
echo ----------------------------------------
|
||||
echo Exporting schemas and packing subgraphs...
|
||||
echo ----------------------------------------
|
||||
|
||||
for %%S in (%SERVICE_LIST%) do (
|
||||
echo Processing service folder: %%S
|
||||
pushd "%%S"
|
||||
|
||||
echo Running schema export...
|
||||
dotnet run -- schema export --output schema.graphql
|
||||
if errorlevel 1 (
|
||||
echo ERROR during schema export in %%S
|
||||
popd
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Running fusion subgraph pack...
|
||||
fusion subgraph pack
|
||||
if errorlevel 1 (
|
||||
echo ERROR during subgraph pack in %%S
|
||||
popd
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
popd
|
||||
echo Completed: %%S
|
||||
echo.
|
||||
)
|
||||
|
||||
echo ----------------------------------------
|
||||
echo Running fusion compose...
|
||||
echo ----------------------------------------
|
||||
|
||||
pushd "%ROOT%"
|
||||
|
||||
if exist gateway.fgp del gateway.fgp
|
||||
|
||||
for %%S in (%SERVICE_LIST%) do (
|
||||
REM Extract the full folder name WITH dots preserved
|
||||
set "SERVICE_NAME=%%~nxS"
|
||||
|
||||
echo Composing subgraph: !SERVICE_NAME!
|
||||
|
||||
fusion compose -p gateway.fgp -s "..\!SERVICE_NAME!"
|
||||
if errorlevel 1 (
|
||||
echo ERROR during fusion compose
|
||||
popd
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
popd
|
||||
|
||||
|
||||
echo ----------------------------------------
|
||||
echo Fusion build complete!
|
||||
echo ----------------------------------------
|
||||
|
||||
endlocal
|
||||
exit /b 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,104 +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_PROJECTS=(
|
||||
"FictionArchive.Service.Shared"
|
||||
"FictionArchive.Service.Legacy"
|
||||
)
|
||||
|
||||
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 "----------------------------------------"
|
||||
Binary file not shown.
5
FictionArchive.API/gateway_skip.txt
Normal file
5
FictionArchive.API/gateway_skip.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
# List of service folders to skip
|
||||
FictionArchive.Service.Shared
|
||||
FictionArchive.Service.AuthenticationService
|
||||
FictionArchive.Service.FileService
|
||||
FictionArchive.Service.NovelService.Tests
|
||||
8
FictionArchive.Common/Enums/RequestStatus.cs
Normal file
8
FictionArchive.Common/Enums/RequestStatus.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace FictionArchive.Common.Enums;
|
||||
|
||||
public enum RequestStatus
|
||||
{
|
||||
Failed = -1,
|
||||
Pending = 0,
|
||||
Success = 1
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Web;
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using FictionArchive.Service.FileService.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Controllers
|
||||
{
|
||||
[Route("api/{*path}")]
|
||||
[ApiController]
|
||||
public class S3ProxyController : ControllerBase
|
||||
{
|
||||
private readonly AmazonS3Client _amazonS3Client;
|
||||
private readonly S3Configuration _s3Configuration;
|
||||
|
||||
public S3ProxyController(AmazonS3Client amazonS3Client, IOptions<S3Configuration> s3Configuration)
|
||||
{
|
||||
_amazonS3Client = amazonS3Client;
|
||||
_s3Configuration = s3Configuration.Value;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get(string path)
|
||||
{
|
||||
var decodedPath = HttpUtility.UrlDecode(path);
|
||||
|
||||
try
|
||||
{
|
||||
var s3Response = await _amazonS3Client.GetObjectAsync(new GetObjectRequest()
|
||||
{
|
||||
BucketName = _s3Configuration.Bucket,
|
||||
Key = decodedPath
|
||||
});
|
||||
|
||||
return new FileStreamResult(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
||||
}
|
||||
catch (AmazonS3Exception e)
|
||||
{
|
||||
if (e.Message == "Key not found")
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
FictionArchive.Service.FileService/Dockerfile
Normal file
23
FictionArchive.Service.FileService/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["FictionArchive.Service.ImageService/FictionArchive.Service.ImageService.csproj", "FictionArchive.Service.ImageService/"]
|
||||
RUN dotnet restore "FictionArchive.Service.ImageService/FictionArchive.Service.ImageService.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/FictionArchive.Service.ImageService"
|
||||
RUN dotnet build "./FictionArchive.Service.ImageService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./FictionArchive.Service.ImageService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "FictionArchive.Service.ImageService.dll"]
|
||||
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AWSSDK.S3" Version="4.0.13.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||
|
||||
public class FileUploadRequestCreatedEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public byte[] FileData { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.FileService.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
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FictionArchive.Service.FileService.Models;
|
||||
|
||||
public class ProxyConfiguration
|
||||
{
|
||||
public string BaseUrl { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FictionArchive.Service.FileService.Models;
|
||||
|
||||
public class S3Configuration
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string Bucket { get; set; }
|
||||
public string AccessKey { get; set; }
|
||||
public string SecretKey { get; set; }
|
||||
}
|
||||
69
FictionArchive.Service.FileService/Program.cs
Normal file
69
FictionArchive.Service.FileService/Program.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Amazon.Runtime;
|
||||
using Amazon.S3;
|
||||
using FictionArchive.Common.Extensions;
|
||||
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.Services.EventBus.Implementations;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.FileService;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.AddLocalAppsettings();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
#region Event Bus
|
||||
|
||||
builder.Services.AddRabbitMQ(opt =>
|
||||
{
|
||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||
})
|
||||
.Subscribe<FileUploadRequestCreatedEvent, FileUploadRequestCreatedEventHandler>();
|
||||
|
||||
#endregion
|
||||
|
||||
builder.Services.Configure<ProxyConfiguration>(builder.Configuration.GetSection("ProxyConfiguration"));
|
||||
|
||||
// Add S3 Client
|
||||
builder.Services.Configure<S3Configuration>(builder.Configuration.GetSection("S3"));
|
||||
builder.Services.AddSingleton<AmazonS3Client>(provider =>
|
||||
{
|
||||
var config = provider.GetRequiredService<IOptions<S3Configuration>>().Value;
|
||||
var s3Config = new AmazonS3Config
|
||||
{
|
||||
ServiceURL = config.Url, // Garage endpoint
|
||||
ForcePathStyle = true, // REQUIRED for Garage
|
||||
AuthenticationRegion = "garage"
|
||||
};
|
||||
return new AmazonS3Client(
|
||||
new BasicAWSCredentials(config.AccessKey, config.SecretKey),
|
||||
s3Config);
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:5546",
|
||||
"sslPort": 44373
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5057",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7247;http://localhost:5057",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.FileService.Models;
|
||||
using FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Services.EventHandlers;
|
||||
|
||||
public class FileUploadRequestCreatedEventHandler : IIntegrationEventHandler<FileUploadRequestCreatedEvent>
|
||||
{
|
||||
private readonly ILogger<FileUploadRequestCreatedEventHandler> _logger;
|
||||
private readonly AmazonS3Client _amazonS3Client;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly S3Configuration _s3Configuration;
|
||||
private readonly ProxyConfiguration _proxyConfiguration;
|
||||
|
||||
public FileUploadRequestCreatedEventHandler(ILogger<FileUploadRequestCreatedEventHandler> logger, AmazonS3Client amazonS3Client, IEventBus eventBus, IOptions<S3Configuration> s3Configuration, IOptions<ProxyConfiguration> proxyConfiguration)
|
||||
{
|
||||
_logger = logger;
|
||||
_amazonS3Client = amazonS3Client;
|
||||
_eventBus = eventBus;
|
||||
_proxyConfiguration = proxyConfiguration.Value;
|
||||
_s3Configuration = s3Configuration.Value;
|
||||
}
|
||||
|
||||
public async Task Handle(FileUploadRequestCreatedEvent @event)
|
||||
{
|
||||
var putObjectRequest = new PutObjectRequest();
|
||||
putObjectRequest.BucketName = _s3Configuration.Bucket;
|
||||
putObjectRequest.Key = @event.FilePath;
|
||||
putObjectRequest.UseChunkEncoding = false; // Needed to avoid an error with Garage
|
||||
|
||||
using MemoryStream memoryStream = new MemoryStream(@event.FileData);
|
||||
putObjectRequest.InputStream = memoryStream;
|
||||
|
||||
var s3Response = await _amazonS3Client.PutObjectAsync(putObjectRequest);
|
||||
if (s3Response.HttpStatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("An error occurred while uploading file to S3. Response code: {responsecode}", s3Response.HttpStatusCode);
|
||||
await _eventBus.Publish(new FileUploadRequestStatusUpdateEvent()
|
||||
{
|
||||
RequestId = @event.RequestId,
|
||||
Status = RequestStatus.Failed,
|
||||
ErrorMessage = "An error occurred while uploading file to S3."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await _eventBus.Publish(new FileUploadRequestStatusUpdateEvent()
|
||||
{
|
||||
Status = RequestStatus.Success,
|
||||
RequestId = @event.RequestId,
|
||||
FileAccessUrl = _proxyConfiguration.BaseUrl + "/" + @event.FilePath
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
22
FictionArchive.Service.FileService/appsettings.json
Normal file
22
FictionArchive.Service.FileService/appsettings.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ProxyConfiguration": {
|
||||
"BaseUrl": "https://localhost:7247/api"
|
||||
},
|
||||
"RabbitMQ": {
|
||||
"ConnectionString": "amqp://localhost",
|
||||
"ClientIdentifier": "FileService"
|
||||
},
|
||||
"S3": {
|
||||
"Url": "https://s3.orfl.xyz",
|
||||
"Bucket": "fictionarchive",
|
||||
"AccessKey": "REPLACE_ME",
|
||||
"SecretKey": "REPLACE_ME"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -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>
|
||||
<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">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<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);
|
||||
|
||||
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")
|
||||
@@ -158,6 +187,9 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
b.Property<long>("AuthorId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid?>("CoverImageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
@@ -194,6 +226,8 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
|
||||
b.HasIndex("AuthorId");
|
||||
|
||||
b.HasIndex("CoverImageId");
|
||||
|
||||
b.HasIndex("DescriptionId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
@@ -335,6 +369,15 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
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")
|
||||
@@ -398,6 +441,10 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
.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")
|
||||
@@ -418,6 +465,8 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
|
||||
b.Navigation("Author");
|
||||
|
||||
b.Navigation("CoverImage");
|
||||
|
||||
b.Navigation("Description");
|
||||
|
||||
b.Navigation("Name");
|
||||
@@ -473,6 +522,11 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
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");
|
||||
|
||||
@@ -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,10 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.FileService.IntegrationEvents;
|
||||
|
||||
public class FileUploadRequestCreatedEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public byte[] FileData { 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.Shared.Models;
|
||||
|
||||
@@ -11,4 +12,7 @@ public class Chapter : BaseEntity<uint>
|
||||
|
||||
public LocalizationKey Name { 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.Service.NovelService.Models.Images;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.Shared.Models;
|
||||
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<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 string? Url { 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 Url { get; set; }
|
||||
public string ExternalId { get; set; }
|
||||
public ImageData? CoverImage { get; set; }
|
||||
|
||||
public Language RawLanguage { get; set; }
|
||||
public NovelStatus RawStatus { get; set; }
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using FictionArchive.Common.Extensions;
|
||||
using FictionArchive.Service.NovelService.GraphQL;
|
||||
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||
@@ -16,6 +18,7 @@ public class Program
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.AddLocalAppsettings();
|
||||
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
@@ -27,7 +30,8 @@ public class Program
|
||||
})
|
||||
.Subscribe<TranslationRequestCompletedEvent, TranslationRequestCompletedEventHandler>()
|
||||
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
||||
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>();
|
||||
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>()
|
||||
.Subscribe<FileUploadRequestStatusUpdateEvent, FileUploadRequestStatusUpdateEventHandler>();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -56,6 +60,7 @@ public class Program
|
||||
})
|
||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
||||
|
||||
builder.Services.Configure<NovelUpdateServiceConfiguration>(builder.Configuration.GetSection("UpdateService"));
|
||||
builder.Services.AddTransient<NovelUpdateService>();
|
||||
|
||||
#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.Novels;
|
||||
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<LocalizationKey> LocalizationKeys { 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.Images;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Services;
|
||||
|
||||
@@ -12,12 +18,16 @@ public class NovelUpdateService
|
||||
private readonly NovelServiceDbContext _dbContext;
|
||||
private readonly ILogger<NovelUpdateService> _logger;
|
||||
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;
|
||||
_logger = logger;
|
||||
_sourceAdapters = sourceAdapters;
|
||||
_eventBus = eventBus;
|
||||
_novelUpdateServiceConfiguration = novelUpdateServiceConfiguration.Value;
|
||||
}
|
||||
|
||||
public async Task<Novel> ImportNovel(string novelUrl)
|
||||
@@ -59,6 +69,10 @@ public class NovelUpdateService
|
||||
RawLanguage = metadata.RawLanguage,
|
||||
Url = metadata.Url,
|
||||
ExternalId = metadata.ExternalId,
|
||||
CoverImage = metadata.CoverImage != null ? new Image()
|
||||
{
|
||||
OriginalPath = metadata.CoverImage.Url,
|
||||
} : null,
|
||||
Chapters = metadata.Chapters.Select(chapter =>
|
||||
{
|
||||
return new Chapter()
|
||||
@@ -86,6 +100,17 @@ public class NovelUpdateService
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -95,17 +120,85 @@ public class NovelUpdateService
|
||||
.Include(novel => novel.Chapters)
|
||||
.ThenInclude(chapter => chapter.Body)
|
||||
.ThenInclude(body => body.Texts)
|
||||
.Include(novel => novel.Source)
|
||||
.Include(novel => novel.Source).Include(novel => novel.Chapters).ThenInclude(chapter => chapter.Images)
|
||||
.FirstOrDefaultAsync();
|
||||
var chapter = novel.Chapters.Where(chapter => chapter.Order == chapterNumber).FirstOrDefault();
|
||||
var adapter = _sourceAdapters.FirstOrDefault(adapter => adapter.SourceDescriptor.Key == novel.Source.Key);
|
||||
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
|
||||
});
|
||||
};
|
||||
chapter.Body.Texts.Add(localizationText);
|
||||
chapter.Images = rawChapter.ImageData.Select(img => new Image()
|
||||
{
|
||||
OriginalPath = img.Url
|
||||
}).ToList();
|
||||
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;
|
||||
}
|
||||
|
||||
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 Task<bool> CanProcessNovel(string url);
|
||||
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.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
|
||||
var badgeSet = Regex.Match(novelData, @"(?s)<p\s+class=""in-badge"">(.*?)<\/p>");
|
||||
var badgeMatches = Regex.Matches(badgeSet.Groups[1].Value, @"<span[^>]*>(.*?)<\/span>");
|
||||
@@ -160,7 +175,7 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
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 endpoint = ChapterDownloadEndpoint + chapterId;
|
||||
@@ -172,6 +187,11 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
var fetchResult = new ChapterFetchResult()
|
||||
{
|
||||
ImageData = new List<ImageData>()
|
||||
};
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
using var doc = JsonDocument.Parse(responseContent);
|
||||
JsonElement root = doc.RootElement;
|
||||
@@ -182,10 +202,20 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
foreach (JsonElement item in sArray.EnumerateArray())
|
||||
{
|
||||
string text = item.GetProperty("text").GetString();
|
||||
var imageMatch = Regex.Match(text, @"<img.+?src=\""(.+?)\"".+?>");
|
||||
if (text.Contains("cover-wrapper"))
|
||||
{
|
||||
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"))
|
||||
{
|
||||
continue;
|
||||
@@ -193,8 +223,24 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("An error occured while retrieving the login key. Message: " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"Username": "REPLACE_ME",
|
||||
"Password": "REPLACE_ME"
|
||||
},
|
||||
"UpdateService": {
|
||||
"PendingImageUrl": "https://localhost:7247/api/pendingupload.png"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=localhost;Database=FictionArchive_NovelService;Username=postgres;password=postgres"
|
||||
},
|
||||
|
||||
@@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.User
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.AuthenticationService", "FictionArchive.Service.AuthenticationService\FictionArchive.Service.AuthenticationService.csproj", "{70C4AE82-B01E-421D-B590-C0F47E63CD0C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.FileService", "FictionArchive.Service.FileService\FictionArchive.Service.FileService.csproj", "{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -54,5 +58,13 @@ Global
|
||||
{70C4AE82-B01E-421D-B590-C0F47E63CD0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{70C4AE82-B01E-421D-B590-C0F47E63CD0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{70C4AE82-B01E-421D-B590-C0F47E63CD0C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EC64A336-F8A0-4BED-9CA3-1B05AD00631D}.Debug|Any CPU.ActiveCfg = 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.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
|
||||
EndGlobal
|
||||
|
||||
1
fictionarchive-web/.env
Normal file
1
fictionarchive-web/.env
Normal file
@@ -0,0 +1 @@
|
||||
VITE_GRAPHQL_URI=http://localhost:5234/graphql/
|
||||
27
fictionarchive-web/.gitignore
vendored
Normal file
27
fictionarchive-web/.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Generated GraphQL artifacts
|
||||
src/__generated__/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
42
fictionarchive-web/README.md
Normal file
42
fictionarchive-web/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# FictionArchive React Starter
|
||||
|
||||
A minimal React + Vite + Apollo Client scaffold ready to connect to the FictionArchive Fusion gateway. Point it at your own endpoint by changing `VITE_GRAPHQL_URI`.
|
||||
|
||||
## Getting started
|
||||
|
||||
```bash
|
||||
cd fictionarchive-web
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Then open the printed local URL. Update `.env` (create it if missing) with your endpoint:
|
||||
|
||||
```
|
||||
VITE_GRAPHQL_URI=https://localhost:5001/graphql
|
||||
VITE_OIDC_AUTHORITY=https://your-idp
|
||||
VITE_OIDC_CLIENT_ID=fictionarchive-web
|
||||
VITE_OIDC_REDIRECT_URI=http://localhost:5173
|
||||
VITE_OIDC_POST_LOGOUT_REDIRECT_URI=http://localhost:5173
|
||||
# Optional: token used only by codegen if your gateway requires auth
|
||||
VITE_CODEGEN_TOKEN=your_api_token
|
||||
```
|
||||
|
||||
## Scripts
|
||||
|
||||
- `npm run dev`: start Vite dev server.
|
||||
- `npm run build`: type-check + build (runs codegen first via `prebuild`).
|
||||
- `npm run codegen`: generate typed hooks from `src/**/*.graphql` into `src/__generated__/graphql.ts`.
|
||||
|
||||
## Project notes
|
||||
|
||||
- `src/apolloClient.ts` configures the Apollo client with `InMemoryCache`, reads `VITE_GRAPHQL_URI`, and attaches an `Authorization: Bearer` header when an OIDC user is present.
|
||||
- GraphQL code generation is configured via `codegen.ts` (loads `.env`/`.env.local` automatically); run `npm run codegen` to emit typed hooks to `src/__generated__/graphql.ts` (ignored by git) or rely on the `prebuild` hook.
|
||||
- Routing is handled in `src/App.tsx` with `react-router-dom`; `/` renders the novels listing and `/novels/:id` is stubbed for future detail pages.
|
||||
- Styles live primarily in `src/index.css` alongside the shared UI components.
|
||||
|
||||
## Codegen tips
|
||||
|
||||
- Default schema URL: `CODEGEN_SCHEMA_URL` (falls back to `VITE_GRAPHQL_URI`, then `https://localhost:5001/graphql`).
|
||||
- Add `VITE_CODEGEN_TOKEN` (or `CODEGEN_TOKEN`) if your gateway requires a bearer token during introspection.
|
||||
- Generated outputs land in `src/__generated__/graphql.ts` (git-ignored). Run `npm run codegen` after schema/operation changes or rely on `npm run build` (runs `prebuild`).
|
||||
40
fictionarchive-web/codegen.ts
Normal file
40
fictionarchive-web/codegen.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { CodegenConfig } from '@graphql-codegen/cli'
|
||||
|
||||
const schema =
|
||||
process.env.CODEGEN_SCHEMA_URL ??
|
||||
process.env.VITE_GRAPHQL_URI ??
|
||||
'https://localhost:5001/graphql'
|
||||
|
||||
const authToken = process.env.VITE_CODEGEN_TOKEN ?? process.env.CODEGEN_TOKEN
|
||||
const headers = authToken
|
||||
? {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
}
|
||||
: undefined
|
||||
|
||||
const config: CodegenConfig = {
|
||||
schema: {
|
||||
[schema]: { headers },
|
||||
},
|
||||
documents: 'src/**/*.graphql',
|
||||
generates: {
|
||||
'src/__generated__/graphql.ts': {
|
||||
plugins: [
|
||||
'typescript',
|
||||
'typescript-operations',
|
||||
'typescript-react-apollo',
|
||||
],
|
||||
config: {
|
||||
withHooks: true,
|
||||
avoidOptionals: true,
|
||||
dedupeFragments: true,
|
||||
maybeValue: 'T | null',
|
||||
skipTypename: true,
|
||||
apolloReactHooksImportFrom: '@apollo/client/react',
|
||||
},
|
||||
},
|
||||
},
|
||||
ignoreNoDocuments: true,
|
||||
}
|
||||
|
||||
export default config
|
||||
23
fictionarchive-web/eslint.config.js
Normal file
23
fictionarchive-web/eslint.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
15
fictionarchive-web/index.html
Normal file
15
fictionarchive-web/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/png" href="/favicon-32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="/favicon-64.png" sizes="64x64" />
|
||||
<link rel="apple-touch-icon" href="/favicon-180.png" sizes="180x180" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>FictionArchive</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
8349
fictionarchive-web/package-lock.json
generated
Normal file
8349
fictionarchive-web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
fictionarchive-web/package.json
Normal file
49
fictionarchive-web/package.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "fictionarchive-web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"prebuild": "npm run codegen",
|
||||
"codegen": "graphql-codegen --config codegen.ts -r dotenv/config --use-system-ca",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^4.0.9",
|
||||
"@radix-ui/react-slot": "^1.1.2",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"graphql": "^16.12.0",
|
||||
"react-router-dom": "^6.27.0",
|
||||
"oidc-client-ts": "^3.4.1",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"tailwind-merge": "^2.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/cli": "^5.0.3",
|
||||
"@graphql-codegen/typescript": "^4.0.9",
|
||||
"@graphql-codegen/typescript-operations": "^4.0.9",
|
||||
"@graphql-codegen/typescript-react-apollo": "^4.0.9",
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/react": "^19.2.5",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^5.1.1",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"dotenv": "^16.4.5",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"postcss": "^8.4.49",
|
||||
"tailwindcss": "^3.4.16",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.46.4",
|
||||
"vite": "^7.2.4"
|
||||
}
|
||||
}
|
||||
6
fictionarchive-web/postcss.config.cjs
Normal file
6
fictionarchive-web/postcss.config.cjs
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
BIN
fictionarchive-web/public/favicon-180.png
Normal file
BIN
fictionarchive-web/public/favicon-180.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
fictionarchive-web/public/favicon-32.png
Normal file
BIN
fictionarchive-web/public/favicon-32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
fictionarchive-web/public/favicon-64.png
Normal file
BIN
fictionarchive-web/public/favicon-64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
BIN
fictionarchive-web/public/favicon.png
Normal file
BIN
fictionarchive-web/public/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 348 KiB |
1
fictionarchive-web/public/vite.svg
Normal file
1
fictionarchive-web/public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
158
fictionarchive-web/src/App.css
Normal file
158
fictionarchive-web/src/App.css
Normal file
@@ -0,0 +1,158 @@
|
||||
.page {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
padding: 2.5rem 1.5rem 3rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #ffffff;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 16px;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 18px 60px -30px rgba(15, 23, 42, 0.3);
|
||||
}
|
||||
|
||||
.card + .card {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
.intro {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
font-size: 0.75rem;
|
||||
color: #475569;
|
||||
margin: 0 0 0.35rem;
|
||||
}
|
||||
|
||||
.lede {
|
||||
color: #475569;
|
||||
margin: 0.5rem 0 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
padding: 0.3rem 0.7rem;
|
||||
border-radius: 999px;
|
||||
background: #eef2ff;
|
||||
color: #312e81;
|
||||
border: 1px solid #c7d2fe;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: #475569;
|
||||
margin: 0.35rem 0 0;
|
||||
}
|
||||
|
||||
.query-form {
|
||||
margin: 1rem 0;
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-weight: 600;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.field-row input {
|
||||
flex: 1;
|
||||
padding: 0.65rem 0.75rem;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 12px;
|
||||
font-size: 1rem;
|
||||
color: #0f172a;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.field-row input:focus {
|
||||
outline: none;
|
||||
border-color: #6366f1;
|
||||
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
|
||||
}
|
||||
|
||||
.field-row button {
|
||||
padding: 0.65rem 0.9rem;
|
||||
border: 1px solid #312e81;
|
||||
background: linear-gradient(135deg, #4338ca, #312e81);
|
||||
color: #fff;
|
||||
border-radius: 12px;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: transform 150ms ease, box-shadow 150ms ease;
|
||||
}
|
||||
|
||||
.field-row button:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 8px 24px -10px rgba(49, 46, 129, 0.6);
|
||||
}
|
||||
|
||||
.field-row button:active {
|
||||
transform: translateY(0);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.country {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.country__headline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.8rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.country h3 {
|
||||
margin: 0.2rem 0 0;
|
||||
}
|
||||
|
||||
.emoji {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-size: 0.9rem;
|
||||
color: #475569;
|
||||
margin-bottom: 0.2rem;
|
||||
}
|
||||
|
||||
dd {
|
||||
margin: 0;
|
||||
font-weight: 600;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #b91c1c;
|
||||
background: #fef2f2;
|
||||
border: 1px solid #fecdd3;
|
||||
border-radius: 12px;
|
||||
padding: 0.75rem 1rem;
|
||||
margin: 0.75rem 0 0;
|
||||
}
|
||||
19
fictionarchive-web/src/App.tsx
Normal file
19
fictionarchive-web/src/App.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
import { AppLayout } from './layouts/AppLayout'
|
||||
import { NovelsPage } from './pages/NovelsPage'
|
||||
import { NovelDetailPage } from './pages/NovelDetailPage'
|
||||
import { NotFoundPage } from './pages/NotFoundPage'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/" element={<AppLayout />}>
|
||||
<Route index element={<NovelsPage />} />
|
||||
<Route path="novels/:id" element={<NovelDetailPage />} />
|
||||
<Route path="*" element={<NotFoundPage />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
30
fictionarchive-web/src/apolloClient.ts
Normal file
30
fictionarchive-web/src/apolloClient.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
|
||||
import {SetContextLink} from '@apollo/client/link/context'
|
||||
import { userManager } from './auth/oidcClient'
|
||||
|
||||
const uri = import.meta.env.VITE_GRAPHQL_URI ?? 'https://localhost:5001/graphql'
|
||||
|
||||
const httpLink = new HttpLink({ uri })
|
||||
|
||||
const authLink = new SetContextLink(async ({ headers }, _) => {
|
||||
if (!userManager) return { headers }
|
||||
try {
|
||||
const user = await userManager.getUser()
|
||||
const token = user?.access_token
|
||||
if (!token) return { headers }
|
||||
return {
|
||||
headers: {
|
||||
...headers,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to load user for auth header', error)
|
||||
return { headers }
|
||||
}
|
||||
})
|
||||
|
||||
export const apolloClient = new ApolloClient({
|
||||
link: authLink.concat(httpLink),
|
||||
cache: new InMemoryCache(),
|
||||
})
|
||||
1
fictionarchive-web/src/assets/react.svg
Normal file
1
fictionarchive-web/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
130
fictionarchive-web/src/auth/AuthContext.tsx
Normal file
130
fictionarchive-web/src/auth/AuthContext.tsx
Normal file
@@ -0,0 +1,130 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
import type { User } from 'oidc-client-ts'
|
||||
import { isOidcConfigured, userManager } from './oidcClient'
|
||||
|
||||
type AuthContextValue = {
|
||||
user: User | null
|
||||
isLoading: boolean
|
||||
isConfigured: boolean
|
||||
login: () => Promise<void>
|
||||
logout: () => Promise<void>
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | undefined>(undefined)
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [user, setUser] = useState<User | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const callbackHandledRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!userManager) {
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
let cancelled = false
|
||||
userManager
|
||||
.getUser()
|
||||
.then((loadedUser) => {
|
||||
if (!cancelled) setUser(loadedUser ?? null)
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setIsLoading(false)
|
||||
})
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const manager = userManager
|
||||
if (!manager) return
|
||||
|
||||
const handleLoaded = (nextUser: User) => setUser(nextUser)
|
||||
const handleUnloaded = () => setUser(null)
|
||||
|
||||
manager.events.addUserLoaded(handleLoaded)
|
||||
manager.events.addUserUnloaded(handleUnloaded)
|
||||
manager.events.addUserSignedOut(handleUnloaded)
|
||||
|
||||
return () => {
|
||||
manager.events.removeUserLoaded(handleLoaded)
|
||||
manager.events.removeUserUnloaded(handleUnloaded)
|
||||
manager.events.removeUserSignedOut(handleUnloaded)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const manager = userManager
|
||||
if (!manager || callbackHandledRef.current) return
|
||||
|
||||
const url = new URL(window.location.href)
|
||||
const hasAuthParams =
|
||||
url.searchParams.has('code') ||
|
||||
url.searchParams.has('id_token') ||
|
||||
url.searchParams.has('error')
|
||||
|
||||
if (!hasAuthParams) return
|
||||
|
||||
callbackHandledRef.current = true
|
||||
manager
|
||||
.signinRedirectCallback()
|
||||
.then((nextUser) => {
|
||||
setUser(nextUser ?? null)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Failed to complete sign-in redirect', error)
|
||||
})
|
||||
.finally(() => {
|
||||
const cleanUrl = `${url.origin}${url.pathname}`
|
||||
window.history.replaceState({}, document.title, cleanUrl)
|
||||
})
|
||||
}, [])
|
||||
|
||||
const login = useCallback(async () => {
|
||||
const manager = userManager
|
||||
if (!manager) {
|
||||
console.warn('OIDC is not configured; set VITE_OIDC_* environment variables.')
|
||||
return
|
||||
}
|
||||
await manager.signinRedirect()
|
||||
}, [])
|
||||
|
||||
const logout = useCallback(async () => {
|
||||
const manager = userManager
|
||||
if (!manager) {
|
||||
console.warn('OIDC is not configured; set VITE_OIDC_* environment variables.')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await manager.signoutRedirect()
|
||||
} catch (error) {
|
||||
console.error('Failed to sign out via redirect, clearing local session instead.', error)
|
||||
await manager.removeUser()
|
||||
setUser(null)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const value = useMemo<AuthContextValue>(
|
||||
() => ({
|
||||
user,
|
||||
isLoading,
|
||||
isConfigured: isOidcConfigured,
|
||||
login,
|
||||
logout,
|
||||
}),
|
||||
[isLoading, login, logout, user],
|
||||
)
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>
|
||||
}
|
||||
|
||||
export function useAuth() {
|
||||
const context = useContext(AuthContext)
|
||||
if (!context) {
|
||||
throw new Error('useAuth must be used within an AuthProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
36
fictionarchive-web/src/auth/oidcClient.ts
Normal file
36
fictionarchive-web/src/auth/oidcClient.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { UserManager, WebStorageStateStore, type UserManagerSettings } from 'oidc-client-ts'
|
||||
|
||||
const authority = import.meta.env.VITE_OIDC_AUTHORITY
|
||||
const clientId = import.meta.env.VITE_OIDC_CLIENT_ID
|
||||
const redirectUri = import.meta.env.VITE_OIDC_REDIRECT_URI
|
||||
const postLogoutRedirectUri =
|
||||
import.meta.env.VITE_OIDC_POST_LOGOUT_REDIRECT_URI ?? redirectUri
|
||||
const scope = import.meta.env.VITE_OIDC_SCOPE ?? 'openid profile email'
|
||||
|
||||
export const isOidcConfigured =
|
||||
Boolean(authority) && Boolean(clientId) && Boolean(redirectUri)
|
||||
|
||||
function buildSettings(): UserManagerSettings | null {
|
||||
if (!isOidcConfigured) return null
|
||||
|
||||
return {
|
||||
authority: authority!,
|
||||
client_id: clientId!,
|
||||
redirect_uri: redirectUri!,
|
||||
post_logout_redirect_uri: postLogoutRedirectUri,
|
||||
response_type: 'code',
|
||||
scope,
|
||||
loadUserInfo: true,
|
||||
automaticSilentRenew: true,
|
||||
userStore:
|
||||
typeof window !== 'undefined'
|
||||
? new WebStorageStateStore({ store: window.localStorage })
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
export const userManager = (() => {
|
||||
const settings = buildSettings()
|
||||
if (!settings) return null
|
||||
return new UserManager(settings)
|
||||
})()
|
||||
103
fictionarchive-web/src/components/AuthenticationDisplay.tsx
Normal file
103
fictionarchive-web/src/components/AuthenticationDisplay.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useAuth } from '../auth/AuthContext'
|
||||
import { Button } from './ui/button'
|
||||
|
||||
export function AuthenticationDisplay() {
|
||||
const { user, isConfigured, isLoading, login, logout } = useAuth()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const menuRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const email = useMemo(
|
||||
() =>
|
||||
user?.profile?.email ??
|
||||
user?.profile?.preferred_username ??
|
||||
user?.profile?.name ??
|
||||
user?.profile?.sub ??
|
||||
null,
|
||||
[user],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (!menuRef.current) return
|
||||
if (!menuRef.current.contains(event.target as Node)) {
|
||||
setIsOpen(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleEscape = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') setIsOpen(false)
|
||||
}
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
document.addEventListener('keydown', handleEscape)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside)
|
||||
document.removeEventListener('keydown', handleEscape)
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<Button variant="outline" size="sm" disabled>
|
||||
Loading...
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
if (!isConfigured) {
|
||||
return (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
alert('OIDC is not configured. Set VITE_OIDC_* environment variables to enable login.')
|
||||
}
|
||||
>
|
||||
Configure OIDC
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return (
|
||||
<Button variant="secondary" size="sm" onClick={login}>
|
||||
Login
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative" ref={menuRef}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="flex items-center gap-2 text-foreground"
|
||||
onClick={() => setIsOpen((open) => !open)}
|
||||
aria-expanded={isOpen}
|
||||
aria-haspopup="menu"
|
||||
>
|
||||
<span className="inline-flex h-7 w-7 items-center justify-center rounded-full bg-primary/10 text-sm font-semibold text-primary">
|
||||
{(email ?? 'User').slice(0, 1).toUpperCase()}
|
||||
</span>
|
||||
<span className="max-w-[12ch] truncate">{email ?? 'User'}</span>
|
||||
</Button>
|
||||
{isOpen && (
|
||||
<div className="absolute right-0 top-full mt-2 w-56 rounded-lg border bg-white p-2 shadow-lg">
|
||||
<div className="px-3 py-2">
|
||||
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
||||
Signed in
|
||||
</p>
|
||||
<p className="truncate text-sm font-medium text-foreground">{email ?? 'User'}</p>
|
||||
</div>
|
||||
<Button variant="ghost" size="sm" className="w-full justify-start" onClick={logout}>
|
||||
Log out
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
50
fictionarchive-web/src/components/Navbar.tsx
Normal file
50
fictionarchive-web/src/components/Navbar.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Link, NavLink } from 'react-router-dom'
|
||||
import { AuthenticationDisplay } from './AuthenticationDisplay'
|
||||
import { Button } from './ui/button'
|
||||
import { Input } from './ui/input'
|
||||
|
||||
export function Navbar() {
|
||||
return (
|
||||
<nav className="sticky top-0 z-10 border-b bg-white/80 backdrop-blur">
|
||||
<div className="mx-auto flex max-w-6xl items-center gap-6 px-4 py-3 sm:px-6 lg:px-8">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link to="/" className="flex items-center gap-3">
|
||||
<div
|
||||
className="flex h-10 w-10 select-none items-center justify-center rounded-xl bg-primary text-primary-foreground font-bold shadow-md shadow-primary/20"
|
||||
translate="no"
|
||||
aria-label="FictionArchive"
|
||||
>
|
||||
FA
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-semibold text-foreground">FictionArchive</p>
|
||||
<p className="text-xs text-muted-foreground">GraphQL playground</p>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-muted-foreground">
|
||||
<Button variant="ghost" size="sm" asChild>
|
||||
<NavLink
|
||||
to="/"
|
||||
className={({ isActive }) =>
|
||||
isActive ? 'text-foreground' : 'text-muted-foreground'
|
||||
}
|
||||
>
|
||||
Novels
|
||||
</NavLink>
|
||||
</Button>
|
||||
</div>
|
||||
<div className="ml-auto flex items-center gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
placeholder="Search"
|
||||
className="w-48 sm:w-64"
|
||||
aria-label="Search"
|
||||
/>
|
||||
</div>
|
||||
<AuthenticationDisplay />
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
47
fictionarchive-web/src/components/NovelCard.tsx
Normal file
47
fictionarchive-web/src/components/NovelCard.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { Novel } from '../__generated__/graphql'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from './ui/card'
|
||||
|
||||
type NovelCardProps = {
|
||||
novel: Novel
|
||||
}
|
||||
|
||||
function pickText(novelText?: Novel['name'] | Novel['description']) {
|
||||
const texts = novelText?.texts ?? []
|
||||
const english = texts.find((t) => t.language === 'EN')
|
||||
return (english ?? texts[0])?.text ?? 'No description available.'
|
||||
}
|
||||
|
||||
export function NovelCard({ novel }: NovelCardProps) {
|
||||
const title = pickText(novel.name)
|
||||
const description = pickText(novel.description)
|
||||
const cover = novel.coverImage
|
||||
|
||||
const coverSrc = cover?.newPath ?? cover?.originalPath
|
||||
|
||||
return (
|
||||
<Card className="overflow-hidden border shadow-sm hover:shadow-md transition-shadow">
|
||||
{coverSrc ? (
|
||||
<div className="aspect-[3/4] w-full overflow-hidden bg-muted/50">
|
||||
<img
|
||||
src={coverSrc}
|
||||
alt={title}
|
||||
className="h-full w-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="aspect-[3/4] w-full bg-muted/50" />
|
||||
)}
|
||||
<CardHeader className="space-y-2">
|
||||
<CardTitle className="line-clamp-2 text-lg leading-tight">
|
||||
{title}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="pt-0">
|
||||
<p className="line-clamp-3 text-sm text-muted-foreground">
|
||||
{description}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
34
fictionarchive-web/src/components/ui/badge.tsx
Normal file
34
fictionarchive-web/src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as React from 'react'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
const badgeVariants = cva(
|
||||
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
'border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/90',
|
||||
secondary:
|
||||
'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
outline: 'text-foreground',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
export interface BadgeProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
|
||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||
return (
|
||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
54
fictionarchive-web/src/components/ui/button.tsx
Normal file
54
fictionarchive-web/src/components/ui/button.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ring-offset-background',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
|
||||
secondary:
|
||||
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
outline:
|
||||
'border border-input bg-background hover:bg-accent hover:text-accent-foreground shadow-sm',
|
||||
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
||||
},
|
||||
size: {
|
||||
default: 'h-10 px-4 py-2',
|
||||
sm: 'h-9 rounded-md px-3',
|
||||
lg: 'h-11 rounded-md px-8',
|
||||
icon: 'h-10 w-10',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Comp = asChild ? Slot : 'button'
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Button.displayName = 'Button'
|
||||
|
||||
export { Button, buttonVariants }
|
||||
76
fictionarchive-web/src/components/ui/card.tsx
Normal file
76
fictionarchive-web/src/components/ui/card.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
const Card = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'rounded-xl border bg-card text-card-foreground shadow-sm',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
Card.displayName = 'Card'
|
||||
|
||||
const CardHeader = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn('flex flex-col space-y-1.5 p-6', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardHeader.displayName = 'CardHeader'
|
||||
|
||||
const CardTitle = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn('text-2xl font-semibold leading-none tracking-tight', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardTitle.displayName = 'CardTitle'
|
||||
|
||||
const CardDescription = React.forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<p
|
||||
ref={ref}
|
||||
className={cn('text-sm text-muted-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardDescription.displayName = 'CardDescription'
|
||||
|
||||
const CardContent = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
|
||||
))
|
||||
CardContent.displayName = 'CardContent'
|
||||
|
||||
const CardFooter = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
React.HTMLAttributes<HTMLDivElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn('flex items-center p-6 pt-0', className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
CardFooter.displayName = 'CardFooter'
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
|
||||
25
fictionarchive-web/src/components/ui/input.tsx
Normal file
25
fictionarchive-web/src/components/ui/input.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { cn } from '../../lib/utils'
|
||||
|
||||
export interface InputProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||
|
||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
className={cn(
|
||||
'flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
)
|
||||
Input.displayName = 'Input'
|
||||
|
||||
export { Input }
|
||||
31
fictionarchive-web/src/graphql/novels.graphql
Normal file
31
fictionarchive-web/src/graphql/novels.graphql
Normal file
@@ -0,0 +1,31 @@
|
||||
query Novels($first: Int, $after: String) {
|
||||
novels(first: $first, after: $after) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
id
|
||||
url
|
||||
name {
|
||||
texts {
|
||||
language
|
||||
text
|
||||
}
|
||||
}
|
||||
description {
|
||||
texts {
|
||||
language
|
||||
text
|
||||
}
|
||||
}
|
||||
coverImage {
|
||||
originalPath
|
||||
newPath
|
||||
}
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
69
fictionarchive-web/src/index.css
Normal file
69
fictionarchive-web/src/index.css
Normal file
@@ -0,0 +1,69 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--background: 210 40% 98%;
|
||||
--foreground: 222 47% 11%;
|
||||
--muted: 214 32% 91%;
|
||||
--muted-foreground: 215 16% 47%;
|
||||
--popover: 0 0% 100%;
|
||||
--popover-foreground: 222 47% 11%;
|
||||
--card: 0 0% 100%;
|
||||
--card-foreground: 222 47% 11%;
|
||||
--border: 214 32% 91%;
|
||||
--input: 214 32% 91%;
|
||||
--primary: 243 75% 59%;
|
||||
--primary-foreground: 0 0% 100%;
|
||||
--secondary: 240 33% 94%;
|
||||
--secondary-foreground: 222 47% 11%;
|
||||
--accent: 220 70% 96%;
|
||||
--accent-foreground: 222 47% 11%;
|
||||
--destructive: 0 84% 60%;
|
||||
--destructive-foreground: 0 0% 100%;
|
||||
--ring: 243 75% 59%;
|
||||
--radius: 12px;
|
||||
--font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: 222 47% 11%;
|
||||
--foreground: 210 40% 98%;
|
||||
--muted: 222 47% 14%;
|
||||
--muted-foreground: 215 20% 65%;
|
||||
--popover: 222 47% 11%;
|
||||
--popover-foreground: 210 40% 98%;
|
||||
--card: 222 47% 11%;
|
||||
--card-foreground: 210 40% 98%;
|
||||
--border: 222 47% 20%;
|
||||
--input: 222 47% 20%;
|
||||
--primary: 243 75% 70%;
|
||||
--primary-foreground: 222 47% 11%;
|
||||
--secondary: 222 47% 20%;
|
||||
--secondary-foreground: 210 40% 98%;
|
||||
--accent: 222 47% 20%;
|
||||
--accent-foreground: 210 40% 98%;
|
||||
--destructive: 0 84% 60%;
|
||||
--destructive-foreground: 210 40% 98%;
|
||||
--ring: 243 75% 70%;
|
||||
}
|
||||
|
||||
* {
|
||||
@apply border-border;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-background text-foreground min-h-screen antialiased;
|
||||
background-image: radial-gradient(circle at 20% 20%, #eef2ff, transparent 32%),
|
||||
radial-gradient(circle at 80% 10%, #dcfce7, transparent 25%),
|
||||
radial-gradient(circle at 50% 80%, #fee2e2, transparent 20%),
|
||||
linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(248, 250, 252, 0.95));
|
||||
}
|
||||
|
||||
a {
|
||||
@apply text-primary font-medium;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
@apply underline;
|
||||
}
|
||||
13
fictionarchive-web/src/layouts/AppLayout.tsx
Normal file
13
fictionarchive-web/src/layouts/AppLayout.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Outlet } from 'react-router-dom'
|
||||
import { Navbar } from '../components/Navbar'
|
||||
|
||||
export function AppLayout() {
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50">
|
||||
<Navbar />
|
||||
<main className="mx-auto flex max-w-6xl flex-col gap-6 px-4 py-8 sm:px-6 lg:px-8">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
6
fictionarchive-web/src/lib/utils.ts
Normal file
6
fictionarchive-web/src/lib/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
20
fictionarchive-web/src/main.tsx
Normal file
20
fictionarchive-web/src/main.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
import { ApolloProvider } from '@apollo/client/react'
|
||||
import { apolloClient } from './apolloClient.ts'
|
||||
import { AuthProvider } from './auth/AuthContext'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<AuthProvider>
|
||||
<ApolloProvider client={apolloClient}>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</ApolloProvider>
|
||||
</AuthProvider>
|
||||
</StrictMode>,
|
||||
)
|
||||
17
fictionarchive-web/src/pages/NotFoundPage.tsx
Normal file
17
fictionarchive-web/src/pages/NotFoundPage.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card'
|
||||
|
||||
export function NotFoundPage() {
|
||||
return (
|
||||
<Card className="shadow-md shadow-primary/10">
|
||||
<CardHeader>
|
||||
<CardTitle>Page not found</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
The page you are looking for does not exist. Head back to the novels
|
||||
list to continue.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
17
fictionarchive-web/src/pages/NovelDetailPage.tsx
Normal file
17
fictionarchive-web/src/pages/NovelDetailPage.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card'
|
||||
|
||||
export function NovelDetailPage() {
|
||||
return (
|
||||
<Card className="shadow-md shadow-primary/10">
|
||||
<CardHeader>
|
||||
<CardTitle>Novel details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Detail view coming soon. Select a novel to explore chapters and
|
||||
metadata once implemented.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
111
fictionarchive-web/src/pages/NovelsPage.tsx
Normal file
111
fictionarchive-web/src/pages/NovelsPage.tsx
Normal file
@@ -0,0 +1,111 @@
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import { useNovelsQuery } from '../__generated__/graphql'
|
||||
import { NovelCard } from '../components/NovelCard'
|
||||
import { Button } from '../components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card'
|
||||
|
||||
const PAGE_SIZE = 12
|
||||
|
||||
export function NovelsPage() {
|
||||
const { data, loading, error, fetchMore } = useNovelsQuery({
|
||||
variables: { first: PAGE_SIZE, after: null },
|
||||
notifyOnNetworkStatusChange: true,
|
||||
})
|
||||
|
||||
const edges = data?.novels?.edges ?? []
|
||||
const pageInfo = data?.novels?.pageInfo
|
||||
const hasNextPage = pageInfo?.hasNextPage ?? false
|
||||
const endCursor = pageInfo?.endCursor ?? null
|
||||
|
||||
const novels = useMemo(
|
||||
() => edges.map((edge) => edge?.node).filter(Boolean),
|
||||
[edges]
|
||||
)
|
||||
|
||||
async function handleLoadMore() {
|
||||
if (!hasNextPage || !endCursor) return
|
||||
await fetchMore({
|
||||
variables: { after: endCursor, first: PAGE_SIZE },
|
||||
updateQuery: (prev, { fetchMoreResult }) => {
|
||||
if (!fetchMoreResult?.novels?.edges) return prev
|
||||
const mergedEdges = [
|
||||
...(prev.novels?.edges ?? []),
|
||||
...fetchMoreResult.novels.edges,
|
||||
]
|
||||
return {
|
||||
...prev,
|
||||
novels: {
|
||||
...fetchMoreResult.novels,
|
||||
edges: mergedEdges,
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Card className="shadow-md shadow-primary/10">
|
||||
<CardHeader>
|
||||
<CardTitle>Latest Novels</CardTitle>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Novels that have recently been updated.
|
||||
</p>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
|
||||
{loading && !data && (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<div className="h-10 w-10 animate-spin rounded-full border-2 border-primary border-t-transparent" aria-label="Loading novels" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<Card className="border-destructive/40 bg-destructive/5">
|
||||
<CardContent>
|
||||
<p className="py-4 text-sm text-destructive">
|
||||
Could not load novels: {error.message}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{!loading && novels.length === 0 && !error && (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<p className="py-4 text-sm text-muted-foreground">
|
||||
No novels found yet. Try adding content to the gateway.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{novels.length > 0 && (
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{novels.map(
|
||||
(novel) =>
|
||||
novel && <NovelCard key={novel.id.toString()} novel={novel} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{hasNextPage && (
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
onClick={handleLoadMore}
|
||||
variant="outline"
|
||||
disabled={loading}
|
||||
className="min-w-[160px]"
|
||||
>
|
||||
{loading ? 'Loading...' : 'Load more'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
69
fictionarchive-web/tailwind.config.cjs
Normal file
69
fictionarchive-web/tailwind.config.cjs
Normal file
@@ -0,0 +1,69 @@
|
||||
const { fontFamily } = require('tailwindcss/defaultTheme')
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
darkMode: ['class'],
|
||||
content: ['./index.html', './src/**/*.{ts,tsx}'],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
border: 'hsl(var(--border))',
|
||||
input: 'hsl(var(--input))',
|
||||
ring: 'hsl(var(--ring))',
|
||||
background: 'hsl(var(--background))',
|
||||
foreground: 'hsl(var(--foreground))',
|
||||
primary: {
|
||||
DEFAULT: 'hsl(var(--primary))',
|
||||
foreground: 'hsl(var(--primary-foreground))',
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: 'hsl(var(--secondary))',
|
||||
foreground: 'hsl(var(--secondary-foreground))',
|
||||
},
|
||||
destructive: {
|
||||
DEFAULT: 'hsl(var(--destructive))',
|
||||
foreground: 'hsl(var(--destructive-foreground))',
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: 'hsl(var(--muted))',
|
||||
foreground: 'hsl(var(--muted-foreground))',
|
||||
},
|
||||
accent: {
|
||||
DEFAULT: 'hsl(var(--accent))',
|
||||
foreground: 'hsl(var(--accent-foreground))',
|
||||
},
|
||||
popover: {
|
||||
DEFAULT: 'hsl(var(--popover))',
|
||||
foreground: 'hsl(var(--popover-foreground))',
|
||||
},
|
||||
card: {
|
||||
DEFAULT: 'hsl(var(--card))',
|
||||
foreground: 'hsl(var(--card-foreground))',
|
||||
},
|
||||
},
|
||||
borderRadius: {
|
||||
lg: 'var(--radius)',
|
||||
md: 'calc(var(--radius) - 2px)',
|
||||
sm: 'calc(var(--radius) - 4px)',
|
||||
},
|
||||
fontFamily: {
|
||||
sans: ['var(--font-sans)', ...fontFamily.sans],
|
||||
},
|
||||
keyframes: {
|
||||
'accordion-down': {
|
||||
from: { height: '0' },
|
||||
to: { height: 'var(--radix-accordion-content-height)' },
|
||||
},
|
||||
'accordion-up': {
|
||||
from: { height: 'var(--radix-accordion-content-height)' },
|
||||
to: { height: '0' },
|
||||
},
|
||||
},
|
||||
animation: {
|
||||
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [require('tailwindcss-animate')],
|
||||
}
|
||||
28
fictionarchive-web/tsconfig.app.json
Normal file
28
fictionarchive-web/tsconfig.app.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
fictionarchive-web/tsconfig.json
Normal file
7
fictionarchive-web/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
26
fictionarchive-web/tsconfig.node.json
Normal file
26
fictionarchive-web/tsconfig.node.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
22
fictionarchive-web/vite.config.ts
Normal file
22
fictionarchive-web/vite.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'node:path'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
react: path.resolve(__dirname, 'node_modules/react'),
|
||||
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
|
||||
'react/jsx-runtime': path.resolve(
|
||||
__dirname,
|
||||
'node_modules/react/jsx-runtime'
|
||||
),
|
||||
'react/jsx-dev-runtime': path.resolve(
|
||||
__dirname,
|
||||
'node_modules/react/jsx-dev-runtime'
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user