refactoring for integration

This commit is contained in:
Paul Schneider 2026-06-06 21:10:48 +01:00
commit 070f41ac7e
48 changed files with 100 additions and 46 deletions

View file

@ -12,6 +12,7 @@ MODERATION_AUTO_APPROVE_THRESHOLD=0.7
# Limite par appel # Limite par appel
ANTHROPIC_MAX_TOKENS=256 # la modération n'a pas besoin de plus ANTHROPIC_MAX_TOKENS=256 # la modération n'a pas besoin de plus
# Choisis le bon modèle selon l'usage YAVSC_API_HOST=127.0.0.1
# - Modération : claude-haiku-4-5 (rapide, pas cher) YAVSC_API_PORT=6001
# - Aide rédaction devis : claude-sonnet-4-6 (meilleur équilibre)
ASPNETCORE_Kestrel__Endpoints__Https__Url="https://$YAVSC_API_HOST:$YAVSC_API_PORT"

2
.gitignore vendored
View file

@ -47,11 +47,9 @@ generated/
*.Development.json *.Development.json
*.log *.log
**/AppDataDevelopment/ **/AppDataDevelopment/
binaries/ binaries/
build/ build/
src/*/Blog-Dev/ src/*/Blog-Dev/
*.mp4 *.mp4
src/Yavsc.Org/data/ src/Yavsc.Org/data/

View file

@ -4,10 +4,17 @@
"cSpell.words": [ "cSpell.words": [
"appsettings", "appsettings",
"asciidoctor", "asciidoctor",
"ASPNETCORE",
"Cratie", "Cratie",
"DESTDIR", "DESTDIR",
"dotnet",
"DOTNET",
"envsubst",
"Newtonsoft", "Newtonsoft",
"Npgsql", "Npgsql",
"SLNDIR",
"www-data",
"yavsc",
"Yavsc" "Yavsc"
], ],
"cSpell.dictionaries": [ "cSpell.dictionaries": [

View file

@ -1,36 +1,80 @@
APP_PROJECTS=src/Org/Org.csproj src/Api/Api.csproj APP_PROJECT_NAMES=Api Org Blogs
APP_PROJECTS=src/Yavsc.Org/Yavsc.Org.csproj src/Yavsc.Api/Yavsc.Api.csproj
SLNDIR=.. SLNDIR=..
DESTDIR=/srv/www/yavsc/
USER_AND_GROUP=www-data:www-data
CONFIGURATION=Release
DOTNET_FRAMEWORK=net10.0
generated/%.service: template.service %.env .env include $(SLNDIR)/.env
envsubst < template.service > $@
copy-service-Org: $(DESTDIR)/etc/systemd/system/Org.service generated/:
@mkdir -p $@
$(DESTDIR)/etc/systemd/system/%.service: generated/%.service generated/Api.service:
generated/Org.service:
generated/Blogs.service:
generated/yavsc%.service: generated/ template.service $(SLNDIR)/.env
@cat template.service | APP_NAME="$*" \
DESTDIR="$(DESTDIR)" \
APP_SYSLOG_ID="yavsc$*" \
POSTGRES_HOST="$(POSTGRES_HOST)" \
POSTGRES_PORT="$(POSTGRES_PORT)" \
POSTGRES_DB="$(POSTGRES_DB)" \
POSTGRES_USER="$(POSTGRES_USER)" \
POSTGRES_PASSWORD="$(POSTGRES_PASSWORD)" \
ANTHROPIC_API_KEY="$(ANTHROPIC_API_KEY)" \
ANTHROPIC_MAX_TOKENS="$(ANTHROPIC_MAX_TOKENS)" \
envsubst > $@
@echo Created service file: $@
copy-services: copy-service-Org copy-service-Api copy-service-Blogs
copy-service-Org: /etc/systemd/system/yavscOrg.service
copy-service-Api: /etc/systemd/system/yavscApi.service
copy-service-Blogs: /etc/systemd/system/yavscBlogs.service
copy-binaries:
for project in $(APP_PROJECT_NAMES); \
do \
sudo cp -a $(SLNDIR)/src/Yavsc.$${project}/bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/* $(DESTDIR) ; \
done
sudo chown -R $(USER_AND_GROUP) $(DESTDIR)
/etc/systemd/system/yavsc%.service: generated/yavsc%.service
sudo cp $^ $@ sudo cp $^ $@
sudo chown root:root $@
sudo systemctl daemon-reload sudo systemctl daemon-reload
build_publish: build_publish:
for f in $(APP_PROJECTS); do \ for f in $(APP_PROJECTS); do \
ASPNETCORE_ENV=$(CONFIGURATION) dotnet publish $(SLNDIR)/$$f ; \ ASPNETCORE_ENV=$(CONFIGURATION) dotnet publish $(SLNDIR)/$$f ; \
done done
rmep: build_publish install: build_publish copy-services copy-binaries
sudo systemctl stop yavsc-api sudo systemctl daemon-reload
sudo systemctl stop yavsc-org for project in $(APP_PROJECT_NAMES); \
for f in Api Org; do do \
pushd $(SLNDIR)/src/$$prj sudo systemctl enable yavsc$${project} ; \
SOURCE_DIR=bin/$(CONFIGURATION)/$(DOTNET_FRAMEWORK)/publish/ sudo systemctl start yavsc$${project} ; \
sudo cp -a $(SOURCE_DIR)/* $(DESTDIR) done
sudo chown -R $(USER_AND_GROUP) $(DESTDIR)
popd reinstall: build_publish copy-services copy-binaries
for project in $(APP_PROJECT_NAMES); \
do \
sudo systemctl stop yavsc$${project} ; \
done
for project in $(APP_PROJECT_NAMES); \
do \
sudo systemctl start yavsc$${project} ; \
done done
sudo sync
sudo systemctl start yavsc-org
sudo systemctl start yavsc-api
showConfig: showConfig:
@echo CONFIGURATION: $(CONFIGURATION) @echo CONFIGURATION: $(CONFIGURATION)
@echo DESTDIR: $(DESTDIR) @echo DESTDIR: $(DESTDIR)
reinstall: copy-service-Org copy-service-Api rmep clean:
rm -rf generated
.PHONY: build_publish mep showConfig copy-service-Api copy-service-Org copy-service-Blogs reinstall clean

View file

@ -12,16 +12,18 @@ Type=simple
User=www-data User=www-data
Group=www-data Group=www-data
WorkingDirectory=$DESTDIR WorkingDirectory=$DESTDIR
ExecStart=$DESTDIR/$APP_NAME ExecStart=$DESTDIR/Yavsc.$APP_NAME
Restart=always Restart=always
Environment="HOME=$DESTDIR" Environment="HOME=$DESTDIR"
Environment="ASPNETCORE_ENVIRONMENT=Production" Environment="ASPNETCORE_ENVIRONMENT=Production"
Environment="ASPNETCORE_ConnectionStrings__YavscConnection=Server=$YAVSC_CONNECTION_HOST;Port=$YAVSC_CONNECTION_PORT;Database=$YAVSC_CONNECTION_DATABASE;Username=$YAVSC_CONNECTION_USERNAME;Password=$YAVSC_CONNECTION_PASSWORD;" Environment="ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY"
Environment="ANTHROPIC_MAX_TOKENS=$ANTHROPIC_MAX_TOKENS"
Environment="ASPNETCORE_ConnectionStrings__YavscConnection=Server=$POSTGRES_HOST;Port=$POSTGRES_PORT;Database=$POSTGRES_DB;Username=$POSTGRES_USER;Password=$POSTGRES_PASSWORD;"
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_BIND_SERVICE
StandardOutput=syslog StandardOutput=syslog
StandardError=syslog StandardError=syslog
SyslogIdentifier=$APP_NAME SyslogIdentifier=$APP_SYSLOG_ID
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -10,10 +10,12 @@
copies or substantial portions of the Software. copies or substantial portions of the Software.
*/ */
using Anthropic.SDK;
using IdentityModel; using IdentityModel;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Yavsc; using Yavsc;
using Yavsc.Abstract.Interfaces;
using Yavsc.Helpers; using Yavsc.Helpers;
using Yavsc.Interface; using Yavsc.Interface;
using Yavsc.Models; using Yavsc.Models;
@ -28,7 +30,23 @@ internal class Program
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var services = builder.Services; var services = builder.Services;
// builder.Services.AddDistributedMemoryCache();
// Anthropic client
builder.Services.AddSingleton<AnthropicClient>(_ =>
new AnthropicClient(
new APIAuthentication(
builder.Configuration["ANTHROPIC_API_KEY"]
?? throw new InvalidOperationException("ANTHROPIC_API_KEY manquante")
)
)
);
// Service de modération
if (builder.Environment.IsDevelopment())
builder.Services.AddScoped<IModerationService, MockModerationService>();
else
builder.Services.AddScoped<IModerationService, ClaudeModerationService>();
// accepts any access token issued by identity server // accepts any access token issued by identity server
// adds an authorization policy for scope 'scope1' // adds an authorization policy for scope 'scope1'

View file

@ -10,4 +10,4 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<ProjectReference Include="../Yavsc.Server/Yavsc.Server.csproj" /> <ProjectReference Include="../Yavsc.Server/Yavsc.Server.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -10,22 +10,6 @@ namespace Yavsc
{ {
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Anthropic client
builder.Services.AddSingleton<AnthropicClient>(_ =>
new AnthropicClient(
new APIAuthentication(
builder.Configuration["ANTHROPIC_API_KEY"]
?? throw new InvalidOperationException("ANTHROPIC_API_KEY manquante")
)
)
);
// Service de modération
if (builder.Environment.IsDevelopment())
builder.Services.AddScoped<IModerationService, MockModerationService>();
else
builder.Services.AddScoped<IModerationService, ClaudeModerationService>();
var app = await builder var app = await builder
.ConfigureWebAppServices() .ConfigureWebAppServices()
.ConfigurePipeline(); .ConfigurePipeline();

View file

@ -13,7 +13,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Org", "src\Yavsc.Org\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Web", "src\Yavsc.Web\Yavsc.Web.csproj", "{1F594222-C5CB-4D4A-94A1-C5AEB4990B59}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Web", "src\Yavsc.Web\Yavsc.Web.csproj", "{1F594222-C5CB-4D4A-94A1-C5AEB4990B59}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "src\Api\Api.csproj", "{95DAD2B5-4324-4E89-A337-5703E45CFBE8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Api", "src\Yavsc.Api\Yavsc.Api.csproj", "{95DAD2B5-4324-4E89-A337-5703E45CFBE8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cli", "src\cli\cli.csproj", "{27DA6CEC-4266-4F78-BB32-8388F9A401D0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cli", "src\cli\cli.csproj", "{27DA6CEC-4266-4F78-BB32-8388F9A401D0}"
EndProject EndProject