Initial commit
This commit is contained in:
75
FictionArchive.API/Controllers/TestController.cs
Normal file
75
FictionArchive.API/Controllers/TestController.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FictionArchive.API.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class TestController : ControllerBase
|
||||
{
|
||||
/*private readonly FictionArchiveDbContext _dbContext;
|
||||
private readonly ISourceAdapter _novelpiaAdapter;
|
||||
private readonly ITranslationEngineAdapter _translationEngine;
|
||||
|
||||
public TestController(ISourceAdapter novelpiaAdapter, FictionArchiveDbContext dbContext, ITranslationEngineAdapter translationEngine)
|
||||
{
|
||||
_novelpiaAdapter = novelpiaAdapter;
|
||||
_dbContext = dbContext;
|
||||
_translationEngine = translationEngine;
|
||||
}
|
||||
|
||||
[HttpGet("GetNovel")]
|
||||
public async Task<Novel> GetNovel(string novelUrl)
|
||||
{
|
||||
var novel = await _novelpiaAdapter.GetMetadata(novelUrl);
|
||||
novel.Source = new Source()
|
||||
{
|
||||
Name = "Novelpia",
|
||||
Id = 1,
|
||||
Url = "https://novelpia.com"
|
||||
};
|
||||
_dbContext.Novels.Add(novel);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return novel;
|
||||
}
|
||||
|
||||
[HttpGet("GetChapter")]
|
||||
public async Task<string> GetChapter(uint novelId, uint chapterNumber)
|
||||
{
|
||||
var novel = await _dbContext.Novels.Include(n => n.Chapters).ThenInclude(c => c.Translations).FirstOrDefaultAsync(n => n.Id == novelId);
|
||||
var chapter = novel.Chapters.FirstOrDefault(c => c.Order == chapterNumber);
|
||||
var rawChapter = await _novelpiaAdapter.GetRawChapter(chapter.Url);
|
||||
chapter.Translations.Add(new ChapterTranslation()
|
||||
{
|
||||
Language = novel.RawLanguage,
|
||||
Body = rawChapter
|
||||
});
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return rawChapter;
|
||||
}
|
||||
|
||||
[HttpPost("TranslateChapter")]
|
||||
public async Task<ChapterTranslation> TranslateChapter(uint novelId, uint chapterNumber, Language to)
|
||||
{
|
||||
var novel = await _dbContext.Novels.Include(n => n.Chapters)
|
||||
.ThenInclude(c => c.Translations).FirstOrDefaultAsync(novel => novel.Id == novelId);
|
||||
var chapter = novel.Chapters.FirstOrDefault(c => c.Order == chapterNumber);
|
||||
var chapterRaw = chapter.Translations.FirstOrDefault(ct => ct.Language == novel.RawLanguage);
|
||||
var newTranslation = new ChapterTranslation()
|
||||
{
|
||||
Language = to,
|
||||
TranslationEngine = new TranslationEngine()
|
||||
{
|
||||
Name = "DeepL"
|
||||
}
|
||||
};
|
||||
var translation = await _translationEngine.GetTranslation(chapterRaw.Body, novel.RawLanguage, to);
|
||||
newTranslation.Body = translation;
|
||||
chapter.Translations.Add(newTranslation);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
return newTranslation;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
23
FictionArchive.API/Dockerfile
Normal file
23
FictionArchive.API/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.API/FictionArchive.API.csproj", "FictionArchive.API/"]
|
||||
RUN dotnet restore "FictionArchive.API/FictionArchive.API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/FictionArchive.API"
|
||||
RUN dotnet build "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "FictionArchive.API.dll"]
|
||||
35
FictionArchive.API/FictionArchive.API.csproj
Normal file
35
FictionArchive.API/FictionArchive.API.csproj
Normal file
@@ -0,0 +1,35 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HotChocolate.AspNetCore" Version="15.1.11" />
|
||||
<PackageReference Include="HotChocolate.Data" Version="15.1.11" />
|
||||
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="15.1.11" />
|
||||
<PackageReference Include="HotChocolate.Types.Scalars" Version="15.1.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="GraphQL\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
FictionArchive.API/FictionArchive.API.http
Normal file
6
FictionArchive.API/FictionArchive.API.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@FictionArchive.API_HostAddress = http://localhost:5234
|
||||
|
||||
GET {{FictionArchive.API_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
48
FictionArchive.API/Program.cs
Normal file
48
FictionArchive.API/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace FictionArchive.API;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
// OpenAPI & REST
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
41
FictionArchive.API/Properties/launchSettings.json
Normal file
41
FictionArchive.API/Properties/launchSettings.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:50224",
|
||||
"sslPort": 44385
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:5234",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7063;http://localhost:5234",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
FictionArchive.API/appsettings.Development.json
Normal file
8
FictionArchive.API/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
FictionArchive.API/appsettings.json
Normal file
9
FictionArchive.API/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user